Sujet : Re: Show argument values in bgerror
De : et99 (at) *nospam* rocketship1.me (et99)
Groupes : comp.lang.tclDate : 18. Sep 2024, 03:32:55
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vcde4n$3tbui$1@dont-email.me>
References : 1
User-Agent : Mozilla Thunderbird
On 9/17/2024 2:31 PM, alexandru wrote:
I have this ::bgerror function to help debug errors in program flow:
proc ::bgerror {message} {
global errorInfo
puts "*** START OF ERROR MESSAGE ***\n$message\n$errorInfo\n*** END OF
ERROR MESSAGE ***"
}
The issue is, that the errorInfo does not show the values of the
arguments of called procedures in the stack.
Thus it's often not clear which arguments lead the the error.
Is there a trick how to show the values with which the procedures were
called in the stack prior to the error?
Many thanks
Alexandru
Here's some test code I cobbled together, I think there may be something here that does what you want. The "info level [info level]" might be just what you need, if issued at the proper uplevel. Note, the outer info has 2 args, the inner info only 1 and that's intentional. You likely would iterate on uplevel's and toss ones that give an error.
console show
proc foo {} {foo2 11 22 33}
proc foo2 {a b c} {set x 1; set y 2; foo3}
proc foo3 {} {
set level [info frame]
puts "level= |$level| "
set vars [ \
uplevel 1 {
set _vars [info vars]
puts "_vars= |$_vars| level= [info frame] args= [info level [info level]]"
foreach _var $_vars {
puts " _var= |$_var| "
lappend _varsx "$_var = [set $_var]"
}
set _varsx
}
]
puts "vars= |$vars| "
puts [join $vars \n]
}
if [catch {
foo
} err_code] {
puts $err_code
}
output:
level= |9|
_vars= |a b c x y| level= 10 args= foo2 11 22 33
_var= |a|
_var= |b|
_var= |c|
_var= |x|
_var= |y|
vars= |{a = 11} {b = 22} {c = 33} {x = 1} {y = 2}|
a = 11
b = 22
c = 33
x = 1
y = 2