Skip to content

fix: route warnings through MultiProgress::suspend() to prevent truncation#18638

Open
majiayu000 wants to merge 2 commits intoastral-sh:mainfrom
majiayu000:fix/issue-18626-warning-truncation
Open

fix: route warnings through MultiProgress::suspend() to prevent truncation#18638
majiayu000 wants to merge 2 commits intoastral-sh:mainfrom
majiayu000:fix/issue-18626-warning-truncation

Conversation

@majiayu000
Copy link
Copy Markdown
Contributor

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-warnings that routes warning output through MultiProgress::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: Add set_printer() / clear_printer() / print_warning() functions with a global PRINTER callback. Both warn_user! and warn_user_once! macros now route through print_warning() instead of calling anstream::eprintln! directly. Uses try_lock() to avoid deadlocking if a callback transitively triggers another warning.
  • crates/uv/src/commands/reporters.rs: When a ProgressReporter creates a visible MultiProgress, register a printer callback that uses mp.suspend(|| anstream::eprintln!(...)). Clear the callback on drop.

No new dependencies added — the callback approach avoids coupling uv-warnings to indicatif.

Test Plan

  • Added unit tests for set_printer, clear_printer, and print_warning fallthrough behavior
  • cargo test -p uv-warnings — all pass
  • cargo clippy -p uv-warnings -p uv — clean

…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>
@majiayu000 majiayu000 marked this pull request as ready for review March 22, 2026 05:45
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.

Warnings produced by uv sync are truncated at certain terminal widths

1 participant