GNU bug report logs - #76787
31.0.50; Double backtrace in batch mode

Previous Next

Package: emacs;

Reported by: Stefan Monnier <monnier <at> iro.umontreal.ca>

Date: Thu, 6 Mar 2025 17:24:02 UTC

Severity: normal

Found in version 31.0.50

Done: Stefan Monnier <monnier <at> iro.umontreal.ca>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: tracker <at> debbugs.gnu.org
Subject: bug#76787: closed (31.0.50; Double backtrace in batch mode)
Date: Thu, 06 Mar 2025 20:27:01 +0000
[Message part 1 (text/plain, inline)]
Your message dated Thu, 06 Mar 2025 15:26:40 -0500
with message-id <jwvfrjpx5yn.fsf-monnier+emacs <at> gnu.org>
and subject line Re: bug#76787: 31.0.50; Double backtrace in batch mode
has caused the debbugs.gnu.org bug report #76787,
regarding 31.0.50; Double backtrace in batch mode
to be marked as done.

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


-- 
76787: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=76787
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: bug-gnu-emacs <at> gnu.org
Subject: 31.0.50; Double backtrace in batch mode
Date: Thu, 06 Mar 2025 12:23:15 -0500
Package: Emacs
Version: 31.0.50


Emacs in batch mode sometimes shows twice the same backtrace:

    % /usr/bin/emacs -Q --batch --eval '(setq debug-on-error t)' --eval '(error "foo")'                            
    
    Error: error ("foo")
      error("foo")
      eval((error "foo") t)
      command-line-1(("--eval" "(setq debug-on-error t)" "--eval" "(error \"foo\")"))
      command-line()
      normal-top-level()
    
    Debugger entered--Lisp error: (error "foo")
      error("foo")
      eval((error "foo") t)
      command-line-1(("--eval" "(setq debug-on-error t)" "--eval" "(error \"foo\")"))
      command-line()
      normal-top-level()
    
    %

I think I'm in part to blame for this one.  It seems that one of them
comes from the "normal" debugger and the other from
`debug-early--handler`.


        Stefan



[Message part 3 (message/rfc822, inline)]
From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: 76787-done <at> debbugs.gnu.org
Subject: Re: bug#76787: 31.0.50; Double backtrace in batch mode
Date: Thu, 06 Mar 2025 15:26:40 -0500
> I think I'm in part to blame for this one.  It seems that one of them
> comes from the "normal" debugger and the other from
> `debug-early--handler`.

Rather than try and figure out how to coordinate the two places so they
don't both call a debugger, I generalized the
`debugger--last-error` mechanism with the patch below.


        Stefan


diff --git a/lisp/emacs-lisp/debug-early.el b/lisp/emacs-lisp/debug-early.el
index 48b71e7f9f0..e63edb19328 100644
--- a/lisp/emacs-lisp/debug-early.el
+++ b/lisp/emacs-lisp/debug-early.el
@@ -36,6 +36,8 @@
 ;; For bootstrap reasons, we cannot use any macros here since they're
 ;; not defined yet.
 
+(defvar debugger--last-error nil)
+
 (defalias 'debug-early-backtrace
   #'(lambda (&optional base)
       "Print a trace of Lisp function calls currently active.
@@ -76,15 +78,19 @@ 'debug-early-backtrace
 	                      (setq args (cdr args)))
 	               (princ " ")))
 	         (princ ")\n"))))
-	 base))))
+	 base))
+      (message "debug-early-backtrace...done")))
 
 (defalias 'debug--early
   #'(lambda (error base)
-  (princ "\nError: ")
-  (prin1 (car error))	; The error symbol.
-  (princ " ")
-  (prin1 (cdr error))	; The error data.
-  (debug-early-backtrace base)))
+      (if (eq error debugger--last-error) nil
+        (setq debugger--last-error nil)
+        (princ "\nError: ")
+        (prin1 (car error))             ; The error symbol.
+        (princ " ")
+        (prin1 (cdr error))             ; The error data.
+        (prog1 (debug-early-backtrace base)
+          (setq debugger--last-error error)))))
 
 (defalias 'debug-early                  ;Called from C.
   #'(lambda (&rest args)
diff --git a/lisp/emacs-lisp/debug.el b/lisp/emacs-lisp/debug.el
index f8af6eafa32..c1aaa1ac623 100644
--- a/lisp/emacs-lisp/debug.el
+++ b/lisp/emacs-lisp/debug.el
@@ -153,8 +153,6 @@ debugger--restore-buffer-state
     (insert (debugger--buffer-state-content state)))
   (goto-char (debugger--buffer-state-pos state)))
 
-(defvar debugger--last-error nil)
-
 (defun debugger--duplicate-p (args)
   (pcase args
     (`(error ,err . ,_) (and (consp err) (eq err debugger--last-error)))))




This bug report was last modified 133 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.