There are cases Emacs wont print stack traces on error
How can I make elisp print a stack trace from my own code? (into the stdout/stderr for example)
Something like Python's traceback:
import traceback
traceback.print_exc()
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.
Sign up to join this communityThere are cases Emacs wont print stack traces on error
How can I make elisp print a stack trace from my own code? (into the stdout/stderr for example)
Something like Python's traceback:
import traceback
traceback.print_exc()
I'm not sure just what you're asking, but does using function backtrace
in your code, at the place where you want to see a backtrace, help? C-h f
says:
backtrace
is a compiled Lisp function insubr.el
.
(backtrace)
Print a trace of Lisp function calls currently active.
Output stream used is value of
standard-output
.
(let ((standard-output 'external-debugging-output)) (backtrace))
– wasamasa
Apr 10 '20 at 7:19
(let ((debug-on-error t))
(error "test"))
With emacs -Q --batch -l tmp/test.el
the following is printed to stderr:
Debugger entered--Lisp error: (error "test")
signal(error ("test"))
error("test")
(let ((debug-on-error t)) (error "test"))
eval-buffer(#<buffer *load*> nil "/home/wasa/tmp/test.el" nil t) ; Reading at buffer position 44
load-with-code-conversion("/home/wasa/tmp/test.el" "/home/wasa/tmp/test.el" nil t)
load("/home/wasa/tmp/test.el" nil t)
command-line-1(("-l" "tmp/test.el"))
command-line()
normal-top-level()
If there's a situation where it doesn't work, chances are errors are inhibited by the code in question.
jit-lock-register
: Error during redisplay: (jit-lock-function 1501) signaled (error "test")
– ideasman42
Apr 9 '20 at 12:22