all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@gmail.com>
To: 57195@debbugs.gnu.org
Subject: bug#57195: 28.1.90; Can error backtrace be preserved upon intercepting with `condition-case'?
Date: Sun, 14 Aug 2022 11:49:04 +0800	[thread overview]
Message-ID: <87edxj1o3z.fsf@localhost> (raw)

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





             reply	other threads:[~2022-08-14  3:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-14  3:49 Ihor Radchenko [this message]
2022-08-15  7:18 ` bug#57195: 28.1.90; Can error backtrace be preserved upon intercepting with `condition-case'? Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87edxj1o3z.fsf@localhost \
    --to=yantar92@gmail.com \
    --cc=57195@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.