Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 82c415b0eff08cc1a3c7b789b47747e36a2c2809466231a910ba5f6a19d0efad
Ticket: afa8c9f5bbde5127175f4a9f118106aed36f6773
Error in an execution trace reports line 1 and loses the traced command's frame in errorInfo
User & Date: jan.nijtmans on 2026-11-27 15:26:47
Changes

  1. assignee changed to: "jan.nijtmans"
  2. closer changed to: "nobody"
  3. 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].
    
  4. icomment: "Merged to [f158fb9ffa|trunk]"
  5. login: "jan.nijtmans"
  6. mimetype: "text/x-fossil-wiki"
  7. resolution changed to: "Fixed"
  8. status changed to: "Pending"