Skip to content

Only print unique diagnostics - #2385

Merged
laurmaedje merged 4 commits into
typst:mainfrom
tingerrr:args-error-reporting
Oct 19, 2023
Merged

laurmaedje merged 4 commits into
typst:mainfrom
tingerrr:args-error-reporting

Conversation

@tingerrr

@tingerrr tingerrr commented Oct 13, 2023 •

Copy link
Copy Markdown
Contributor

The changes in this PR remove duplicates (unique over span and message combination) from source diagnostics to avoid the same diagnostic being printed multiple times, as it would happen for long argument sinks.

The following document would previously print the following diagnostic 8 times, once for each element in the sink, but now only prints it once.

Motivated by #201.

#table(
  columns: 2,
  ..range(0, 8).map(x => 2 * x),
)
error: expected content, found integer
  ┌─ main.typ:3:4
  │
3 │   ..range(0, 8).map(x => 2 * x),
  │     ^^^^^^^^^^^^^^^^^^^^^^^^^^^

Other fields on SourceDiagnostic such as trace and hint were not considered, because these should likely match between diagnostics with the same span and message anyway. But they can be added by simply adding the lengths to the tuple stored in the HashSet.

Comment thread crates/typst-cli/src/compile.rs Resolved
@laurmaedje

Copy link
Copy Markdown
Member

I also think that maybe we should handle this internally so that different consumers don't need to handle it each on their own. Since warnings are already deduplicated, I guess we could this in typst::compile just for the errors.

@tingerrr

Copy link
Copy Markdown
Contributor Author

I also think that maybe we should handle this internally so that different consumers don't need to handle it each on their own. Since warnings are already deduplicated, I guess we could this in typst::compile just for the errors.

Sure! Means we're back to iter -> filter -> collect, but I don't see this as being a big problem considering it's on the error path. We could also convert SourceResult to contain a HashSet with a new type that hashes using only the span message tuple instead, but that seems like it would make the API a bit too complicated for little to no gain.

@laurmaedje

Copy link
Copy Markdown
Member

This needs some adjustment due to #2420 having landed.

@laurmaedje
laurmaedje merged commit 76d4c39 into typst:main Oct 19, 2023
@laurmaedje

Copy link
Copy Markdown
Member

Thank you!

@tingerrr
tingerrr deleted the args-error-reporting branch April 26, 2024 15:00
Dikluwe pushed a commit to Dikluwe/typst-crystalline that referenced this pull request Sep 12, 2026
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.

2 participants