Skip to content

Add per-error informational diagnostics - #2040

Draft
zanieb wants to merge 6 commits into
mainfrom
zb/rich-diagnostic-info-20260922
Draft

zanieb wants to merge 6 commits into
mainfrom
zb/rich-diagnostic-info-20260922

Conversation

@zanieb

@zanieb zanieb commented Sep 22, 2026

Copy link
Copy Markdown
Member

TOML failures place the parser's complete multiline display inside a cause, including a redundant heading and source gutter. Add typed presentation data so the shared renderer can show the specific parser message, a source location, and a numbered excerpt when a valid span is available. Retain the original parser errors and inputs, and use the same presentation for recoverable warnings. The API also supports inline info: statements and guttered detail blocks without changing source chains, hints, or exit statuses.

Corresponds to astral-sh#21604.

@astral-automations-bot astral-automations-bot Bot added area:error-messages Messaging when something goes wrong enhancement New feature or request labels Sep 22, 2026
@zanieb
zanieb force-pushed the zb/rich-diagnostic-info-20260922 branch from de73bc8 to 3d1befa Compare September 22, 2026 20:26
@codspeed

codspeed Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 11.6%

⚠️ 8 benchmarks spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

⚡ 1 improved benchmark
✅ 68 untouched benchmarks
⏩ 35 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚡ ⚠️ Simulation discover_workspace_from_all_members 151.5 ms 135.8 ms +11.6%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing zb/rich-diagnostic-info-20260922 (33b8574) with main (64e2ac8)

Open in CodSpeed

Footnotes

  1. 35 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@zanieb
zanieb added this pull request to stack #2044 September 22, 2026 21:13
@zaniebot zaniebot added risk:2 Low, contained risk of minor incorrect behavior with straightforward recovery. priority:3 Normal: useful features, documentation, usability, or routine efficiency improvements. size:3 Substantial: interacting behaviors, difficult compatibility questions, or a careful migration. priority:2 Important: bounded correctness, release reliability, committed work, or proven performance gains. and removed priority:3 Normal: useful features, documentation, usability, or routine efficiency improvements. labels Sep 23, 2026
@astral-automations-bot
astral-automations-bot Bot force-pushed the zb/rich-diagnostic-info-20260922 branch 3 times, most recently from 52e2404 to 6009f11 Compare October 7, 2026 18:37
@zaniebot zaniebot added the build:skip-release Disable building release binaries for a pull request label Oct 7, 2026
@astral-automations-bot
astral-automations-bot Bot force-pushed the zb/rich-diagnostic-info-20260922 branch from 6009f11 to bc37bfc Compare October 7, 2026 21:39
Comment thread crates/uv-errors/src/diagnostic.rs Outdated
Comment on lines +33 to +38
/// Attach additional context to this error.
#[cfg(test)]
#[must_use]
pub(super) fn with_info(mut self, info: Info<'a>) -> Self {
self.info.push(info);
self

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Defer informational rendering until it has a production consumer

with_info and the Info constructors are private and test-only, so production diagnostics always have an empty info vector. Nevertheless, the shared renderer carries the field and implements wrapping, detail blocks, and rendering calls for it. Defer this unused machinery and its synthetic tests until a concrete error needs informational context; the TOML snippet implementation can remain independently reviewable.

Comment thread crates/uv-tool-commands/src/install.rs Outdated
Comment on lines +62 to +66
fn diagnostic_for_error<'a>(error: &'a (dyn StdError + 'static)) -> Option<Diagnostic<'a>> {
uv_settings::diagnostic_for_error(error)
.or_else(|| uv_workspace::pyproject::diagnostic_for_error(error))
.or_else(|| uv_pypi_types::diagnostic_for_error(error))
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Share the standard TOML diagnostic dispatcher

This dispatcher duplicates the same three providers, in the same order, in uv-lock-operations/src/lock.rs and uv/src/commands/diagnostics.rs. Maintaining supported TOML diagnostics now requires coordinated edits across fatal-error rendering and two recoverable-warning paths. Extract these identical dispatchers into one shared command-level helper, leaving the warning-specific message adapters local, so presentation changes apply consistently.

@astral-automations-bot
astral-automations-bot Bot force-pushed the zb/rich-diagnostic-info-20260922 branch from bc37bfc to e41456b Compare October 8, 2026 14:31
@astral-automations-bot
astral-automations-bot Bot force-pushed the zb/rich-diagnostic-info-20260922 branch from e41456b to bb1dbd1 Compare October 8, 2026 17:33
Comment thread crates/uv-settings/Cargo.toml Outdated
Comment on lines +49 to +50
textwrap = { workspace = true }
serde-untagged = { workspace = true }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Remove the unused settings dependencies

serde-untagged has no consumer in uv-settings, and the warning refactor removes the crate’s last textwrap use. Both declarations are now unused dependencies, which the repository checks with cargo-shear --deny-warnings. Remove both manifest entries and their corresponding uv-settings lockfile dependency entries.

Comment on lines +12 to +14
pub struct ParseError<E> {
error: E,
document: Option<SourceFile>,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Require the source snapshot in ParseError

Every production construction in PyProjectToml::from_string and PyProjectToml::from_toml supplies a SourceFile. The source-less conversion only supports an otherwise unused From<toml::de::Error> implementation and a synthetic test. Making the document optional adds fallback branches to both diagnostic providers and lets future ? conversions silently omit source excerpts. Store SourceFile directly and remove the unused conversions; missing or invalid parser spans can still retain their existing display fallback independently.

Comment on lines +167 to +168
let document =
SourceFile::new(path.as_ref().user_display().to_string(), raw.clone());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Borrow the TOML text when constructing the source snapshot

On a workspace TOML parse failure, raw.clone() copies the entire document before SourceFile::new copies that temporary into an Arc<str>. The fallback parse only borrows raw, and the other parser adapters already pass borrowed text to this constructor. Pass raw.as_str() here to retain the same owned snapshot without the redundant full-document allocation.

@astral-automations-bot
astral-automations-bot Bot force-pushed the zb/rich-diagnostic-info-20260922 branch from f4c4680 to 33b8574 Compare October 16, 2026 16:54
@astral-automations-bot
astral-automations-bot Bot force-pushed the zb/rich-diagnostic-info-20260922 branch from 33b8574 to 7597f6b Compare October 20, 2026 19:56
@astral-automations-bot
astral-automations-bot Bot force-pushed the zb/rich-diagnostic-info-20260922 branch from 7597f6b to c56214a Compare October 23, 2026 20:11

This branch was successfully deployed

1 active (outdated) deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:error-messages Messaging when something goes wrong build:skip-release Disable building release binaries for a pull request enhancement New feature or request priority:2 Important: bounded correctness, release reliability, committed work, or proven performance gains. risk:2 Low, contained risk of minor incorrect behavior with straightforward recovery. size:3 Substantial: interacting behaviors, difficult compatibility questions, or a careful migration.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants