r-lib / cli

Tools for making beautiful & useful command line interfaces
https://cli.r-lib.org/
Other
644 stars 70 forks source link

More informative error message with inline markup #687

Open olivroy opened 5 months ago

olivroy commented 5 months ago

It would be great if errors could be rethrown by cli?

If I have this code lost somewhere, it is a bit difficult to find the location.

y <- "{cli}"
cli::format_inline(y)
#> Error in paste0(before, x, after) : 
#>  cannot coerce type 'closure' to vector of type 'character
 cli::format_inline("{.file {x")
#> Error in glue(str, .envir = .envir, .transformer = transformer, .cli = TRUE,  : 
#>  Expecting '}'

It is a bit difficult to know where this error is occuring, especially as these are internal. They should not reach the end user, but while iterating, it can be difficult to find the source of the error.

Maybe cli could check in advance if parenthesis are well balanced?

gaborcsardi commented 3 months ago

Maybe cli could check in advance if parenthesis are well balanced?

That is very difficult, and basically means evaluating the whole thing.

cli calls as.character() and that fails for closures. Maybe we can catch that error, and give a better error message, but what would that error message look like?