diff options
author | Florian Müllner <fmuellner@gnome.org> | 2021-08-11 00:17:49 +0200 |
---|---|---|
committer | Florian Müllner <fmuellner@gnome.org> | 2021-08-13 07:53:19 +0200 |
commit | 86a6d3fa42beaee5cc353f8049ee9cc473934db5 (patch) | |
tree | c0efee1c95b18c65da5c4484cbe84baa87fe7c78 /modules/script | |
parent | 6ca7779479dbf261a1b2ddcb4012dc42281fd292 (diff) | |
download | gjs-86a6d3fa42beaee5cc353f8049ee9cc473934db5.tar.gz |
debugger: Add option to ignore caught exceptions
Right now execution stops whenever an exception is thrown,
regardless of whether the exception was handled or not.
This gets annoying fast when exceptions are expected, for
example when handling EEXISTS after attempted file operations
instead of doing (racy) existence checks.
Address this by ignoring handled exceptions by default, with
the option to restore the old behavior.
https://gitlab.gnome.org/GNOME/gjs/-/issues/431
Diffstat (limited to 'modules/script')
-rw-r--r-- | modules/script/_bootstrap/debugger.js | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/modules/script/_bootstrap/debugger.js b/modules/script/_bootstrap/debugger.js index 8bb2f8f8..6b5020fe 100644 --- a/modules/script/_bootstrap/debugger.js +++ b/modules/script/_bootstrap/debugger.js @@ -21,7 +21,7 @@ var topFrame = null; var debuggeeValues = {}; var nextDebuggeeValueIndex = 1; var lastExc = null; -var options = {pretty: true, colors: true}; +var options = {pretty: true, colors: true, ignoreCaughtExceptions: true}; var breakpoints = [undefined]; // Breakpoint numbers start at 1 // Cleanup functions to run when we next re-enter the repl. @@ -308,6 +308,7 @@ PARAMETERS · option: option name. Allowed options are: · pretty: set print mode to pretty or brief. Allowed value true or false · colors: set printing with colors to true or false. + · ignoreCaughtExceptions: do not stop on handled exceptions. Allowed value true or false · value: option value`; function splitPrintOptions(s, style) { @@ -930,6 +931,18 @@ dbg.onDebuggerStatement = function (frame) { }); }; dbg.onExceptionUnwind = function (frame, value) { + const willBeCaught = currentFrame => { + while (currentFrame) { + if (currentFrame.script.isInCatchScope(currentFrame.offset)) + return true; + currentFrame = currentFrame.older; + } + return false; + }; + + if (options.ignoreCaughtExceptions && willBeCaught(frame)) + return undefined; + return saveExcursion(() => { topFrame = focusedFrame = frame; print("Unwinding due to exception. (Type 'c' to continue unwinding.)"); |