Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: et99 Newsgroups: comp.lang.tcl Subject: Re: Show argument values in bgerror Date: Tue, 17 Sep 2024 19:32:55 -0700 Organization: A noiseless patient Spider Lines: 65 Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Wed, 18 Sep 2024 04:32:55 +0200 (CEST) Injection-Info: dont-email.me; posting-host="d2b8cdfd620b59c4d9bd094d3220daf9"; logging-data="4108242"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19qnkLJMtGJnYAhsRdAGBYY" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:IE9eCmUb+wa83xh7npRnwfd4fsM= In-Reply-To: Content-Language: en-US Bytes: 2972 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