Internal error with `ansi_strwrap`when string contains `\r\n\r` in `cli_abort()` message
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 42/100
Research direction
Start by reproducing the minimal cli::cli_abort() example in an R console and tracing cli::ansi_strwrap(), which is identified in the backtrace as the failing entry point. Compare it with the longer knitr/txtProgressBar stderr example; done means messages containing these carriage-return and newline sequences no longer produce an internal error.
Written by the indexing model from the issue text.
Description
Running in RStudio R console this leads to an internal error
> cli::cli_abort("processing file: report.qmd\r\n\r |")
Error:
! ! Internal error in `cli::ansi_strwrap()`
Run `rlang::last_trace()` to see where the error occurred.
> rlang::last_trace()
<error/rlang_error>
Error:
! ! Internal error in `cli::ansi_strwrap()`
---
Backtrace:
▆
1. └─cli::cli_abort("processing file: report.qmd\r\n\r |")
2. └─rlang::abort(...)
3. └─rlang:::signal_abort(cnd, .file)
4. └─rlang::cnd_message(cnd, inherit = TRUE, prefix = TRUE)
5. └─rlang:::cnd_message_format_prefixed(cnd, ..., parent = FALSE)
6. └─rlang:::cnd_message_format(cnd, ..., alert = alert)
7. └─rlang (local) cli_format(glue_escape(lines))
8. └─rlang:::.rlang_cli_format(x, cli::format_error)
9. └─cli::cli_format(x, .envir = emptyenv())
10. └─cli::cli_fmt(...)
11. └─cli:::cli__fmt(rec, collapse, strip_newline)
12. ├─base::do.call(app[[msg$type]], msg$args)
13. └─cli (local) `<fn>`(text = `<named list>`, id = "cli-8944-50", class = NULL)
14. └─cli:::clii_bullets(app, text, id, class)
15. └─base::lapply(...)
16. └─cli (local) FUN(X[[i]], ...)
17. └─app$text(text[[i]])
18. └─cli:::clii_text(app, text)
19. └─app$xtext(text)
20. └─cli:::clii__xtext(...)
21. └─cli::ansi_strwrap(text, exdent = exdent, width = app$get_width(extra = padding))
22. └─throw(cli_error("Internal error in {.fun cli::ansi_strwrap}"))
The message string is part of the content created by knitr progress bar which uses txtProgressBar.
I encountered this in the context of quarto R package, where quarto render is run with processx::run() and I wanted to use cli_abort() in the error catch
https://github.com/quarto-dev/quarto-r/blob/8a0bcb3a7cf35ce4eb2b412d6d09542cc7b2b35d/R/quarto.R#L41-L48
The full stderr I get in the code above is the following, which leads to same error
msg <- "processing file: report.qmd\r\n\r | \r | | 0%\r | \r |................. | 33% \r | \r |................................... | 67% [unnamed-chunk-1]\r\n\n\nQuitting from lines 8-9 [unnamed-chunk-1] (report.qmd)\r\nError:\r\n! true message\r\n\r \r\nExécution arrêtée\r\n"
> cli::cli_abort(msg)
Error:
! ! Internal error in `cli::ansi_strwrap()`
Run `rlang::last_trace()` to see where the error occurred.
- Dominant language
- R
- Stars
- 730
- Forks
- 94
- Avg merge
- 3d 10h
- Merged PRs (30d)
- 2
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from r-lib/cli
-
Difficulty 1/5 Under an hour Newbie friendliness 68/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
Difficulty 4/5 3-5 days Newbie friendliness 42/100
-
feature
Difficulty 3/5 1-2 days Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 48/100
Similar issues
-
Component: R Type: bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
apache/arrow#51695 · 1 comment ·
Maintainers usually reply within 1 day
-
bug priority: should
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
The-Strategy-Unit/nhp_outputs#477 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
InseeFrLab/melodi#27 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Open-Systems-Pharmacology/OSPSuite.ReportingEngine#1380 · 1 comment ·