Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: d4bcebc95393786ae5f4e9f2600aa93601005652b5584ed2cb64e8bb23ee4f3b
Ticket: afa8c9f5bbde5127175f4a9f118106aed36f6773
Error in an execution trace reports line 1 and loses the traced command's frame in errorInfo
User & Date: serhiy.storchaka on 2026-10-17 10:51:12
Changes

  1. cmimetype changed to: "text/x-fossil-wiki"
  2. comment changed to:
    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 <tt>x.tcl</tt>:
    
    <verbatim>
    proc p args {}
    trace add execution p leave {error boom;#}
    
    p
    </verbatim>
    
    <nowiki>[catch {source x.tcl} m o; puts [dict get $o -errorinfo]]</nowiki> in 8.6.1 and later (also 9.0.5 and main):
    
    <verbatim>
    boom
        while executing
    "error boom"
        (leave trace on "p")
        (file "x.tcl" line 1)
        invoked from within
    "source x.tcl"
    </verbatim>
    
    8.5.19 says <tt>(file "x.tcl" line 4)</tt>, with <tt>invoked from within "p"</tt> before it (8.6.0 also says line 4, but drops the error message of the trace, see [2438181fff]). The same happens with <tt>enter</tt> traces, in proc bodies (<tt>(procedure "q" line 1)</tt>) and in <nowiki>[eval]</nowiki> bodies. Variable traces are not affected (<tt>(write trace on "v")</tt>, <tt>invoked from within "set v 1"</tt>, correct line).
    
    Cause: the fix for [010f4162ef] ([f0e808cc64], 8.6.1) appends <tt>(enter/leave trace on "...")</tt> in <tt>TEOV_RunEnterTraces()</tt> / <tt>TEOV_RunLeaveTraces()</tt> in <tt>generic/tclBasic.c</tt> and then sets <tt>ERR_ALREADY_LOGGED</tt>. That flag makes the caller skip <tt>TclLogCommandInfo()</tt>, which is where the line number of the failing command is computed and the <tt>invoked from within</tt> frame is added, so the line stays 1.
    
    A fix would need to keep that logging in the caller while still avoiding the doubled <tt>-errorstack</tt> level from [010f4162ef].
    
  3. foundin changed to: "8.6.18, 9.0.5, 9.1.0"
  4. login: "serhiy.storchaka"
  5. priority changed to: "5 Medium"
  6. resolution changed to: "None"
  7. severity changed to: "Minor"
  8. status changed to: "Open"
  9. subsystem changed to: "46. Traces"
  10. title changed to:
    Error in an execution trace reports line 1 and loses the traced command's frame in errorInfo
    
  11. type changed to: "Bug"