GNU bug report logs - #57195
28.1.90; Can error backtrace be preserved upon intercepting with `condition-case'?

Previous Next

Package: emacs;

Reported by: Ihor Radchenko <yantar92 <at> gmail.com>

Date: Sun, 14 Aug 2022 03:49:01 UTC

Severity: normal

Found in version 28.1.90

To reply to this bug, email your comments to 57195 AT debbugs.gnu.org.

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

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


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#57195; Package emacs. (Sun, 14 Aug 2022 03:49:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Ihor Radchenko <yantar92 <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sun, 14 Aug 2022 03:49:02 GMT) Full text and rfc822 format available.

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

From: Ihor Radchenko <yantar92 <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 28.1.90; Can error backtrace be preserved upon intercepting with
 `condition-case'?
Date: Sun, 14 Aug 2022 11:49:04 +0800
Consider the following functions:

(defun my/err ()
  (let ((x 0))
    (/ 2 x)))

(defun my/interc ()
  (condition-case err
      (my/err)
    (arith-error
     (backtrace-revert)
     (error "`my/err' signalled an error. Check out Troubleshooting section of the manual. (%S)" err))))

`my/interc' function calls `my/err', but wants to provide a more useful
error message. This can obviously be done using `condition-case'.

However, when one tries to run M-: (my/interc), the following backtrace
will appear:

Debugger entered--Lisp error: (error "My custom error: (arith-error)")
  (error "My custom error: %S" (arith-error))
  (condition-case err (my/err) (arith-error (error "My custom error: %S" err)))
  (my/interc)
  (eval-expression (my/interc) nil nil 127)
  (funcall-interactively eval-expression (my/interc) nil nil 127)
  (command-execute eval-expression)

This backtrace is limiting the information up to the `condition-case'
form itself. The deeper levels are not available.

Compare it with the result of M-: (my/err)

Debugger entered--Lisp error: (arith-error)
  (/ 2 0)
  (let ((x 0)) (/ 2 x))
  (my/err)
  (eval-expression (my/err) nil nil 127)
  (funcall-interactively eval-expression (my/err) nil nil 127)
  (command-execute eval-expression)

This backtrace is much more detailed and gives the exact place where the
error happens.

Unfortunately, the second case does not allow to make the error message
more helpful.

Is it possible to display the original backtrace in the intercepted
condition-case?

-- 
Ihor Radchenko,
Org mode contributor,
Learn more about Org mode at https://orgmode.org/.
Support Org development at https://liberapay.com/org-mode,
or support my work at https://liberapay.com/yantar92




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#57195; Package emacs. (Mon, 15 Aug 2022 07:19:01 GMT) Full text and rfc822 format available.

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

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Ihor Radchenko <yantar92 <at> gmail.com>
Cc: 57195 <at> debbugs.gnu.org
Subject: Re: bug#57195: 28.1.90; Can error backtrace be preserved upon
 intercepting with `condition-case'?
Date: Mon, 15 Aug 2022 09:18:37 +0200
Ihor Radchenko <yantar92 <at> gmail.com> writes:

> Is it possible to display the original backtrace in the intercepted
> condition-case?

I don't think that's possible, so that's why condition-case-unless-debug
exists.





This bug report was last modified 2 years and 307 days ago.

Previous Next


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