Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Gary Hart: living proof that you *can* screw your brains out.


devel / comp.lang.tcl / Re: new control structure, uplevel and proper error forwarding

SubjectAuthor
* new control structure, uplevel and proper error forwardingPetro Kazmirchuk
`* new control structure, uplevel and proper error forwardingGerald Lester
 `* new control structure, uplevel and proper error forwardingPetro Kazmirchuk
  `- new control structure, uplevel and proper error forwardingGerald Lester

1
new control structure, uplevel and proper error forwarding

<4a7104ae-7cfc-4ba1-b4c0-283c423ffb77n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10498&group=comp.lang.tcl#10498

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:ac8:6684:0:b0:3a8:2b88:81cd with SMTP id d4-20020ac86684000000b003a82b8881cdmr1880519qtp.176.1672756986385;
Tue, 03 Jan 2023 06:43:06 -0800 (PST)
X-Received: by 2002:ad4:5288:0:b0:531:9495:61e6 with SMTP id
v8-20020ad45288000000b00531949561e6mr1326591qvr.31.1672756986233; Tue, 03 Jan
2023 06:43:06 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!3.eu.feeder.erje.net!3.us.feeder.erje.net!feeder.erje.net!border-1.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Tue, 3 Jan 2023 06:43:06 -0800 (PST)
Injection-Info: google-groups.googlegroups.com; posting-host=193.163.1.59; posting-account=yD4T_QoAAAAzNGigQobo9AtcgLgheZii
NNTP-Posting-Host: 193.163.1.59
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <4a7104ae-7cfc-4ba1-b4c0-283c423ffb77n@googlegroups.com>
Subject: new control structure, uplevel and proper error forwarding
From: petro.ka...@gmail.com (Petro Kazmirchuk)
Injection-Date: Tue, 03 Jan 2023 14:43:06 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 24
 by: Petro Kazmirchuk - Tue, 3 Jan 2023 14:43 UTC

there's a lot of information on Tcl Wiki on the subject, but most of it pre-dates 8.6
I've read a whole lot, and still couldn't figure out a clean way to remove my new control structure from an error's callstack.

Consider:
proc duration {script varName} {
upvar 1 $varName elapsed
set now [clock millis]
uplevel 1 $script
set elapsed [expr {[clock millis] - $now}]
} to be used as:
duration {
set result [foo]
} elapsed
I don't care about return codes "break" and "continue"
I save the return value of $script myself
The problem is that if [foo] raises an error, and I catch it outside [duration], the -errorstack will contain things like "UP 1 CALL duration" that I'd prefer to hide. Experimenting with return -level 2 didn't help, and I can't use tailcall because then I can't compute $elapsed.
I've looked at Tcllib's ascaller.tcl, but it clearly pre-dates 8.6 too, and I don't want to rely on it just for the sake of one proc.
Thanks in advance

Re: new control structure, uplevel and proper error forwarding

<tp1f5p$13p4$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10499&group=comp.lang.tcl#10499

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!uo8TmemMtp6nxYqNz/lvbA.user.46.165.242.75.POSTED!not-for-mail
From: Gerald.L...@KnG-Consulting.net (Gerald Lester)
Newsgroups: comp.lang.tcl
Subject: Re: new control structure, uplevel and proper error forwarding
Date: Tue, 3 Jan 2023 08:47:21 -0600
Organization: KnG Consulting, LLC
Message-ID: <tp1f5p$13p4$1@gioia.aioe.org>
References: <4a7104ae-7cfc-4ba1-b4c0-283c423ffb77n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="36644"; posting-host="uo8TmemMtp6nxYqNz/lvbA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.4.2
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Gerald Lester - Tue, 3 Jan 2023 14:47 UTC

On 1/3/23 08:43, Petro Kazmirchuk wrote:
> there's a lot of information on Tcl Wiki on the subject, but most of it pre-dates 8.6
> I've read a whole lot, and still couldn't figure out a clean way to remove my new control structure from an error's callstack.
>
> Consider:
> proc duration {script varName} {
> upvar 1 $varName elapsed
> set now [clock millis]
> uplevel 1 $script
> set elapsed [expr {[clock millis] - $now}]
> }
> to be used as:
> duration {
> set result [foo]
> } elapsed
> I don't care about return codes "break" and "continue"
> I save the return value of $script myself
> The problem is that if [foo] raises an error, and I catch it outside [duration], the -errorstack will contain things like "UP 1 CALL duration" that I'd prefer to hide. Experimenting with return -level 2 didn't help, and I can't use tailcall because then I can't compute $elapsed.
> I've looked at Tcllib's ascaller.tcl, but it clearly pre-dates 8.6 too, and I don't want to rely on it just for the sake of one proc.
> Thanks in advance

You need to catch it in duration and reraise the error with the stack
information you want via the error or return commands (depending on what
you want).

--
+----------------------------------------------------------------------+
| Gerald W. Lester, President, KNG Consulting LLC |
| Email: Gerald.Lester@kng-consulting.net |
+----------------------------------------------------------------------+

Re: new control structure, uplevel and proper error forwarding

<9086327e-49e1-4bcb-964e-badf03fb2b88n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10500&group=comp.lang.tcl#10500

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:ac8:7219:0:b0:3a8:2e0b:7715 with SMTP id a25-20020ac87219000000b003a82e0b7715mr1469083qtp.416.1672760206239;
Tue, 03 Jan 2023 07:36:46 -0800 (PST)
X-Received: by 2002:a37:6594:0:b0:6fe:c37a:e8d6 with SMTP id
z142-20020a376594000000b006fec37ae8d6mr2464442qkb.40.1672760206051; Tue, 03
Jan 2023 07:36:46 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Tue, 3 Jan 2023 07:36:45 -0800 (PST)
In-Reply-To: <tp1f5p$13p4$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=193.163.1.59; posting-account=yD4T_QoAAAAzNGigQobo9AtcgLgheZii
NNTP-Posting-Host: 193.163.1.59
References: <4a7104ae-7cfc-4ba1-b4c0-283c423ffb77n@googlegroups.com> <tp1f5p$13p4$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <9086327e-49e1-4bcb-964e-badf03fb2b88n@googlegroups.com>
Subject: Re: new control structure, uplevel and proper error forwarding
From: petro.ka...@gmail.com (Petro Kazmirchuk)
Injection-Date: Tue, 03 Jan 2023 15:36:46 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2336
 by: Petro Kazmirchuk - Tue, 3 Jan 2023 15:36 UTC

This is how -errorinfo looks when I call [foo] directly:

my error
while executing
"throw AAA "my error""
(procedure "bar" line 2)
invoked from within
"bar"
(procedure "foo" line 2)
invoked from within
"foo"
("try" body line 3)

nice and clean - this is what I want to achieve with [duration]

Let's try to handle the error:
proc duration {script varName} {
upvar 1 $varName elapsed
set now [clock millis]
if {[catch {uplevel 1 $script} result errOpts]} {
dict incr errOpts -level ;# makes no difference, but I did my due diligence
return -options $errOpts $result
}
set elapsed [expr {[clock millis] - $now}]
}

resulting -errorinfo:

my error
while executing
"throw AAA "my error""
(procedure "bar" line 2)
invoked from within
"bar"
(procedure "foo" line 2)
invoked from within
"foo"
("uplevel" body line 2)
invoked from within
"uplevel 1 $script"
invoked from within
"duration {
foo
} elapsed"
("try" body line 2)

P.S. is it possible to format Tcl code somehow here? it becomes really unreadable after posting :(

Re: new control structure, uplevel and proper error forwarding

<tp3vql$r9e$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10502&group=comp.lang.tcl#10502

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!fNWdM1l90cyJADw128ZATQ.user.46.165.242.75.POSTED!not-for-mail
From: Gerald.L...@KnG-Consulting.net (Gerald Lester)
Newsgroups: comp.lang.tcl
Subject: Re: new control structure, uplevel and proper error forwarding
Date: Wed, 4 Jan 2023 07:43:48 -0600
Organization: KnG Consulting, LLC
Message-ID: <tp3vql$r9e$1@gioia.aioe.org>
References: <4a7104ae-7cfc-4ba1-b4c0-283c423ffb77n@googlegroups.com>
<tp1f5p$13p4$1@gioia.aioe.org>
<9086327e-49e1-4bcb-964e-badf03fb2b88n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="27950"; posting-host="fNWdM1l90cyJADw128ZATQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.4.2
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Gerald Lester - Wed, 4 Jan 2023 13:43 UTC

On 1/3/23 09:36, Petro Kazmirchuk wrote:
> This is how -errorinfo looks when I call [foo] directly:
>
> my error
> while executing
> "throw AAA "my error""
> (procedure "bar" line 2)
> invoked from within
> "bar"
> (procedure "foo" line 2)
> invoked from within
> "foo"
> ("try" body line 3)
>
> nice and clean - this is what I want to achieve with [duration]
>
> Let's try to handle the error:
> proc duration {script varName} {
> upvar 1 $varName elapsed
> set now [clock millis]
> if {[catch {uplevel 1 $script} result errOpts]} {
> dict incr errOpts -level ;# makes no difference, but I did my due diligence
> return -options $errOpts $result
> }
> set elapsed [expr {[clock millis] - $now}]
> }
>
> resulting -errorinfo:
>
> my error
> while executing
> "throw AAA "my error""
> (procedure "bar" line 2)
> invoked from within
> "bar"
> (procedure "foo" line 2)
> invoked from within
> "foo"
> ("uplevel" body line 2)
> invoked from within
> "uplevel 1 $script"
> invoked from within
> "duration {
> foo
> } elapsed"
> ("try" body line 2)
>
> P.S. is it possible to format Tcl code somehow here? it becomes really unreadable after posting :(

You only did part of the work -- remove the uplevel from the trace in
errOpts (any anything else you want).

It is all under your control.
--
+----------------------------------------------------------------------+
| Gerald W. Lester, President, KNG Consulting LLC |
| Email: Gerald.Lester@kng-consulting.net |
+----------------------------------------------------------------------+


devel / comp.lang.tcl / Re: new control structure, uplevel and proper error forwarding

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor