Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

Building translators is good clean fun. -- T. Cheatham


devel / comp.lang.tcl / How do I hack Tk error messages?

SubjectAuthor
* How do I hack Tk error messages?Luc
+- How do I hack Tk error messages?et99
+* How do I hack Tk error messages?Rich
|`* How do I hack Tk error messages?Luc
| `- How do I hack Tk error messages?Rich
`- How do I hack Tk error messages?Don Porter

1
How do I hack Tk error messages?

<20240106204610.43fe78b6@lud1.home>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=13104&group=comp.lang.tcl#13104

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: luc@sep.invalid (Luc)
Newsgroups: comp.lang.tcl
Subject: How do I hack Tk error messages?
Date: Sat, 6 Jan 2024 20:46:10 -0300
Organization: A noiseless patient Spider
Lines: 47
Message-ID: <20240106204610.43fe78b6@lud1.home>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="668b3f6add0b3ef931ababf55d9e8b0d";
logging-data="842004"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18VSiA65ur7GpOl2jzP3bwOAB4RpFmWVKA="
Cancel-Lock: sha1:bSNywYrgjgyMtwssqr8VZboTfvA=
 by: Luc - Sat, 6 Jan 2024 23:46 UTC

One of the rare things I dislike about Tcl/Tk is the error messages.
They pop up and I hate them.

Well, I've changed them a little. Larger, much better font, better key
bindings and automatic focus so it's easier to copy the error message,
which I like to do so I can dismiss the error and paste the message
elsewhere for reference.

OK.

But this really annoys me:

can't read "dir": no such variable
can't read "dir": no such variable
while executing
"set dir"
(procedure "p.RunTime.Navigate" line 141)
invoked from within
"p.RunTime.Navigate "Up""
(command bound to event)

I hate it because line 141 is pointed out, but 141 is counted within
the proc! It's very hard to find. That is another reason for me to make
copying more convenient, so I can copy the bad line and pray that I
can find it exactly.

[dict get [info frame 0] line] can give me an exact, absolute line
number in relation to the entire file so why can't Tk error messages?
What file do I hack to achieve that?

I made the changes I mentioned earlier in this file:
/usr/share/tcltk/tk8.6/bgerror.tcl

Every error message says "while executing" and "invoked from within".
But grep can only find those strings in /usr/share/tcltk/tcl8.6/init.tcl.
And when I change, say, "while executing" to "while dancing hula" the
changes are not reflected in the error messages. So I won't even waste
my time trying to understand that file. What I want is not there.

Where is it?

--
Luc
>>

Re: How do I hack Tk error messages?

<und37p$qv93$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=13105&group=comp.lang.tcl#13105

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: et99@rocketship1.me (et99)
Newsgroups: comp.lang.tcl
Subject: Re: How do I hack Tk error messages?
Date: Sat, 6 Jan 2024 18:45:13 -0800
Organization: A noiseless patient Spider
Lines: 81
Message-ID: <und37p$qv93$1@dont-email.me>
References: <20240106204610.43fe78b6@lud1.home>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 7 Jan 2024 02:45:13 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="b80018e697652f7a70f3d29c62a5394d";
logging-data="884003"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/iJZ6GO8yj8zxxxpgptA61"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.6.1
Cancel-Lock: sha1:Q2W2a7sv1pXCpHPLZipCJK6/b8g=
In-Reply-To: <20240106204610.43fe78b6@lud1.home>
Content-Language: en-US
 by: et99 - Sun, 7 Jan 2024 02:45 UTC

On 1/6/2024 3:46 PM, Luc wrote:
> One of the rare things I dislike about Tcl/Tk is the error messages.
> They pop up and I hate them.
>
> Well, I've changed them a little. Larger, much better font, better key
> bindings and automatic focus so it's easier to copy the error message,
> which I like to do so I can dismiss the error and paste the message
> elsewhere for reference.
>
> OK.
>
> But this really annoys me:
>
> can't read "dir": no such variable
> can't read "dir": no such variable
> while executing
> "set dir"
> (procedure "p.RunTime.Navigate" line 141)
> invoked from within
> "p.RunTime.Navigate "Up""
> (command bound to event)
>
>
> I hate it because line 141 is pointed out, but 141 is counted within
> the proc! It's very hard to find. That is another reason for me to make
> copying more convenient, so I can copy the bad line and pray that I
> can find it exactly.
>
> [dict get [info frame 0] line] can give me an exact, absolute line
> number in relation to the entire file so why can't Tk error messages?
> What file do I hack to achieve that?
>
> I made the changes I mentioned earlier in this file:
> /usr/share/tcltk/tk8.6/bgerror.tcl
>
> Every error message says "while executing" and "invoked from within".
> But grep can only find those strings in /usr/share/tcltk/tcl8.6/init.tcl.
> And when I change, say, "while executing" to "while dancing hula" the
> changes are not reflected in the error messages. So I won't even waste
> my time trying to understand that file. What I want is not there.
>
> Where is it?
>
>
Part of the problem is that \<nl>'s are absorbed by the parser before the text is saved. The reporting of proc relative line numbers may not agree with those in a text editor. However, [info body] can be used to list the same line numbers that the error reporting outputs:

# heinrichmartin version from clt post, reconstruct proc(s) in a list
proc lp3 {{namepat *}} {
set ans [lmap p [uplevel 1 info procs [list $namepat]] {
set globp [uplevel 1 namespace which -command [list $p]]
set args [lmap arg [info args $globp] {
if {[info default $globp $arg val]} {
list $arg $val
} else {
list $arg
}
}]
list proc $p $args [info body $globp]
}]
return $ans
}

# puts proc(s) with line numbers arg= [info proc] pattern
proc lpn {arg} {
foreach p [lp3 $arg] {
puts "#--------- [lindex $p 1 ] ------------"
set lnum 0
foreach line [split $p \n] {
puts "[incr lnum]\t$line"
}
}
}

Try:

lpn lp?

Re: How do I hack Tk error messages?

<und802$vadk$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=13106&group=comp.lang.tcl#13106

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: rich@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: How do I hack Tk error messages?
Date: Sun, 7 Jan 2024 04:06:26 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 98
Message-ID: <und802$vadk$1@dont-email.me>
References: <20240106204610.43fe78b6@lud1.home>
Injection-Date: Sun, 7 Jan 2024 04:06:26 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="848de04a1cc71e1163f22940425b1b88";
logging-data="1026484"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18I866xhI8LRxwZbIECQD7i"
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Cancel-Lock: sha1:vxl9pwDn+rp3rDNoVrwMqfCSUAw=
 by: Rich - Sun, 7 Jan 2024 04:06 UTC

Luc <luc@sep.invalid> wrote:
> One of the rare things I dislike about Tcl/Tk is the error messages.
> They pop up and I hate them.

If you wish to have the feedback, the information has to go somewhere.
Do note that you are going on about the "default" error popups, which
if they were not present would likely leave you with the basic C
equivalent of:

segmentation fault: process aborted

And absolutely no information on where.

> Well, I've changed them a little. Larger, much better font, better key
> bindings and automatic focus so it's easier to copy the error message,
> which I like to do so I can dismiss the error and paste the message
> elsewhere for reference.

If you catch your own errors you can have any form of error message you
want to code. But you have to catch the errors (via either [catch] or
[try]) and then handle the error conditions yourself. Such is more
work, but you can have very finely tuned, highly relevant, error
feedback that way. But complaining about the provided default, which
if not provided would give you a "process aborted" message instead, is
a bit disingenuous. The default message, if you don't bother to catch
your errors and provide your own message, necessarially needs to be
reasonably generic and generally useful (and, compare Tcl's messages
with what Python or [shudder] Java provides on an error one day, and
you'll praise Tcl's nice, clean, useful, messages instead).

> OK.
>
> But this really annoys me:
>
> can't read "dir": no such variable
> can't read "dir": no such variable
> while executing
> "set dir"
> (procedure "p.RunTime.Navigate" line 141)
> invoked from within
> "p.RunTime.Navigate "Up""
> (command bound to event)
>
>
> I hate it because line 141 is pointed out, but 141 is counted within
> the proc! It's very hard to find.

Not a all. I jump my editor to the first line of the proc mentioned,
then I command the editor to do "down arrow" 141 times, and I arrive at
the very line that Tcl has referenced. Nothing could be simpler to
find.

Do note that the above does require one's editor to have the ability to
"repeat" an edit operation some number of times. I use joe (Joe's Own
Editor, https://en.wikipedia.org/wiki/Joe's_Own_Editor) in the jstar
configuration.

> That is another reason for me to make copying more convenient, so I
> can copy the bad line and pray that I can find it exactly.

I should note here that on a modern windowing system with
multi-tasking, that you can keep the tk error message dialog up while
simultaneously switching to the other window where you editor is
running, so that you can move about in your editor while simultaneously
viewing the Tk error popup. I do this all the time when I'm writing
Tcl/Tk code. The dialog pops up for some syntax error or type error,
and unless it happens to be for the last 5-10 new lines I just wrote, I
simply leave it open, switch to my editor window, and go about finding
the issue while the Tk message box is visible.

> [dict get [info frame 0] line] can give me an exact, absolute line
> number in relation to the entire file so why can't Tk error messages?

Possibly no one thought to do so, or the default error handling was
setup long ago (possibly before the 'line' key of info frame 0 existed)
and no one's been bothered enough by it to bother with tweaking it?

> What file do I hack to achieve that?

Unfortunately I have no idea. I've never been bothered by the message
(and compared to Python or Java Tcl's messages are a dream of
usefulness) and so have never sought out what to change. And for
anything I write for consumption by others, I catch errors and provide
custom, domain specific, feedback, I don't expect others to want to see
the default popup.

> Where is it?

The default error popup window is provided by the default bgerror
handler proc provided by Tcl. On my Slackware system the default
bgerror proc is defined in /usr/lib64/tk8.6/bgerror.tcl.

If you want to make changes, start by copying that file into your code,
then make your changes locally, the source your local changed copy
sometime during your startup (which will then overwrite the default
with your new and improved one) and you'll have a different dialog (or
even no dialog at all if you so desire).

Re: How do I hack Tk error messages?

<20240107020254.0f93a917@lud1.home>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=13108&group=comp.lang.tcl#13108

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: luc@sep.invalid (Luc)
Newsgroups: comp.lang.tcl
Subject: Re: How do I hack Tk error messages?
Date: Sun, 7 Jan 2024 02:02:53 -0300
Organization: A noiseless patient Spider
Lines: 71
Message-ID: <20240107020254.0f93a917@lud1.home>
References: <20240106204610.43fe78b6@lud1.home>
<und802$vadk$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="5ad61530f9796c8e4620a64da94f6b8e";
logging-data="1025843"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/hAzHveomdvFPbUlUA0/XOMcPGjj/+6gE="
Cancel-Lock: sha1:69XRk2mChmHElALIkG15c0tjIKk=
 by: Luc - Sun, 7 Jan 2024 05:02 UTC

On Sun, 7 Jan 2024 04:06:26 -0000 (UTC), Rich wrote:

>if they were not present would likely leave you with the basic C
>equivalent of:
>
>segmentation fault: process aborted
>
>And absolutely no information on where.

Of course, I understand, you do have a point, but you also sound like
you could have added something like "in the snow uphill both ways." :-)

It just seems to me that the error message is showing its age and could
be improved. I have improved it myself a little already.

> If you catch your own errors you can have any form of error message
> you want to code. But you have to catch the errors (via either
> [catch] or [try]) and then handle the error conditions yourself.

That suggestion calls to my mind the image of a basement with a large
array of mouse traps strewn all over, one or two going SNAP! every now
and then.

I don't want to pepper my code with God knows how many catch statements
in every possible corner. I just want a better error message.

>Not a all. I jump my editor to the first line of the proc mentioned,
>then I command the editor to do "down arrow" 141 times, and I arrive at
>the very line that Tcl has referenced. Nothing could be simpler to
>find.
>
>Do note that the above does require one's editor to have the ability to
>"repeat" an edit operation some number of times. I use joe (Joe's Own
>Editor, https://en.wikipedia.org/wiki/Joe's_Own_Editor) in the jstar
>configuration.

Ah. My first thought was, "Vi user detected."

I am familiar with joe, but I don't like it. I use geany. I like it
a lot.

>Unfortunately I have no idea. I've never been bothered by the message
>(and compared to Python or Java Tcl's messages are a dream of
>usefulness)

Yes, Tcl is better than Python and Java. And the sky looks blue unless
you're English. We can all agree on that.

>> Where is it?
>
>The default error popup window is provided by the default bgerror
>handler proc provided by Tcl. On my Slackware system the default
>bgerror proc is defined in /usr/lib64/tk8.6/bgerror.tcl.

Yes, and like I said, I have already made changes to it. But I don't
think the code I am looking for so I can change it is there. It
doesn't even contain the key words seen in the error messages.

--
Luc
>>

Re: How do I hack Tk error messages?

<undh4a$107pc$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=13109&group=comp.lang.tcl#13109

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: rich@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: How do I hack Tk error messages?
Date: Sun, 7 Jan 2024 06:42:18 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 71
Message-ID: <undh4a$107pc$1@dont-email.me>
References: <20240106204610.43fe78b6@lud1.home> <und802$vadk$1@dont-email.me> <20240107020254.0f93a917@lud1.home>
Injection-Date: Sun, 7 Jan 2024 06:42:18 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="848de04a1cc71e1163f22940425b1b88";
logging-data="1056556"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+jq6s7dUMzkSAfRt57Hoz9"
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Cancel-Lock: sha1:UXqfNrxXyGan6wLc04ipruxRDBw=
 by: Rich - Sun, 7 Jan 2024 06:42 UTC

Luc <luc@sep.invalid> wrote:
> On Sun, 7 Jan 2024 04:06:26 -0000 (UTC), Rich wrote:
>
>>if they were not present would likely leave you with the basic C
>>equivalent of:
>>
>>segmentation fault: process aborted
>>
>>And absolutely no information on where.
>
> Of course, I understand, you do have a point, but you also sound like
> you could have added something like "in the snow uphill both ways."
> :-)

Yeah, I could have added that, and I've been there/done that (6502
assembly on an Atari 800, the feedback for a problem was the system
locking up and having to hit the reset key). Tcl's default is light
years better than that.

>> If you catch your own errors you can have any form of error message
>> you want to code. But you have to catch the errors (via either
>> [catch] or [try]) and then handle the error conditions yourself.
>
> That suggestion calls to my mind the image of a basement with a large
> array of mouse traps strewn all over, one or two going SNAP! every now
> and then.
>
> I don't want to pepper my code with God knows how many catch statements
> in every possible corner. I just want a better error message.

Understood, and for someting you are writing for yourself, yes, letting
the default error handler handle the errors beats adding in all those
catch and try statements. But sometimes there is value in catching
some of them yourself.

>>Not a all. I jump my editor to the first line of the proc mentioned,
>>then I command the editor to do "down arrow" 141 times, and I arrive
>>at the very line that Tcl has referenced. Nothing could be simpler
>>to find.
>>
>>Do note that the above does require one's editor to have the ability
>>to "repeat" an edit operation some number of times. I use joe (Joe's
>>Own Editor, https://en.wikipedia.org/wiki/Joe's_Own_Editor) in the
>>jstar configuration.
>
> Ah. My first thought was, "Vi user detected."

I know just enough VI to be able to edit files in it when it is all I
have available. But I use joe in jstar mode normally.

> I am familiar with joe, but I don't like it. I use geany. I like it
> a lot.

To each his own. Does geany have a "repeat function X times" feature
somewhere? That's all that is needed to find the line Tcl's
referencing from its default message.

>>> Where is it?
>>
>>The default error popup window is provided by the default bgerror
>>handler proc provided by Tcl. On my Slackware system the default
>>bgerror proc is defined in /usr/lib64/tk8.6/bgerror.tcl.
>
> Yes, and like I said, I have already made changes to it. But I don't
> think the code I am looking for so I can change it is there. It
> doesn't even contain the key words seen in the error messages.

The "error message" part of the popup is the Tcl generated stack trace.
It may be generated in the C code that makes up the Tcl interpreter
itself. If so then to change it you would have to recompile your Tcl
interpreter.

Re: How do I hack Tk error messages?

<unh0l1$1ieio$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=13121&group=comp.lang.tcl#13121

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: donald.porter@nist.gov (Don Porter)
Newsgroups: comp.lang.tcl
Subject: Re: How do I hack Tk error messages?
Date: Mon, 8 Jan 2024 09:25:37 -0500
Organization: ACMD ITL NIST
Lines: 15
Message-ID: <unh0l1$1ieio$1@dont-email.me>
References: <20240106204610.43fe78b6@lud1.home>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 8 Jan 2024 14:25:38 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="fb05112b96bc9ce6b1d5b53517b82103";
logging-data="1653336"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX194EVOH01yKZU5MpnAeRD2x1wrWaWXYqjE="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:Va15m7Pg3vgasuu4bh0YcHdrSE4=
In-Reply-To: <20240106204610.43fe78b6@lud1.home>
Content-Language: en-US
 by: Don Porter - Mon, 8 Jan 2024 14:25 UTC

On 1/6/24 18:46, Luc wrote:
> One of the rare things I dislike about Tcl/Tk is the error messages.
> They pop up and I hate them.

Customize background error handling with [interp bgerror].

https://www.tcl-lang.org/man/tcl8.6.13/TclCmd/interp.htm#M55

--
| Don Porter Applied and Computational Mathematics Division |
| donald.porter@nist.gov Information Technology Laboratory |
| http://math.nist.gov/~DPorter/ NIST |
|______________________________________________________________________|

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor