Closed ubearline closed 2 years ago
@sigmaSd / @chris-laplante any suggestions for what might be wrong here?
thread 'main' panicked at 'attempt to subtract with overflow', C:\Users\Dami\.cargo\registry\src\mirrors.sjtug.sjtu.edu.cn-7a04d2510079875b\indicatif-0.17.0-rc.2\src\draw_target.rs:402:44
That's this code:
399 // Keep the cursor on the right terminal side
400 // So that next user writes/prints will happen on the next line
401 let line_width = console::measure_text_width(line);
402 term.write_str(&" ".repeat(usize::from(term.size().1) - line_width))?;
I guess it's definitely possible that the line is longer than the console is wide, so we should account for that somehow?
@ubearline thanks for testing!
Can you add dbg!(term.width(),line_width)
before the panic
Different code, same crash: https://gist.github.com/konstin/1e7450131fb59c216256ec1367f394b5
Can you add the debug calls from the comment before yours?
Also the crash happens also only with git bash ?
Also the crash happens also only with git bash ?
Initially I used a bash on linux in pycharm, but now it failed in the terminal but happened again when stepping through my code in the debugger. The bug seems really flaky in general
Can you add the debug calls from the comment before yours?
Here you go:
[indicatif/src/draw_target.rs:457] term.width() = 80
[indicatif/src/draw_target.rs:457] line_width = 40
aiohttp
Installing ░░░░░░░░░░░░░░░░░░░░ 0/112 [indicatif/src/draw_target.rs:457] term.width() = 80
[indicatif/src/draw_target.rs:457] line_width = 51
Installing ░░░░░░░░░░░░░░░░░░░░ 0/112 ["aiohttp"] [indicatif/src/draw_target.rs:457] term.width() = 80
[indicatif/src/draw_target.rs:457] line_width = 51
aiosignal
Installing ░░░░░░░░░░░░░░░░░░░░ 0/112 ["aiohttp"] [indicatif/src/draw_target.rs:457] term.width() = 80
[indicatif/src/draw_target.rs:457] line_width = 64
Installing ░░░░░░░░░░░░░░░░░░░░ 0/112 ["aiohttp", "aiosignal"] [indicatif/src/draw_target.rs:457] term.width() = 80
[indicatif/src/draw_target.rs:457] line_width = 64
asgiref
Installing ░░░░░░░░░░░░░░░░░░░░ 0/112 ["aiohttp", "aiosignal"] [indicatif/src/draw_target.rs:457] term.width() = 80
[indicatif/src/draw_target.rs:457] line_width = 75
Installing ░░░░░░░░░░░░░░░░░░░░ 0/112 ["aiohttp", "aiosignal", "asgiref"] [indicatif/src/draw_target.rs:457] term.width() = 80
[indicatif/src/draw_target.rs:457] line_width = 75
async_timeout
Installing ░░░░░░░░░░░░░░░░░░░░ 0/112 ["aiohttp", "aiosignal", "asgiref"] [indicatif/src/draw_target.rs:457] term.width() = 80
[indicatif/src/draw_target.rs:457] line_width = 92
thread 'main' panicked at 'attempt to subtract with overflow', indicatif/src/draw_target.rs:458:44
stack backtrace:
0: rust_begin_unwind
at /rustc/02072b482a8b5357f7fb5e5637444ae30e423c40/library/std/src/panicking.rs:498:5
1: core::panicking::panic_fmt
at /rustc/02072b482a8b5357f7fb5e5637444ae30e423c40/library/core/src/panicking.rs:107:14
2: core::panicking::panic
at /rustc/02072b482a8b5357f7fb5e5637444ae30e423c40/library/core/src/panicking.rs:48:5
3: indicatif::draw_target::ProgressDrawState::draw_to_term
at ./indicatif/src/draw_target.rs:458:44
4: indicatif::draw_target::Drawable::draw
at ./indicatif/src/draw_target.rs:296:18
5: indicatif::state::BarState::draw
at ./indicatif/src/state.rs:127:9
6: indicatif::state::BarState::update_and_draw
at ./indicatif/src/state.rs:90:13
7: indicatif::progress_bar::ProgressBar::update_and_draw
at ./indicatif/src/progress_bar.rs:554:9
8: indicatif::progress_bar::ProgressBar::set_message
at ./indicatif/src/progress_bar.rs:318:9
9: cli::main
at ./src/main.rs:130:9
10: core::ops::function::FnOnce::call_once
at /rustc/02072b482a8b5357f7fb5e5637444ae30e423c40/library/core/src/ops/function.rs:227:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
Installing ░░░░░░░░░░░░░░░░░░░░ 0/112 ["aiohttp", "aiosignal", "asgiref", "async_timeout"]
Process finished with exit code 101
So I'm guessing it started installing a fourth package or a package with a longer name, after which the line width exceeded the terminal width, which we currently don't handle well?
Its reproducible by just using a very long template, should be an easy fix for the panic itself
But I was curious though what indicatif does in these cases where the line width > terminal width, turns out indicatif just doesn't handle this case, and the line will wrap and became spammed.
What about if line > terminal.width() we replace the extra characters with "..."
What about if line > terminal.width() we replace the extra characters with "..."
I like this idea. I think it would be pretty complicated to track progress bars that take up multiple lines.
Seems reasonable!
That was quick, thank you!
demo
win10 powershell normal
win10 cmd normal
win10 git-bush panic (It was working in the last version 0.17.0-beta.1)
panic log