|
2025-03-06
| ||
| 19:52 | merge 9.0: amend to [ba68d1e9484a3a92]: rewrite fix of Tcl_GetReturnOptions less invasive (-errorlin... check-in: 5b2df96ce0 user: sebres tags: trunk, main | |
| 19:47 | amend to [ba68d1e9484a3a92]: rewrite fix of Tcl_GetReturnOptions less invasive (-errorline was alway... check-in: d48db316f5 user: sebres tags: core-8-6-branch | |
| 19:32 | merge 9.0 (amend to [ba68d1e9484a3a92] fixed wrong line nummer in Tcl_GetReturnOptions) check-in: 4ad99ceb18 user: sebres tags: trunk, main | |
| 19:30 | merge 8.7 (amend to [ba68d1e9484a3a92] fixed wrong line nummer in Tcl_GetReturnOptions) check-in: 1ed156c4d7 user: sebres tags: core-9-0-branch | |
| 19:29 | merge 8.6 (amend to [ba68d1e9484a3a92] fixed wrong line nummer in Tcl_GetReturnOptions) check-in: 6a45d0a25e user: sebres tags: core-8-branch | |
| 19:24 | • Closed ticket [ba68d1e948]: Errors that occur when using interp eval do not give... artifact: 33a889341a user: sebres | |
| 19:22 | amend to [ba68d1e9484a3a92]: fixes bug in Tcl_GetReturnOptions - reset errorLine if no errorInfo was... check-in: 5cd276dee1 user: sebres tags: core-8-6-branch | |
| 19:12 | • Ticket [ba68d1e948] Errors that occur when using interp eval do not give relevan... artifact: 0293d26c4c user: sebres | |
| 16:26 | • Open ticket [ba68d1e948]. artifact: 542bfb6a09 user: sebres | |
| 14:36 | • Closed ticket [ba68d1e948]. artifact: 41fbf44b1a user: sebres | |
| 14:31 | fixes [ba68d1e9484a3a92]: Tcl_TransferResult appends line-number at end of error stack now (error ca... check-in: f1d2397c7c user: sebres tags: core-8-6-branch | |
|
2025-02-27
| ||
| 13:45 | • Ticket [ba68d1e948] Errors that occur when using interp eval do not give relevan... artifact: 51a23f50b1 user: sebres | |
| 13:44 | • Ticket [ba68d1e948]: 3 changes artifact: eb328581b9 user: sebres | |
| 13:36 | fixes [ba68d1e9484a3a92]: Tcl_TransferResult would include line-number at end of error stack now (er... closed check-in: 497e526e67 user: sebres tags: bug-ba68d1e948-inter-eval-ln-in-ei | |
|
2025-02-25
| ||
| 17:00 | • New ticket [ba68d1e948] Errors that occur when using interp eval do not give rel... artifact: 26317ed2e6 user: anonymous | |
Errors that occur when using interp eval do not give relevant line number and filename locations
More details can be found here: https://stackoverflow.com/questions/78134384/how-to-get-line-number-and-filename-locations-for-errors-that-occur-while-using
To summarize, though, when an error occurs while using interp eval, the error outputs the location of the interp eval call, rather than the location of the actual erroneous code being evaluated.
This may make sense from the perspective of the caller of interp eval.
However, it creates difficulties in the context of implementing something like a plugin system that interp evals scripts, as the writers of the plugin scripts would receive less useful information than might be desired.
Some example code and their outputs:
Example A:
#!/bin/sh
# This line continues for Tcl, but is a single line for 'sh' \
exec tclsh "$0" ${1+"$@"}
::safe::interpCreate i
i eval {expr {"a" + 1}}
Example A Output:
./example.tcl
can't use non-numeric string as operand of "+"
invoked from within
"expr {"a" + 1}"
invoked from within
"i eval {expr {"a" + 1}}"
(file "./example.tcl" line 6)
Example B:
#!/bin/sh
# This line continues for Tcl, but is a single line for 'sh' \
exec tclsh "$0" ${1+"$@"}
::safe::interpCreate i
i eval [list expr {"a" + 1}]
Example B output:
./example.tcl
can't use non-numeric string as operand of "+"
while executing
"expr {"a" + 1}"
invoked from within
"i eval [list expr {"a" + 1}]"
(file "./example.tcl" line 6)
Example C:
#!/bin/sh
# This line continues for Tcl, but is a single line for 'sh' \
exec tclsh "$0" ${1+"$@"}
::safe::interpCreate i
i eval [list expr [list "a" + 1]]
Example C output:
./example.tcl
invalid bareword "a"
in expression "a + 1";
should be "$a" or "{a}" or "a(...)" or ...
(parsing expression "a + 1")
invoked from within
"expr {a + 1}"
invoked from within
"i eval [list expr [list "a" + 1]]"
(file "./example.tcl" line 6)
Already answered on stackoverflow, however hereafter noticed that sometimes it may be indeed interesting, thus here is a fix [497e526e670a9faf] (done in minimalistic way)...
Reviews are welcome. If no objections follow I'll merge it at some point later.
Since no objections, merged now in [f1d2397c7c640072]. Ticket closed as resolved.
Hmm, pity that I did not check the safe.test, but seeing @dgp amend [b756080dc6f8cd05], the whole fix looks a bit weird to me now, because there is no line 59 in code of interp eval (basically the evaluating scripts are single-line scripts).
If I do debug-logging from Tcl_TransferResult, it does that 3 times during test safe-10.4.1, for instance:
******** 04128CA8 ==> 014058B0 : 1 - can't use package in a safe interpreter: no Safepkg1_SafeInit procedure
while executing
"load {} Safepkg1 x"
******** 014058B0 ==> 04128CA8 : 59 - load of binary library for package Safepkg1 failed: can't use package in a safe interpreter: no Safepkg1_SafeInit procedure
******** 04128CA8 ==> 014058B0 : 1 - load of binary library for package Safepkg1 failed: can't use package in a safe interpreter: no Safepkg1_SafeInit procedure
("interp eval" body line 59)
invoked from within
"load {} Safepkg1 x"
(where only middle has errorLine = 59, probably some old value that did not reset in-between)...
Anyway, this doesn't look correct to me. I'll fix it soon.
Found it: the issue has been caused by the bug in Tcl_GetReturnOptions, what sets the errorLine from rethrown error from invokehidden in AliasLoad (so it contains the line number from this proc), but without the errorInfo (which initially empty, but hereafter got filled in Tcl_GetReturnOptions by Tcl_AddErrorInfo(interp, "") with thrown error message...
So ultimately with this 3-way transfer (interp eval -> invocation of alias AliasLoad -> calling invokehidden) it would reach the calling interpreter with non-empty errorInfo (containing the error message only, without the callstack).
The wrong line within interp eval is therefore only an after effect of the bug in Tcl_GetReturnOptions.
Thus fixed now in Tcl_GetReturnOptions, where it'd reset the errorLine if no errorInfo was initially thrown (before errorInfo becomes updated to error message).
Fixed now in [5cd276dee1c2a46f], tests pass, thus close.