Skip to content

Clamp progress bar fill when current is outside 0..total - #844

Merged
gaborcsardi merged 1 commit into
r-lib:mainfrom
taekop:fix/progress-negative-set
Oct 5, 2026
Merged

gaborcsardi merged 1 commit into
r-lib:mainfrom
taekop:fix/progress-negative-set

Conversation

@taekop

@taekop taekop commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Setting a progress bar to a value below zero or above total fails when the bar is drawn, and the error then also surfaces from a deferred on.exit():

options(cli.progress_show_after = 0)
f <- function(x) {
  cli::cli_progress_bar("Test", total = 10)
  cli::cli_progress_update(set = x)
  cli::cli_progress_done()
}
f(-1)
#> Error in `rep()`: invalid 'times' argument
f(11)
#> same error

make_progress_bar() passes width * percent and width - complete_len to rep(), which is negative for percent < 0 or percent > 1. The fill is now clamped to the range 0..1. Values inside that range render exactly as before, and pb_percent still shows the real value (e.g. 110%).

Closes #580

@gaborcsardi

Copy link
Copy Markdown
Member

Thanks!

@gaborcsardi
gaborcsardi merged commit 2972e2e into r-lib:main Oct 5, 2026
11 checks passed
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

Successfully merging this pull request may close these issues.

Bad error from progress bar

2 participants