Skip to content

Commit

Permalink
fix(effects): work around upstream indicatif panic
Browse files Browse the repository at this point in the history
The upstream issue is fixed by console-rs/indicatif#403.
  • Loading branch information
arxanas committed Mar 17, 2022
1 parent 4458efe commit a838fa6
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/core/effects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,17 @@ struct OperationState {
impl OperationState {
pub fn set_progress(&mut self, current: usize, total: usize) {
self.has_meter = true;

if current
.try_into()
.map(|current: u64| current < self.progress_bar.position())
.unwrap_or(false)
{
// Workaround for issue fixed by
// <https://github.com/console-rs/indicatif/pull/403>.
self.progress_bar.reset_eta();
}

self.progress_bar.set_position(current.try_into().unwrap());
self.progress_bar.set_length(total.try_into().unwrap());
}
Expand Down Expand Up @@ -897,4 +908,16 @@ mod tests {

Ok(())
}

/// Test for the issue fixed by <https://github.com/console-rs/indicatif/pull/403>.
#[test]
fn test_effects_progress_rewind_panic() -> eyre::Result<()> {
let effects = Effects::new(Glyphs::text());
let (effects, progress) = effects.start_operation(OperationType::GetMergeBase);
let _ = effects;
progress.notify_progress(3, 10);
// Should not panic.
progress.notify_progress(0, 10);
Ok(())
}
}

0 comments on commit a838fa6

Please sign in to comment.