Skip to content

Commit

Permalink
clean try error messages before passing to cli
Browse files Browse the repository at this point in the history
  • Loading branch information
annakrystalli committed Sep 29, 2023
1 parent 02c5a93 commit 4e0be46
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion R/exec_cfg_check.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ exec_cfg_check <- function(check_name, validations_cfg, caller_env, caller_call)
return(
capture_exec_error(
file_path = caller_env_formals$file_path,
msg = attr(res, "condition")$message,
msg = clean_msg(attr(res, "condition")$message),
call = check_name
)
)
Expand Down
10 changes: 9 additions & 1 deletion R/try_check.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
try_check <- function(expr, file_path) {
check <- try(expr, silent = TRUE)
if (inherits(check, "try-error")) {
msg <- clean_msg(attr(check, "condition")$message)

return(
capture_exec_error(
file_path = file_path,
msg = attr(check, "condition")$message,
msg = msg,
call = get_expr_call_name(expr)
)
)
Expand All @@ -30,3 +32,9 @@ get_expr_call_name <- function(expr) {
}
call_name
}

clean_msg <- function(msg) {
stringr::str_replace_all(
msg, c("\\{" = "[", "\\}" = "]")
)
}

0 comments on commit 4e0be46

Please sign in to comment.