fix: route warnings through MultiProgress::suspend() to prevent truncation#18638
Open
majiayu000 wants to merge 2 commits intoastral-sh:mainfrom
Open
fix: route warnings through MultiProgress::suspend() to prevent truncation#18638majiayu000 wants to merge 2 commits intoastral-sh:mainfrom
majiayu000 wants to merge 2 commits intoastral-sh:mainfrom
Conversation
…ation When indicatif progress bars are active on stderr, warnings emitted via anstream::eprintln! can be truncated because indicatif's line management overwrites content written outside its control. Add a global printer callback to uv-warnings that, when set, routes warning output through the callback instead of writing directly to stderr. In reporters.rs, set this callback to use MultiProgress::suspend() which pauses progress bar rendering while the warning is printed. Fixes astral-sh#18626 Signed-off-by: majiayu000 <1835304752@qq.com>
Use try_lock() instead of lock() in print_warning() so re-entrant calls from within a printer callback fall through to direct stderr output instead of deadlocking. Add unit tests for the printer callback mechanism (set_printer, clear_printer, print_warning fallthrough). Document the single-printer limitation on set_printer. Signed-off-by: majiayu000 <1835304752@qq.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #18626
Summary
When indicatif progress bars are active during operations like
uv sync, warning messages get truncated at certain terminal widths (e.g. 105-106 columns). This happens because indicatif's line management interferes with stderr output — it tracks terminal line positions and can clip lines that are written directly to stderr while progress bars are being drawn.This PR adds a global printer callback mechanism to
uv-warningsthat routes warning output throughMultiProgress::suspend()when progress bars are active.suspend()temporarily pauses indicatif's draw loop, letting the warning print cleanly to stderr without line management interference, then resumes drawing.Changes:
crates/uv-warnings/src/lib.rs: Addset_printer()/clear_printer()/print_warning()functions with a globalPRINTERcallback. Bothwarn_user!andwarn_user_once!macros now route throughprint_warning()instead of callinganstream::eprintln!directly. Usestry_lock()to avoid deadlocking if a callback transitively triggers another warning.crates/uv/src/commands/reporters.rs: When aProgressReportercreates a visibleMultiProgress, register a printer callback that usesmp.suspend(|| anstream::eprintln!(...)). Clear the callback on drop.No new dependencies added — the callback approach avoids coupling
uv-warningsto indicatif.Test Plan
set_printer,clear_printer, andprint_warningfallthrough behaviorcargo test -p uv-warnings— all passcargo clippy -p uv-warnings -p uv— clean