Empty error message when interp limits are exceeded
See the following console session
% interp create slave
slave
% set cmdlimit [slave eval {info cmdcount}]
280
% slave limit command -value [incr cmdlimit 5]
% slave limit time -seconds 600
% slave eval [list expr 1+3]
% set errorInfo
while executing
"expr 1+3"
invoked from within
"slave eval [list expr 1+3]"
("uplevel" body line 1)
invoked from within
"uplevel #0 {slave eval [list expr 1+3]}"
% set errorCode
NONE
The time limit is in the past (it was actually a programming error, should have been absolute time, not relative). An error was generated as expected. However the error message is empty and error code is NONE (expected to be TCL LIMIT) resulting in my trap handler not firing.
22d57302c6Merge [b3d08c0262]: "fix for [e3f4a8b78dec4bdb]: don't swallow limit errors in further invocations of EvalObjvCore (e. g. direct invocation or NRE, Tcl_EvalObjv, Tcl_EvalObjEx, TclNREvalObjEx, etc); partially reverts [b740e2abbd44c7d0]", and "speedup interp.test a bit: switch to 50ms-based time limits (instead of 1sec); more tests for interp-34.14 covering [e3f4a8b78d] (direct/NRE)". check-in2024-08-28 21:56:13c5e7aac063Merge [bcac522a9f25d689]: "Test to demonstrate [9ee9f4d7be]. Not fixed." and "Check limits immediately when we do [interp eval]. [e3f4a8b78d]". check-in2024-08-28 21:35:599a6ae506c9speedup interp.test a bit: switch to 50ms-based time limits (instead of 1sec); more tests for interp-34.14 covering [e3f4a8b78d] (direct/NRE) check-in2024-05-27 20:09:13b740e2abbdCheck limits immediately when we do [interp eval]. [e3f4a8b78d] check-in2024-05-25 15:18:54
I reproduced this with the tip of the 8.6 branch:
interp create slave
set cmdlimit [slave eval {info cmdcount}]
slave limit command -value $cmdlimit
catch {slave eval [list expr 1+3]} msg1 opt1
puts «$msg1»
puts $opt1
catch {slave eval [list expr 1+3]} msg2 opt2
puts «$msg2»
puts $opt2
Output:
«command count limit exceeded»
-errorstack {INNER push1} -errorcode {TCL LIMIT COMMANDS} -errorinfo {command count limit exceeded
while executing
"expr 1+3"
invoked from within
"slave eval [list expr 1+3]"} -errorline 1 -code 1 -level 0
«»
-errorstack {INNER {expr 1+3}} -errorcode NONE -errorinfo {
while executing
"expr 1+3"
invoked from within
"slave eval [list expr 1+3]"} -errorline 1 -code 1 -level 0
Looks like it is a failure due to trying to run code in an environment where the trap has already fired.
Adding a check to the guts of interp eval makes this function correctly.
... that is, a limit check prior to transferring the work to the child interpreter. (Specifically, it's a call to Tcl_LimitCheck() in ChildEval() before TclEvalObjEx()/Tcl_EvalObjEx().)
But then this is not a solution ([b740e2abbd44c7d0] is rather a workaround) - because it'd work only for the case where tcl reaches the limit by interp eval (inside the tcl-level command from tcl level), but would continue to eat the error message if the limit reached calling the code internally (via C API), so by direct or NRE invocation, e. g. using Tcl_EvalObjv, Tcl_EvalObjEx, TclNREvalObjEx and co from the C-side.
The interp eval (or ChildEval) has nothing to do with the origin of the bug.
I have another solution for the bug somewhere (it works on my side without patching ChildEval)... Searching in my fork.
ultimately fixed in [35646a4ff27d1000]