emacs-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#41918: closed ([PATCH] Propagate error value of auto-loaded command)


From: GNU bug Tracking System
Subject: bug#41918: closed ([PATCH] Propagate error value of auto-loaded command)
Date: Wed, 08 Jul 2020 23:54:03 +0000

Your message dated Wed, 08 Jul 2020 18:53:49 -0500
with message-id <5F065C8D.4080002@gmail.com>
and subject line Re: bug#41918: [PATCH] Propagate error value of auto-loaded 
command
has caused the debbugs.gnu.org bug report #41918,
regarding [PATCH] Propagate error value of auto-loaded command
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs@gnu.org.)


-- 
41918: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=41918
GNU Bug Tracking System
Contact help-debbugs@gnu.org with problems
--- Begin Message --- Subject: [PATCH] Propagate error value of auto-loaded command Date: Wed, 17 Jun 2020 14:34:14 +0200 User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0
Hi,

I think I found a bug in proc unknown in lib/framework.exp.

Patch describing the problem and fixing it attached below.

Thanks,
- Tom

Propagate error value of auto-loaded command

Consider a library file foo.tcl:
...
proc foo { } {
    throw {ARITH DIVZERO {divide by zero}} {divide by zero}
}
...
and a test-case test.tcl:
...
\#!/usr/bin/tclsh

auto_mkindex lib *.tcl

lappend auto_path [pwd]/lib

foo
...
which gives us:
...
divide by zero
    while executing
"throw {ARITH DIVZERO {divide by zero}} {divide by zero}"
    (procedure "foo" line 2)
    invoked from within
"foo"
    (file "./test.tcl" line 7)
...

When overriding the ::unknown command using:
...
rename ::unknown ::tcl_unknown
proc unknown args {
    if {[catch {uplevel 1 ::tcl_unknown $args} msg]} {
        puts "ERROR: proc \"$args\" does not exist: $msg"
        exit
    } else {
        return $msg
    }
}
...
we have instead:
...
$ ./test.tcl
ERROR: proc "foo" does not exist: divide by zero
...

This can be fixed by testing for the specific error code, and otherwise
propagating the error:
...
proc unknown args {
    set code [catch {uplevel 1 ::tcl_unknown $args} msg]
    if { $code == 1 } {
        global errorInfo errorCode
        if { [lindex errorCode 0] eq "TCL"
             && [lindex errorCode 1] eq "LOOKUP"
             && [lindex errorCode 2] eq "COMMAND"
             && [lindex errorCode 3] eq [lindex $args 0] } {
            puts "ERROR: proc \"$args\" does not exist: $msg"
            exit
        }

        return -code error -errorinfo $errorInfo -errorcode $errorCode $msg
    }

    return -code $code $msg
}
...

Fix unknown in lib/framework.exp accordingly.

ChangeLog:

2020-06-17  Tom de Vries  <tdevries@suse.de>

        * lib/framework.exp (unknown): Propagate error value of auto-loaded
        command.

---
 lib/framework.exp | 34 +++++++++++++++++++++-------------
 1 file changed, 21 insertions(+), 13 deletions(-)

diff --git a/lib/framework.exp b/lib/framework.exp
index c9875d2..1347cc1 100644
--- a/lib/framework.exp
+++ b/lib/framework.exp
@@ -258,24 +258,32 @@ proc isnative { } {
 
 rename ::unknown ::tcl_unknown
 proc unknown args {
-    if {[catch {uplevel 1 ::tcl_unknown $args} msg]} {
+    set code [catch {uplevel 1 ::tcl_unknown $args} msg]
+    if { $code  == 1 } {
        global errorCode
        global errorInfo
        global exit_status
-
-       clone_output "ERROR: (DejaGnu) proc \"$args\" does not exist."
-       if {[info exists errorCode]} {
-           send_error "The error code is $errorCode\n"
-       }
-       if {[info exists errorInfo]} {
-           send_error "The info on the error is:\n$errorInfo\n"
+       if { [lindex errorCode 0] eq "TCL"
+            && [lindex errorCode 1] eq "LOOKUP"
+            && [lindex errorCode 2] eq "COMMAND"
+            && [lindex errorCode 3] eq [lindex $args 0] } {
+           clone_output "ERROR: (DejaGnu) proc \"$args\" does not exist."
+           if {[info exists errorCode]} {
+               send_error "The error code is $errorCode\n"
+           }
+           if {[info exists errorInfo]} {
+               send_error "The info on the error is:\n$errorInfo\n"
+           }
+           set exit_status 2
+           log_and_exit
        }
-       set exit_status 2
-       log_and_exit
-    } else {
-       # Propagate return value.
-       return $msg
+
+       # Propagate error
+       return -code error -errorinfo $errorInfo -errorcode $errorCode $msg
     }
+
+    # Propagate return value.
+    return -code $code $msg
 }
 
 # Print output to stdout (or stderr) and to log file

--- End Message ---
--- Begin Message --- Subject: Re: bug#41918: [PATCH] Propagate error value of auto-loaded command Date: Wed, 08 Jul 2020 18:53:49 -0500 User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1.22) Gecko/20090807 MultiZilla/1.8.3.4e SeaMonkey/1.1.17 Mnenhy/0.7.6.0 The fix for this bug was rolled into a larger bugfix branch that has landed on master and will be included in the upcoming 1.6.3 release.

-- Jacob


--- End Message ---

reply via email to

[Prev in Thread] Current Thread [Next in Thread]