Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inserting linebreaks to cli_abort error messages #559

Closed
selkamand opened this issue Jan 6, 2023 · 2 comments
Closed

inserting linebreaks to cli_abort error messages #559

selkamand opened this issue Jan 6, 2023 · 2 comments

Comments

@selkamand
Copy link

Thanks for all your work on this incredible package!

I just noticed that single newline (\n) characters are seemingly ignored in cli_abort but double newlines (\n\n) are respected.

  1. Is this expected behaviour?
  2. What is the recommended way to insert a single linebreak into a cli_abort error message?

Reprex (using version cli_3.5.0) :

library(cli)

# single newline character doesn't affect error message
cli_abort("Hello\nWorld")
#> Error:
#> ! Hello World

#> Backtrace:
#>     ▆
#>  1. └─cli::cli_abort("Hello\nWorld")
#>  2.   └─rlang::abort(...)

# two next to each other lead to rendered linebream
cli_abort("Hello\n\nWorld")
#> Error:
#> ! Hello
#> 
#> World

#> Backtrace:
#>     ▆
#>  1. └─cli::cli_abort("Hello\n\nWorld")
#>  2.   └─rlang::abort(...)

Created on 2023-01-06 with reprex v2.0.2

@gaborcsardi
Copy link
Member

In general, you can insert line breaks with \f: https://cli.r-lib.org/reference/inline-markup.html#wrapping

❯ stop(cli::format_error("foo\fbar"))
Error: foo
bar

rlang::abort() seems to strip the \n unfortunately, I am not sure why:

rlang::abort("foo\nbar", use_cli_format=FALSE)
Error:
! foo
bar
Run `rlang::last_error()` to see where the error occurred.rlang::abort("foo\nbar", use_cli_format=TRUE)
Error:
! foo bar
Run `rlang::last_error()` to see where the error occurred.

Somewhat related cli issue: #460.

@gaborcsardi
Copy link
Member

Soon there will be much better ways to nest cli components (e.g. formatted output) into other components (e.g. bullet list).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants