Skip to content

Add support for breaking on exceptions and pausing R at any time#1036

Open
lionel- wants to merge 9 commits intomainfrom
feature/exception-breakpoints-pause
Open

Add support for breaking on exceptions and pausing R at any time#1036
lionel- wants to merge 9 commits intomainfrom
feature/exception-breakpoints-pause

Conversation

@lionel-
Copy link
Contributor

@lionel- lionel- commented Feb 10, 2026

Branched from #1033 (for test infra)
Addresses posit-dev/positron#11797
Addresses posit-dev/positron#11799

Adds support for the DAP feature of exception breakpoints, and for pausing the debugger at any time. Both features rely on:

  • Calling browser() from a global handler for the relevant condition (error, warning, or interrupt)

  • Skipping the top-level frame which points to our global handlers.

    When these handlers trigger, the R stack includes the handler frame at the top. Since this frame is not useful to users, we track why we entered the debugger via DebugStoppedReason (Condition for errors/warnings, Pause for interrupts) and discard the top frame in start_debug() for these cases.

    Note that the console will still evaluate in this frame until we fix IDE alternative to options(error = recover) positron#9156 (comment).

    Also note that for errors and warnings, we'd ideally automatically skip the part of the call stack involved in emitting/handling the condition (partly the base emitting context with withRestart() etc, and partly the package-level emitting context, e.g. based on rlang's error_call = parent.frame() pattern).

The condition breakpoints are surfaced like this in the UI:

Screenshot 2026-02-10 at 15 19 59

We could add messages as well but I thought that'd crowd the UI, and it doesn't feel as useful to easily break on those. Could be added as a user setting in the future.

Pausing can be done by calling the existing VS Code command "Pause":

Screenshot 2026-02-10 at 15 03 39

QA Notes

This is comprehensively tested on the backend side.

Exception breakpoints (break on error/warning):

  • In the Debug Console's breakpoint picker, enable "Uncaught Errors" or "Warnings".

  • Run code that triggers an error (e.g. stop("oops")) or warning (e.g. warning("hmm")). The debugger should pause at the point of the condition.

  • The call stack should show user code (for errors or warnings thrown from C) or stop()/warning(), not R's internal condition handling frames (.handleSimpleError, doWithOneRestart, etc.).

  • The exception type and message should appear in the editor and the debug UI (e.g. "simpleError: oops").

  • Continue (c) should resume execution and propagate the error/warning normally.

Pause:

  • While R is executing a long-running operation (e.g. Sys.sleep(100), an infinite loop, or I/O), run the Debug: Pause command from the command palette. R should interrupt and drop into the debugger at the current execution point.

  • The call stack should reflect where R was interrupted.

  • Q should exit the debugger. c / Continue should resume running code. Note that with curl downloads or I/O there are known issues.

@lionel- lionel- force-pushed the task/dap-protocol-tests-sync-update branch 2 times, most recently from 4611c2c to dbb841c Compare February 12, 2026 18:19
Base automatically changed from task/dap-protocol-tests-sync-update to main February 12, 2026 18:20
@lionel- lionel- force-pushed the feature/exception-breakpoints-pause branch from afd3936 to 7f71cca Compare February 13, 2026 08:28
@lionel- lionel- force-pushed the feature/exception-breakpoints-pause branch from 1811c21 to fb0490c Compare February 13, 2026 10:21
@lionel-
Copy link
Contributor Author

lionel- commented Feb 13, 2026

I've added some filtering of condition handling/emitting frames, like .handleSimpleError, .signalSimpleWarning, doWithOneRestart, etc

@lionel- lionel- requested a review from DavisVaughan February 13, 2026 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IDE alternative to options(error = recover)

1 participant