Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Internal error with `ansi_strwrap`when string contains `\r\n\r` in `cli_abort()` message

Closed
#667 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
r
Domain
cli

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

bug tidy-dev-day :nerd_face:

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from r-lib/cli

All issues in r-lib/cli

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.