-
Notifications
You must be signed in to change notification settings - Fork 29
Reinstate handlers during Rprofile sourcing #1201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -129,6 +129,17 @@ globalInterruptHandler <- function(cnd) { | |
| format_traceback(traceback) | ||
| } | ||
|
|
||
| # Sources `file` with ark's global condition handlers re-registered. | ||
| # Intended to be called from a `top_level_exec()` context (which clears the | ||
| # handler stack), so that `globalCallingHandlers()` succeeds. This restores | ||
| # message/error/warning rendering to match interactive behavior during | ||
| # `.Rprofile` sourcing without putting calling-handlers on the stack that | ||
| # would block user `globalCallingHandlers()` calls. | ||
| .ps.errors.source_with_handlers <- function(file) { | ||
| initialize_errors() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'll need a comment in Are we certain that no ill side effect comes from reregistering the global handlers in that top-level context? Does R restore the handler stack to the previous state? (It might very well do that). To make things clearer I think I'd prefer not using
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The function now makes sure to be idempotent so reapplying it shouldn't change a thing. This is also why I think we need to reuse the function rather than split it because we would otherwise be dependent on the order of calling. I'd be fine with renaming |
||
| sys.source(file, envir = globalenv()) | ||
| } | ||
|
|
||
| # If a sink is active (either on output or on messages) messages | ||
| # are always streamed to `stderr`. This follows rlang behaviour | ||
| # and ensures messages can be sinked from stderr consistently. | ||
|
|
@@ -278,10 +289,21 @@ initialize_errors <- function() { | |
| # Unregister all handlers and hold onto them | ||
| handlers <- globalCallingHandlers(NULL) | ||
|
|
||
| existing_ps_handler <- vapply( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ark rather than ps
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
"registered" is clearer to me, and plural makes it clearer this is a vector |
||
| handlers, | ||
| function(h) { | ||
| isTRUE(all.equal(h, .ps.errors.globalErrorHandler)) || | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is preventing usage of
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I honestly don't know, except that it doesn't return
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you get a chance can you please try Maybe the environment is different too, but I can't see why that would be the case from the top of my head. Not that big of a deal but |
||
| isTRUE(all.equal(h, .ps.errors.globalWarningHandler)) || | ||
| isTRUE(all.equal(h, .ps.errors.globalMessageHandler)) || | ||
| isTRUE(all.equal(h, globalInterruptHandler)) | ||
| }, | ||
| logical(1) | ||
| ) | ||
|
|
||
| # Inject our global error handler at the end. | ||
| # This allows other existing error handlers to run ahead of us. | ||
| handlers <- c( | ||
| handlers, | ||
| handlers[!existing_ps_handler], | ||
| list( | ||
| error = .ps.errors.globalErrorHandler, | ||
| warning = .ps.errors.globalWarningHandler, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not exported so shouldn't use
.ps.prefix.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I'm still a bit uncertain about the meaning of the various prefixes. Will clean up