-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Propagate errors from check_installed() #4845
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
Changes from all commits
996a59c
cb894a9
56778bf
3115900
4d59326
bc7e725
8d7d97b
b016039
2948069
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 |
---|---|---|
|
@@ -97,10 +97,18 @@ Stat <- ggproto("Stat", | |
args <- c(list(data = quote(data), scales = quote(scales)), params) | ||
dapply(data, "PANEL", function(data) { | ||
scales <- layout$get_scales(data$PANEL[1]) | ||
try_fetch(do.call(self$compute_panel, args), error = function(cnd) { | ||
cli::cli_warn("Computation failed in {.fn {snake_class(self)}}", parent = cnd) | ||
new_data_frame() | ||
}) | ||
try_fetch(do.call(self$compute_panel, args), | ||
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. Unless I'm missing something, I think this should be more like: try_fetch(do.call(self$compute_panel, args),
rlib_error_package_not_found = function(cnd) {
cli::cli_abort("Aborted computation in {.fn {snake_class(self)}}", parent = cnd)
},
error = function(cnd) {
cli::cli_warn("Computation failed in {.fn {snake_class(self)}}", parent = cnd)
new_data_frame()
}
) 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 thought so at first, but the rethrown error gets caught in the ignore_all_but_custom_error <- function(expr) {
result <- rlang::try_fetch(
expr,
custom_error = function(cnd) {
rlang::inform("custom_error detected")
rlang::abort("rethrowing the error", parent = cnd)
},
error = function(cnd) {
rlang::inform("ignoring the error")
},
)
invisible(result)
}
# works as expected
ignore_all_but_custom_error(stop("foo"))
#> ignoring the error
# hmm...
ignore_all_but_custom_error(rlang::abort("foo", class = "custom_error"))
#> custom_error detected
#> ignoring the error Created on 2022-05-20 by the reprex package (v2.0.1) 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. Hmmm, I suspect this is because of the way that 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. Now I'm wondering if There are two steps currently:
The second step is 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. But doesn't the same problem arise with any classed condition? i.e. you can't use 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 think we have to keep the error class as errors, otherwise they wouldn't get caught by a generic Isn't the whole point of the design of 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 was wondering whether check-installed really follows the error model or instead is more like an interrupt.
Originally I restarted to Also note that currently We can fix the restart signal protocol but then we still need to think about what UI do we want to implement:
Regarding (1), I think we should prompt the user in interactive sessions, since that is the documented purpose of Regarding (2), I think the interrupt model makes the most sense to me. I'd be a bit surprised to select "No" and then see the computation continue. 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. Ok, that makes sense — that way the initial call is an interrupt and it only becomes an error if you select "No". I'm not too concerned with your I agree that selecting "No" should take you to the top level, as otherwise in the code below you'd need to select "No" 10 times in order to exit the f <- function(i) {
# make a plot that uses hexbin
check_installed("hexbin")
}
purrr::map(1:10, safely(f)) 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.
hmm but then we agree that Just making sure because you also say:
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. Great point regarding repeated prompts in loops by the way. This clearly shows why |
||
error = function(cnd) { | ||
# if the error comes from check_installed(), propagate it immediately. | ||
if (inherits(cnd, "rlib_error_package_not_found")) { | ||
cli::cli_abort("Aborted computation in {.fn {snake_class(self)}}", parent = cnd) | ||
} | ||
|
||
# for other errors, ignore them with warnings | ||
cli::cli_warn("Computation failed in {.fn {snake_class(self)}}", parent = cnd) | ||
new_data_frame() | ||
} | ||
) | ||
}) | ||
}, | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
Unless I'm missing something, I think this should be more like:
Uh oh!
There was an error while loading. Please reload this page.
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.
Also note that the
in {.fn {snake_class(self)}}
is temporary until we replace it with a propercall
. Not sure if we want to do that now or later.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.
Also note that the
in {.fn {snake_class(self)}}
is temporary unless we replace it with a propercall
. Not sure if we want to do that now or later.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 looks not bad to me, but let me think. I'm a noob at cli...
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 think I'd structure the errors in this way, just to avoid multiple formulations of the same idea (an error occurred):
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 couldn't figure out how to structure like this. Can we add the additional "Caused by" like without providing the error message (the line starting with
!
)?