Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2003-10-09
06:18 • Closed ticket [760947ffff]: trace on command leave changes errorInfo/errorCode</... artifact: e926b68062 user: dgp
06:11 • Ticket [760947ffff]: 4 changes artifact: be62acad3b user: dgp
06:11 • Add attachment 760947-HEAD.patch to ticket [760947ffffffffff|760947ffff... artifact: 90a73d8fb6 user: dgp
06:06 • Ticket [760947ffff] trace on command leave changes errorInfo/errorCode statu... artifact: 2fc382d7ce user: dgp
06:06 • Ticket [760947ffff]: 4 changes artifact: d9b8e08eb0 user: dgp
06:06 • Add attachment 760947.patch to ticket [760947ffff] artifact: 88ba2c3d57 user: dgp
05:46 • Ticket [760947ffff] trace on command leave changes errorInfo/errorCode statu... artifact: 202cfd2e1b user: msofer
05:03 • Ticket [760947ffff]: 6 changes artifact: 2e9ad14327 user: dgp
03:58 • Ticket [760947ffff]: 4 changes artifact: 17c8a9dc1f user: dgp
03:37 • Ticket [760947ffff]: 5 changes artifact: dd7971b887 user: dgp
00:55 • Ticket [760947ffff]: 4 changes artifact: 02d56c6e16 user: dgp
00:12 • Ticket [760947ffff]: 4 changes artifact: b4991d8215 user: dgp
2003-07-18
21:55 • Ticket [760947ffff]: 2 changes artifact: 8d08c91d6f user: dgp
17:33 • Ticket [760947ffff]: 4 changes artifact: a804666681 user: vincentdarley
02:53 • Ticket [760947ffff]: 5 changes artifact: 0765241875 user: dgp
2003-07-16
19:58 • Ticket [760947ffff]: 1 change artifact: 0b57bced23 user: dgp
2003-06-26
22:46 • Ticket [760947ffff]: 1 change artifact: 1201eb7c69 user: dgp
17:24 • Ticket [760947ffff]: 1 change artifact: 93a129ca25 user: dkf
04:02 • New ticket [760947ffff]. artifact: 48330313ae user: yahalom

trace on command leave changes errorInfo/errorCode

Closed / Fixed760947ffffffffffffffffffffffffffffffffffCreated 23 years agoUpdated 23 years ago
Descriptionplain2003-06-26 04:02:58
Tcl Version 8.4.3
OS Platform and Version: windows 2000,linux redhat 7.3

when putting a trace on command execution leave the 
errorInfo and errorCode are not being set properly when 
an error happens in the command being called

proc traceLog {cmd info {result ""} {op ""}} {
puts "----- trace -----"
puts "command: $cmd"
puts "info: $info"
puts "result: $result"
puts "op: $op"
puts "----- leave trace -----"
}
proc test {} {
error "testMsg" "testInfo" "testCode"
}
for {set i 0} {$i<2} {incr i} {
catch {test} msg
puts "message: $msg"
puts "errorInfo: $errorInfo"
puts "errorCode: $errorCode"
unset msg
unset errorCode
unset errorInfo
trace add execution test leave {traceLog}
}

result:

message: testMsg
errorInfo: testInfo
    (procedure "test"
    invoked from with
"test"
errorCode: testCode
----- trace -----
command: test
info: 1
result: testMsg
op: leave
----- leave trace ---
message: testMsg
errorInfo: testMsg
    while executing
"test"
errorCode: NONE
dkf Ticket [760947ffff]: 1 change [History diff]2003-06-26 17:24:07
dgp Ticket [760947ffff]: 1 change [History diff]2003-06-26 22:46:50
dgp Ticket [760947ffff]: 1 change [History diff]2003-07-16 19:58:26
dgpplain2003-07-18 02:53:35
Logged In: YES 
user_id=80530


Can I get another TIP 62 ruling?

Is this intended behavior?
vincentdarleyplain2003-07-18 17:33:15
Logged In: YES 
user_id=32170

Well, the manpage states (for 'leave' and 'leavestep' traces):

"If an error occurs while executing the command body, then 
the command name as a whole will return that same error."

The result above does look a little peculiar, although I don't 
really know enough about error(Code|Info) to be sure what 
the correct result should be.

In some sense if there's a leave trace on 'foo', then the result 
ought to be nearly identical to that obtained by manually 
replacing every occurrence of 'foo' in one's code by 'foo ; 
tracecmd foo ...'. (Obviously this is complicated by additional 
arguments, and by the cases where foo throws an error itself).
dgp Ticket [760947ffff]: 2 changes [History diff]2003-07-18 21:55:22
dgpplain2003-10-09 00:12:01
Logged In: YES 
user_id=80530

re-reading this, it seems that comment
in the docs makes either no sense,
or only tautological sense.  In context
"command" refers to the handler command,
not the traced command.  The name of
the traced command is known as "name"
in context.

Ahhh... hold on.  TIP 62 has the correct
specification.  This is a typo in the man page.
dgpplain2003-10-09 00:55:30
Logged In: YES 
user_id=80530

updated the docs to be the
same as TIP 62.

Unfortunately, the documented
behavior isn't completely 
possible, and isn't directly
"on point" for this report.

It's not possible, because multiple
execution traces may be set on
a single command, and if more that
one trace raises an error, it's not
possible for all of those error to become
the error of the traced command.

Generally error management during
execution tracing is way under-specified.

The issue in this report deals with a
simpler situation, where the traces
themselves raise no errors, but corrupt
the extra error information produced
by the traced command.
dgpplain2003-10-09 03:37:06
Logged In: YES 
user_id=80530


seems the way to fix this is to
save and restore the values
of ::errorCode and ::errorInfo
around the calling of leave traces.

potential problem is that this
will also cause any read
and write traces on those
variables to fire.

Seems it's not a safe enough
change to explore in time
for 8.4.5.  May need more
detailed sorting out and
testing through 8.5a development.
dgpplain2003-10-09 03:58:33
Logged In: YES 
user_id=80530

seems it's even worse that that.
While execution traces are
handled completely within
TclEvalObjvInternal(), the
management of errorCode
and errorInfo is all over the
place, so simple attempt to
fix this do not even work.
The real culprit may be
the Tcl_ResetResult()
embedded inside the execution
of the leave traces, which cause
the errorInfo and errorCode
machinery to get reset,
upsetting the expectations
of the [error] command,
which wants Tcl_LogCommandInfo
to respect the ERR_ALREADY_LOGGED
and ERROR_CODE_SET
flags that it set.
dgpplain2003-10-09 05:03:42
File Added - 63814: 760947.patch

Logged In: YES 
user_id=80530


Ha!  Yes, that's it.  Just needed
to get the flags right.  Here's a
patch that makes the demo
script act as expected, and
I think it does no damage.
Passing to another maintainer
for a second opinion.
msoferplain2003-10-09 05:46:19
Logged In: YES 
user_id=148712

Second opinion: I'm pretty sure it does no damage, but I do
not claim to really grok traces . Testsuite seems happy too ...
dgpplain2003-10-09 06:06:10
File Added - 63817: 760947.patch

Logged In: YES 
user_id=80530


Revised patch takes more care
to only save/restore the bits
that control error information.
That should ease any safety
concerns (deleted or safe
interps getting modified, etc...)
dgpplain2003-10-09 06:06:11
File Deleted - 63814:
dgpplain2003-10-09 06:11:18
File Added - 63818: 760947-HEAD.patch

Logged In: YES 
user_id=80530

Corresponding patch for the HEAD
must also save/restore return
options (TIP 90).
dgpplain2003-10-09 06:18:42
Logged In: YES 
user_id=80530


Fixed for 8.4.5+.
Log in (anonymous is fine) to add a comment.

Attachments: