R/process_error_msg.R
process_error_msg.Rd
The tra
list indicates which (partial) error message should be replaced
by a more elaborate version, using the cli::cli_abort()
syntax.
process_error_msg(msg, tra, fixed = TRUE)
The original error message.
The translation list, where the names are the partial error and the content is the new error message(s).
Should a fixed or a regular expression comparison be done
between the names of tra
and the msg
? Defaults to TRUE
, which is
faster. In case you need different behavior for different items, you can
also supply a logical vector of the same length as tra
.
The replaced error message.
dir <- "/temp/dir"
file <- "~/some file.txt"
tra = list(
"Directory not found" = c("The directory {.path {dir}} does not exist.",
i = "Please create it first."),
"file does not exist" = c("The file {.file {file}} does not exist.",
i = "Check the path and try again.")
)
msg <- "The file does not exist"
try(cli::cli_abort(process_error_msg(msg, tra)))
#> Error in eval(expr, envir) :
#> The file ~/some file.txt does not exist.
#> ℹ Check the path and try again.
msg <- "Directory not found on this machine"
try(cli::cli_abort(process_error_msg(msg, tra)))
#> Error in eval(expr, envir) :
#> The directory /temp/dir does not exist.
#> ℹ Please create it first.