From 4e0be464c4011356b863cf9945dbf52954ca3c35 Mon Sep 17 00:00:00 2001 From: Anna Krystalli Date: Fri, 29 Sep 2023 10:20:51 +0300 Subject: [PATCH] clean try error messages before passing to cli --- R/exec_cfg_check.R | 2 +- R/try_check.R | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/R/exec_cfg_check.R b/R/exec_cfg_check.R index 2db880b7..590ad29d 100644 --- a/R/exec_cfg_check.R +++ b/R/exec_cfg_check.R @@ -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 ) ) diff --git a/R/try_check.R b/R/try_check.R index 165688c3..020c3efb 100644 --- a/R/try_check.R +++ b/R/try_check.R @@ -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) ) ) @@ -30,3 +32,9 @@ get_expr_call_name <- function(expr) { } call_name } + +clean_msg <- function(msg) { + stringr::str_replace_all( + msg, c("\\{" = "[", "\\}" = "]") + ) +}