Skip to content

Conversation

@rabuu
Copy link
Collaborator

@rabuu rabuu commented Oct 29, 2025

This introduces the AppErrors wrapper type that contains a positive number of AppError and uses that as main error and result type in the driver.

That makes the error handling for multiple and single errors uniform between the different stages (for now only parsing can return multiple errors).

@codecov
Copy link

codecov bot commented Oct 29, 2025

Codecov Report

❌ Patch coverage is 58.82353% with 77 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
lang/lsp/src/diagnostics.rs 0.00% 25 Missing ⚠️
lang/driver/src/database.rs 77.27% 10 Missing ⚠️
lang/driver/src/render_reports.rs 65.51% 10 Missing ⚠️
app/src/cli/xfunc.rs 0.00% 4 Missing ⚠️
test/test-runner/src/phases.rs 86.66% 4 Missing ⚠️
app/src/cli/compile.rs 0.00% 3 Missing ⚠️
app/src/cli/format.rs 0.00% 3 Missing ⚠️
app/src/cli/lift.rs 0.00% 3 Missing ⚠️
app/src/cli/texify.rs 0.00% 3 Missing ⚠️
app/src/cli/clean.rs 0.00% 2 Missing ⚠️
... and 9 more
Files with missing lines Coverage Δ
app/src/cli/check.rs 100.00% <100.00%> (ø)
app/src/cli/mod.rs 58.62% <100.00%> (ø)
app/src/main.rs 100.00% <100.00%> (ø)
lang/driver/src/xfunc.rs 98.90% <100.00%> (-0.04%) ⬇️
app/src/cli/doc.rs 0.00% <0.00%> (ø)
app/src/cli/gen_completions.rs 0.00% <0.00%> (ø)
app/src/cli/lex.rs 0.00% <0.00%> (ø)
app/src/cli/lsp.rs 0.00% <0.00%> (ø)
app/src/cli/run.rs 92.85% <75.00%> (ø)
bench/src/main.rs 0.00% <0.00%> (ø)
... and 13 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@rabuu rabuu changed the title Support muliple errors from any stage in driver Support multiple errors from any stage in driver Oct 29, 2025
pub enum Error {
#[error("Failed parsing")]
Parser(#[related] Vec<polarity_lang_parser::ParseError>),
#[error("One or more errors occured.")]
Copy link
Collaborator

Choose a reason for hiding this comment

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

This information message is a bit redundant. Can you try to make this transparent instead?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ideally, this should also reduce the diff that affects the *.expected files.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This information message is a bit redundant. Can you try to make this transparent instead?

This is not so easy, at least using miette. There is no good way of handling multiple errors in the library, the #[related] is more of a hack but works fine.

If we want to implement Diagnostic/Error for the AppErrors type, we must provide such an error message, it can't be "transparent".

We could also not implement Diagnostic and Error but then we can't transform AppErrors into a single miette::Report anymore and would have to handle Vec<Report>s instead of single Reports in the result of the app/src/cli/... commands. This is not as elegant -- for example, we'd have to manually emit all errors in main and can't just return it as miette::Result -- but probably the "intended" way for multiple errors in miette.

Let me know what you think is better.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see, thanks for the detailed explanation! I think in that case it may be better to replace miette::Result and handle printing the list of errors ourselves. This is slightly more code on our side, but should be manageable.

Copy link
Collaborator

@timsueberkrueb timsueberkrueb left a comment

Choose a reason for hiding this comment

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

Great work! Please address the comments above.

@rabuu rabuu requested a review from timsueberkrueb October 30, 2025 15:07
Copy link
Collaborator

@timsueberkrueb timsueberkrueb left a comment

Choose a reason for hiding this comment

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

Thank you, there are two more things I noticed; happy to merge otherwise!


// There was no panic and `run` returned with an error.
self.report_phases
.push(PhaseReport { name: phase.name(), output: format!("{reports:?}") });
Copy link
Collaborator

Choose a reason for hiding this comment

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

format!("{reports:?}") produces a debug representation of the reports. I think we might want to use render_reports here, as well?

}

fn render_report(report: &miette::Report, colorize: bool) -> String {
fn render_reports(reports: &[miette::Report], colorize: bool) -> String {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does it make sense to move this function to driver and reuse it in app as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Since it is a miette-only thing, wouldn't it make sense to move to miette_util?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I am a bit unhappy about our current miette_util crate: If we publish the project on crates.io then we also have to publish a polarity-miette-util crate, but it barely contains 100 lines of code, and we might not even need that code in the future if we do a rewrite. I think it might be more futureproof to rename the crate to polarity-util and use it as a more general purpose util library with super generic code that we use all over the codebase. An alternative would be to merge it with the printer crate. Wdyt @timsueberkrueb ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would move render_reports to driver for now, we can deal with miette_util separately.

@rabuu rabuu marked this pull request as draft November 3, 2025 14:10
@rabuu rabuu marked this pull request as ready for review November 3, 2025 17:35
use miette::Report;

/// Terminal width for pretty-printing error messages.
const TERMINAL_WIDTH: usize = 200;
Copy link
Collaborator

Choose a reason for hiding this comment

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

In the future we might want to consider getting the terminal width dynamically.

Copy link
Collaborator

@timsueberkrueb timsueberkrueb left a comment

Choose a reason for hiding this comment

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

Thanks a lot!

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.

4 participants