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.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 76787 in the body.
You can then email your comments to 76787 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to monnier <at> iro.umontreal.ca, bug-gnu-emacs <at> gnu.org:
bug#76787; Package emacs. (Thu, 06 Mar 2025 17:24:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Stefan Monnier <monnier <at> iro.umontreal.ca>:
New bug report received and forwarded. Copy sent to monnier <at> iro.umontreal.ca, bug-gnu-emacs <at> gnu.org. (Thu, 06 Mar 2025 17:24:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

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





Reply sent to Stefan Monnier <monnier <at> iro.umontreal.ca>:
You have taken responsibility. (Thu, 06 Mar 2025 20:27:01 GMT) Full text and rfc822 format available.

Notification sent to Stefan Monnier <monnier <at> iro.umontreal.ca>:
bug acknowledged by developer. (Thu, 06 Mar 2025 20:27:02 GMT) Full text and rfc822 format available.

Message #10 received at 76787-done <at> debbugs.gnu.org (full text, mbox):

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)))))






bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 04 Apr 2025 11:24:17 GMT) Full text and rfc822 format available.

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.