Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

Are you making all this up as you go along?


comp / comp.lang.tcl / Re: try command error codes, where documented?

SubjectAuthor
* try command error codes, where documented?et99
`* Re: try command error codes, where documented?greg
 `* Re: try command error codes, where documented?et99
  `* Re: try command error codes, where documented?Harald Oehlmann
   `* Re: try command error codes, where documented?et99
    `* Re: try command error codes, where documented?clt.to.davebr
     `- Re: try command error codes, where documented?et99

1
Subject: try command error codes, where documented?
From: et99
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Fri, 16 Aug 2024 18:28 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: et99@rocketship1.me (et99)
Newsgroups: comp.lang.tcl
Subject: try command error codes, where documented?
Date: Fri, 16 Aug 2024 11:28:47 -0700
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <v9o5ov$1h561$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 16 Aug 2024 20:28:48 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="53a6822249c531a54b45aa61fb870516";
logging-data="1610945"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/GhxvHNNchS11moC07qyei"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:mp1AA0thJQRfDZyeC1tC2pv3aTk=
Content-Language: en-US
View all headers

Is there a good place to lookup the various error codes returned by tcl commands?

In the try command manual there's an example:

try {
set f [open /some/file/name w]
} trap {POSIX EISDIR} {} {
puts "failed to open /some/file/name: it's a directory"
} trap {POSIX ENOENT} {} {
puts "failed to open /some/file/name: it doesn't exist"
}

How did the writer of this example know about these two error cases since they are not documented in the manual under either try or open.

Also, are POSIX error codes system independent?

Subject: Re: try command error codes, where documented?
From: greg
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Sat, 17 Aug 2024 04:45 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: gregor.ebbing@gmx.de (greg)
Newsgroups: comp.lang.tcl
Subject: Re: try command error codes, where documented?
Date: Sat, 17 Aug 2024 06:45:59 +0200
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <v9p9u9$1poub$1@dont-email.me>
References: <v9o5ov$1h561$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 17 Aug 2024 06:46:01 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="794598c384991eff2b0d6c8b13a4a862";
logging-data="1893323"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/cdZQfIwN0mHUuOfljD9r72LZaFmdrT3c="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:pFZI1VtUhFjisugpjt9VTTC2DRo=
In-Reply-To: <v9o5ov$1h561$1@dont-email.me>
Content-Language: de-DE
View all headers

Am 16.08.24 um 20:28 schrieb et99:
> Is there a good place to lookup the various error codes returned by tcl
> commands?
>
> In the try command manual there's an example:
>
> try {
>     set f [open /some/file/name w]
> } trap {POSIX EISDIR} {} {
>     puts "failed to open /some/file/name: it's a directory"
> } trap {POSIX ENOENT} {} {
>     puts "failed to open /some/file/name: it doesn't exist"
> }
>
> How did the writer of this example know about these two error cases
> since they are not documented in the manual under either try or open.
>
> Also, are POSIX error codes system independent?
>
>

Hello;
maybe this helps:

https://www.tcl.tk/man/tcl8.6/TclCmd/tclvars.htm#M12

source code tcl 8.6
../tcl8.6.14/win/tclWinError.c
/.tcl8.6.14/generic/tclPosixStr.c

https://en.wikipedia.org/wiki/Errno.h

Subject: Re: try command error codes, where documented?
From: et99
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Sat, 17 Aug 2024 07:09 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: et99@rocketship1.me (et99)
Newsgroups: comp.lang.tcl
Subject: Re: try command error codes, where documented?
Date: Sat, 17 Aug 2024 00:09:08 -0700
Organization: A noiseless patient Spider
Lines: 46
Message-ID: <v9piak$1qmrc$1@dont-email.me>
References: <v9o5ov$1h561$1@dont-email.me> <v9p9u9$1poub$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 17 Aug 2024 09:09:08 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="b2bb8f1521785b05de1481ba2ec0a88b";
logging-data="1923948"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18H2McA6xorM4YBxxLjmy9C"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:a45Jo2W/rrRrTJoGCZjg52Tbhzo=
In-Reply-To: <v9p9u9$1poub$1@dont-email.me>
Content-Language: en-US
View all headers

On 8/16/2024 9:45 PM, greg wrote:
> Am 16.08.24 um 20:28 schrieb et99:
>> Is there a good place to lookup the various error codes returned by tcl commands?
>>
>> In the try command manual there's an example:
>>
>> try {
>>      set f [open /some/file/name w]
>> } trap {POSIX EISDIR} {} {
>>      puts "failed to open /some/file/name: it's a directory"
>> } trap {POSIX ENOENT} {} {
>>      puts "failed to open /some/file/name: it doesn't exist"
>> }
>>
>> How did the writer of this example know about these two error cases since they are not documented in the manual under either try or open.
>>
>> Also, are POSIX error codes system independent?
>>
>>
>
> Hello;
> maybe this helps:
>
> https://www.tcl.tk/man/tcl8.6/TclCmd/tclvars.htm#M12
>
> source code tcl 8.6
> ./tcl8.6.14/win/tclWinError.c
> /.tcl8.6.14/generic/tclPosixStr.c
>
>
> https://en.wikipedia.org/wiki/Errno.h

Thanks for the links.

I was afraid this was probably the only way to get the codes.

I think this could make a useful TIP - to add an error section to all command man pages as is done in the linux man pages.

If I were 30 years younger, with the inherent time and energy, I might have volunteered to do this, since it is obviously a tedious and perhaps thankless job.

I guess I will just stick to using my if-catch-template and not try to differentiate the particular errors. Besides, only I ever use my programs anymore :)

-e

Subject: Re: try command error codes, where documented?
From: Harald Oehlmann
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Mon, 19 Aug 2024 08:01 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: wortkarg3@yahoo.com (Harald Oehlmann)
Newsgroups: comp.lang.tcl
Subject: Re: try command error codes, where documented?
Date: Mon, 19 Aug 2024 10:01:43 +0200
Organization: A noiseless patient Spider
Lines: 85
Message-ID: <v9uu53$2paeg$2@dont-email.me>
References: <v9o5ov$1h561$1@dont-email.me> <v9p9u9$1poub$1@dont-email.me>
<v9piak$1qmrc$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 19 Aug 2024 10:01:39 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="d5e9aa3409b5c7c28367b9fc4da548b4";
logging-data="2927056"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+PqfIrT0cXhTkt6A+fhKAd"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:dEATGt/xiYvm1xsHcAxMluHbUtM=
Content-Language: en-GB
In-Reply-To: <v9piak$1qmrc$1@dont-email.me>
View all headers

Am 17.08.2024 um 09:09 schrieb et99:
> On 8/16/2024 9:45 PM, greg wrote:
>> Am 16.08.24 um 20:28 schrieb et99:
>>> Is there a good place to lookup the various error codes returned by
>>> tcl commands?
>>>
>>> In the try command manual there's an example:
>>>
>>> try {
>>>      set f [open /some/file/name w]
>>> } trap {POSIX EISDIR} {} {
>>>      puts "failed to open /some/file/name: it's a directory"
>>> } trap {POSIX ENOENT} {} {
>>>      puts "failed to open /some/file/name: it doesn't exist"
>>> }
>>>
>>> How did the writer of this example know about these two error cases
>>> since they are not documented in the manual under either try or open.
>>>
>>> Also, are POSIX error codes system independent?
>>>
>>>
>>
>> Hello;
>> maybe this helps:
>>
>> https://www.tcl.tk/man/tcl8.6/TclCmd/tclvars.htm#M12
>>
>> source code tcl 8.6
>> ./tcl8.6.14/win/tclWinError.c
>> /.tcl8.6.14/generic/tclPosixStr.c
>>
>>
>> https://en.wikipedia.org/wiki/Errno.h
>
>
> Thanks for the links.
>
> I was afraid this was probably the only way to get the codes.
>
> I think this could make a useful TIP - to add an error section to all
> command man pages as is done in the linux man pages.
>
> If I were 30 years younger, with the inherent time and energy, I might
> have volunteered to do this, since it is obviously a tedious and perhaps
> thankless job.
>
> I guess I will just stick to using my if-catch-template and not try to
> differentiate the particular errors. Besides, only I ever use my
> programs anymore :)

Thank you for the words and the initiative.
Reality is worse. We are on 3 platforms.
So, we try to get the same error code on all of them.
Errors come often from system calls. On Posix systems, they are just put
up to the script. On WIndows, Windows error codes are mapped to possix
error codes, which works more or less...

Remark that error codes are also available by catch.

The advantage of try is that you have a cleanup case, which is always
executed, even on error and on return.

so:

proc t {fn} {
try {
set f [open $fn]
set d [read $f]
return $d
} trap ...
} on ...
} finally {
if {[info exists f]} {close $f}
} }

Closes the file in any handling case. It is beautiful, that the finally
happens after the return command and the return still works.

This is a constructed example. But it might be handy.

Take care,
Harald

Subject: Re: try command error codes, where documented?
From: et99
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Wed, 21 Aug 2024 01:17 UTC
References: 1 2 3 4
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: et99@rocketship1.me (et99)
Newsgroups: comp.lang.tcl
Subject: Re: try command error codes, where documented?
Date: Tue, 20 Aug 2024 18:17:41 -0700
Organization: A noiseless patient Spider
Lines: 58
Message-ID: <va3f7m$3j3ao$1@dont-email.me>
References: <v9o5ov$1h561$1@dont-email.me> <v9p9u9$1poub$1@dont-email.me>
<v9piak$1qmrc$1@dont-email.me> <v9uu53$2paeg$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 21 Aug 2024 03:17:43 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="57d37fd883c60efb724567fd9b814674";
logging-data="3771736"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/5slJIzVc/lCaUcoQaAi6/"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:cJwxmePuLRSXT5AVzLrFS5rMxaE=
Content-Language: en-US
In-Reply-To: <v9uu53$2paeg$2@dont-email.me>
View all headers

On 8/19/2024 1:01 AM, Harald Oehlmann wrote:
> Am 17.08.2024 um 09:09 schrieb et99:
>> On 8/16/2024 9:45 PM, greg wrote:
>>> Am 16.08.24 um 20:28 schrieb et99:
>>>> Is there a good place to lookup the various error codes returned by tcl commands?

...snip

> Thank you for the words and the initiative.
> Reality is worse. We are on 3 platforms.
> So, we try to get the same error code on all of them.
> Errors come often from system calls. On Posix systems, they are just put up to the script. On WIndows, Windows error codes are mapped to possix error codes, which works more or less...
>
> Remark that error codes are also available by catch.

I see the problem. However, many tcl command manual entries have sections describing differences between systems. If error codes are different, that would be an appropriate place to document that as well.

I was thinking about the leverage one would have if all the error codes were documented in one place. By them not being easy to find, I just take the lazy course and use catch and write out whatever error message the catch returns. If they were documented once, then (all) programmers would have an easier time.

>
> The advantage of try is that you have a cleanup case, which is always executed, even on error and on return.
>
> so:
>
> proc t {fn} {
> try {
> set f [open $fn]
> set d [read $f]
> return $d
> } trap ...
> } on ...
> } finally {
>     if {[info exists f]} {close $f}
> }
> }
>
> Closes the file in any handling case. It is beautiful, that the finally happens after the return command and the return still works.
>
> This is a constructed example. But it might be handy.

This finally behavior I had not known. It also seems quite remarkable to me since ordinarily once a return statement is executed, the stack frame would be expected to be popped and so that variable f would no longer be accessible. Clearly try must be doing something special if it can execute code after a return command.

I just re-read both return and try manual pages and I cannot find anywhere that mentions this behavior explicitly with a return command. Frankly, this seems like a good way to create a lurking bug.

It reminds me of the C code gotcha where a programmer added the andthis w/o realizing the scope of the if statement:

if(boolean)
dothis;
andthis;

-e

Subject: Re: try command error codes, where documented?
From: clt.to.davebr@dfgh.net
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Wed, 21 Aug 2024 05:08 UTC
References: 1 2 3 4 5
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: clt.to.davebr@dfgh.net
Newsgroups: comp.lang.tcl
Subject: Re: try command error codes, where documented?
Date: Wed, 21 Aug 24 05:08:02 GMT
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <99917242168821001@llp>
References: <v9o5ov$1h561$1@dont-email.me> <v9p9u9$1poub$1@dont-email.me> <v9piak$1qmrc$1@dont-email.me> <v9uu53$2paeg$2@dont-email.me> <va3f7m$3j3ao$1@dont-email.me>
Injection-Date: Wed, 21 Aug 2024 07:10:24 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="10d474cc6d2cf1f5a60e5b6d9fb5083d";
logging-data="3946709"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/cj1etQTe4b8KZPrSlLHOI"
Cancel-Lock: sha1:aoXRewAhRRSHPgwjvUijW1fHt0s=
In-Reply-To: <va3f7m$3j3ao$1@dont-email.me>
View all headers

>This finally behavior I had not known. It also seems quite remarkable to me since ordinarily once a return statement is executed, the stack frame would be expected to be popped and so that variable f would no longer be accessible. Clearly try must be doing something special if it can execute code after a return command.

From the first paragraph of the try man page:

.... if the finally clause is present, the script it includes will be run and the result of the handler (or the body if no handler matched) is allowed to continue to propogate.

The "result of the body" is the result from the try script, not the finally script.

I'm kind of amazed it works too, but it is very nice that it does. My most common use for try {...} finally {...} is to close a file regardless of any errors after reading and maybe processing the contents inside the try script.

daveb

Subject: Re: try command error codes, where documented?
From: et99
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Thu, 22 Aug 2024 21:43 UTC
References: 1 2 3 4 5 6
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: et99@rocketship1.me (et99)
Newsgroups: comp.lang.tcl
Subject: Re: try command error codes, where documented?
Date: Thu, 22 Aug 2024 14:43:34 -0700
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <va8be7$j3e0$1@dont-email.me>
References: <v9o5ov$1h561$1@dont-email.me> <v9p9u9$1poub$1@dont-email.me>
<v9piak$1qmrc$1@dont-email.me> <v9uu53$2paeg$2@dont-email.me>
<va3f7m$3j3ao$1@dont-email.me> <99917242168821001@llp>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 22 Aug 2024 23:43:36 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="9e54bbb846b70ce3b5fa83f3819add61";
logging-data="626112"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19u2cIbwuoYHC3VcMeAdbfo"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:AG0THAO5nfjhBfE931Rg7asuFjk=
Content-Language: en-US
In-Reply-To: <99917242168821001@llp>
View all headers

On 8/20/2024 10:08 PM, clt.to.davebr@dfgh.net wrote:

>
> I'm kind of amazed it works too, but it is very nice that it does. My most common use for try {...} finally {...} is to close a file regardless of any errors after reading and maybe processing the contents inside the try script.
>
> daveb
>
>
>

Well, I *finally* decided to read sections 11.2-3 in Ashok's great Tcl book and the text and examples there has cleared up everything for me.

That explains how the try command can execute the finally clause *after* the execution of the return command. It's because try gets to do whatever it wants with the return code of 2 that the return command itself returns.

-e

1

rocksolid light 0.9.8
clearnet tor