Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 26317ed2e67b5d84251de570f1a5d92a94ef41892a04e31492b65775ee70c34d
Ticket: ba68d1e9484a3a92449fdaab4c377b534842c0e0
Errors that occur when using interp eval do not give relevant line number and filename locations
User & Date: anonymous on 2025-02-25 17:00:06
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/x-fossil-plain"
  4. comment changed to:
    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)
    
  5. foundin changed to: "9.0"
  6. is_private changed to: "0"
  7. login: "anonymous"
  8. priority changed to: "5 Medium"
  9. private_contact changed to: "ac2378affc3f3ba3bd2cd1d1f0d09395d3a439be"
  10. resolution changed to: "None"
  11. severity changed to: "Minor"
  12. status changed to: "Open"
  13. submitter changed to: "anonymous"
  14. subsystem changed to: "20. [interp]"
  15. title changed to:
    Errors that occur when using interp eval do not give relevant line number and filename locations
    
  16. type changed to: "Bug"