diff options
| author | Philipp Stephani | 2020-11-29 14:24:57 +0100 |
|---|---|---|
| committer | Philipp Stephani | 2020-12-06 17:47:52 +0100 |
| commit | 40e11743ca3803bdc2c6c612f35ab695efb3eb8b (patch) | |
| tree | 85d9362c7e46106a3212716dff5f2cfd30ffdaba /src | |
| parent | 87a9fc6dcd8e364c9ae27da27fee439dc41c2e25 (diff) | |
| download | emacs-40e11743ca3803bdc2c6c612f35ab695efb3eb8b.tar.gz emacs-40e11743ca3803bdc2c6c612f35ab695efb3eb8b.zip | |
Print a backtrace on unhandled errors in batch mode (Bug#44942).
* src/eval.c (signal_or_quit): Print a backtrace in batch mode if no
error handler was found.
* test/src/eval-tests.el (eval-tests/backtrace-in-batch-mode)
(eval-tests/backtrace-in-batch-mode/demoted-errors): New unit tests.
* etc/NEWS: Document change.
Diffstat (limited to 'src')
| -rw-r--r-- | src/eval.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/eval.c b/src/eval.c index d9a424b57a9..18df484aac0 100644 --- a/src/eval.c +++ b/src/eval.c | |||
| @@ -1709,6 +1709,7 @@ signal_or_quit (Lisp_Object error_symbol, Lisp_Object data, bool keyboard_quit) | |||
| 1709 | break; | 1709 | break; |
| 1710 | } | 1710 | } |
| 1711 | 1711 | ||
| 1712 | bool debugger_called = false; | ||
| 1712 | if (/* Don't run the debugger for a memory-full error. | 1713 | if (/* Don't run the debugger for a memory-full error. |
| 1713 | (There is no room in memory to do that!) */ | 1714 | (There is no room in memory to do that!) */ |
| 1714 | !NILP (error_symbol) | 1715 | !NILP (error_symbol) |
| @@ -1722,7 +1723,7 @@ signal_or_quit (Lisp_Object error_symbol, Lisp_Object data, bool keyboard_quit) | |||
| 1722 | if requested". */ | 1723 | if requested". */ |
| 1723 | || EQ (h->tag_or_ch, Qerror))) | 1724 | || EQ (h->tag_or_ch, Qerror))) |
| 1724 | { | 1725 | { |
| 1725 | bool debugger_called | 1726 | debugger_called |
| 1726 | = maybe_call_debugger (conditions, error_symbol, data); | 1727 | = maybe_call_debugger (conditions, error_symbol, data); |
| 1727 | /* We can't return values to code which signaled an error, but we | 1728 | /* We can't return values to code which signaled an error, but we |
| 1728 | can continue code which has signaled a quit. */ | 1729 | can continue code which has signaled a quit. */ |
| @@ -1730,6 +1731,18 @@ signal_or_quit (Lisp_Object error_symbol, Lisp_Object data, bool keyboard_quit) | |||
| 1730 | return Qnil; | 1731 | return Qnil; |
| 1731 | } | 1732 | } |
| 1732 | 1733 | ||
| 1734 | /* If we're in batch mode, print a backtrace unconditionally to help with | ||
| 1735 | debugging. Make sure to use `debug' unconditionally to not interfere with | ||
| 1736 | ERT or other packages that install custom debuggers. */ | ||
| 1737 | if (!debugger_called && !NILP (error_symbol) | ||
| 1738 | && (NILP (clause) || EQ (h->tag_or_ch, Qerror)) && noninteractive) | ||
| 1739 | { | ||
| 1740 | ptrdiff_t count = SPECPDL_INDEX (); | ||
| 1741 | specbind (Vdebugger, Qdebug); | ||
| 1742 | call_debugger (list2 (Qerror, Fcons (error_symbol, data))); | ||
| 1743 | unbind_to (count, Qnil); | ||
| 1744 | } | ||
| 1745 | |||
| 1733 | if (!NILP (clause)) | 1746 | if (!NILP (clause)) |
| 1734 | { | 1747 | { |
| 1735 | Lisp_Object unwind_data | 1748 | Lisp_Object unwind_data |