Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2026-11-27
15:26 • Pending ticket [afa8c9f5bb]: Error in an execution trace reports line 1 and lose... artifact: 82c415b0ef user: jan.nijtmans
13:37
Fix [afa8c9f5bb]: an error in an execution trace lost the frame of the traced command check-in: f158fb9ffa user: jan.nijtmans tags: trunk, main
2026-10-20
18:11 • Ticket [afa8c9f5bb] Error in an execution trace reports line 1 and loses the tra... artifact: e054356f5f user: serhiy.storchaka
2026-10-17
12:10 • Ticket [afa8c9f5bb]: 3 changes artifact: ea23b02d8c user: serhiy.storchaka
12:01
Fix [afa8c9f5bb]: an error in an execution trace lost the frame of the traced command and its line n... check-in: 74b2ba4e13 user: serhiy.storchaka tags: trace-error-keep-frame
10:51 • New ticket [afa8c9f5bb] Error in an execution trace reports line 1 and loses the... artifact: d4bcebc953 user: serhiy.storchaka

Error in an execution trace reports line 1 and loses the traced command's frame in errorInfo

Pendingafa8c9f5bbde5127175f4a9f118106aed36f6773Created 46 days agoUpdated 5 days ago
Descriptionwiki2026-10-17 10:51:12
When an execution trace (enter or leave) raises an error, the errorInfo has the wrong line number and loses the frame of the traced command. File x.tcl:
proc p args {}
trace add execution p leave {error boom;#}

p

[catch {source x.tcl} m o; puts [dict get $o -errorinfo]] in 8.6.1 and later (also 9.0.5 and main):

boom
    while executing
"error boom"
    (leave trace on "p")
    (file "x.tcl" line 1)
    invoked from within
"source x.tcl"

8.5.19 says (file "x.tcl" line 4), with invoked from within "p" before it (8.6.0 also says line 4, but drops the error message of the trace, see [2438181fff]). The same happens with enter traces, in proc bodies ((procedure "q" line 1)) and in [eval] bodies. Variable traces are not affected ((write trace on "v"), invoked from within "set v 1", correct line).

Cause: the fix for [010f4162ef] ([f0e808cc64], 8.6.1) appends (enter/leave trace on "...") in TEOV_RunEnterTraces() / TEOV_RunLeaveTraces() in generic/tclBasic.c and then sets ERR_ALREADY_LOGGED. That flag makes the caller skip TclLogCommandInfo(), which is where the line number of the failing command is computed and the invoked from within frame is added, so the line stays 1.

A fix would need to keep that logging in the caller while still avoiding the doubled -errorstack level from [010f4162ef].

Referenced by2
  • f158fb9ffaFix [afa8c9f5bb]: an error in an execution trace lost the frame of the traced command check-in2026-11-27 13:37:12
  • 74b2ba4e13Fix [afa8c9f5bb]: an error in an execution trace lost the frame of the traced command and its line number in errorInfo, because [010f4162ef] marked it as ERR_ALREADY_LOGGED. Use a new flag ERR_STACK_LOGGED instead, which only skips the errorstack level. check-in2026-10-17 12:01:32
serhiy.storchakawiki2026-10-17 12:10:54

Proposed fix in branch trace-error-keep-frame: the trace code sets a new flag ERR_STACK_LOGGED instead of ERR_ALREADY_LOGGED, so TclLogCommandInfo() still adds the frame and line number to errorInfo and only skips the errorstack level (the doubled level of [010f4162ef] does not come back, error-4.8 passes). Tests trace-bug-afa8c9f5bb-1 and -2.

serhiy.storchaka Ticket [afa8c9f5bb]: 1 change [History diff]2026-10-20 18:11:29
jan.nijtmanswiki2026-11-27 15:26:47

Merged to [trunk]

Log in (anonymous is fine) to add a comment.