loading...

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)

Arguments

msg

The original error message.

tra

The translation list, where the names are the partial error and the content is the new error message(s).

fixed

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.

Value

The replaced error message.

Examples

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.