Skip to content

Commit

Permalink
rethrow message on pal creation failure (closes #62)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpcouch committed Nov 21, 2024
1 parent 83bcccb commit 4734dc8
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions R/rstudioapi.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ retrieve_pal <- function(role) {
} else {
tryCatch(
pal <- .init_pal(role),
error = function(e) {
rstudioapi::showDialog("Error", "Unable to create a pal. See `?.init_pal()`.")
error = function(cnd) {
# rethrow condition message directly rather than setting
# `cli::cli_abort(parent)` so that rstudioapi::showDialog is able
# to handle the formatting (#62)
stop(condition_message(cnd), call. = FALSE)
return(NULL)
}
)
Expand All @@ -74,6 +77,14 @@ retrieve_pal <- function(role) {
pal
}

condition_message <- function(cnd) {
if ("message" %in% names(cnd)) {
return(cnd$message)
}

cnd_message(cnd, inherit = FALSE, prefix = FALSE)
}

get_primary_selection <- function(context) {
selection <- rstudioapi::primary_selection(context)

Expand Down

0 comments on commit 4734dc8

Please sign in to comment.