Skip to content

Modernize and improve error handling#279

Merged
micprog merged 10 commits intomasterfrom
fischeti/error-handling
Apr 9, 2026
Merged

Modernize and improve error handling#279
micprog merged 10 commits intomasterfrom
fischeti/error-handling

Conversation

@fischeti
Copy link
Copy Markdown
Contributor

@fischeti fischeti commented Feb 23, 2026

The previous error implementation is outdated: both cause and description have been deprecated since a while in the standard library. This PR modernizes the error type and handling

Adopting miette error type

The new global error type is now miette::Report, which has the following benefits:

  • Error output follows the same style as warnings, and also reuses the same code since both warnings and errors are Diagnostics.
  • Error messages can now contain help messages as well
  • miette::Report has neat macros like bail!, ensure! and miette! (inspired by anyhow)
  • The previous chaining is replaced with wrap_err (resp. wrap_err_with for lazy evaluation), which additionally has the advantage that the source is retained with the standard source() which allows to traverse the whole chain of errors and print it out.

Suppressible errors

An additional downgrade_if_suppressed() function has been introduced to support downgrading errors to warnings. The suppressible errors are duplicated in an Errors enum with corresponding variants in Warnings. Then, the call site of the error can simply do:

Errors::FileMissing { ... }.downgrade_if_suppressed()?

Restructuring

Additionally error.rs has been removed entirely, and the rest (e.g. stageln! and other macros) moved to the diagnostic.rs, where they also belong imo.

@fischeti fischeti force-pushed the fischeti/error-handling branch 6 times, most recently from f9fa419 to af269e3 Compare February 27, 2026 13:56
@fischeti fischeti marked this pull request as ready for review February 27, 2026 14:25
@fischeti fischeti force-pushed the fischeti/error-handling branch from af269e3 to fc383f5 Compare April 2, 2026 14:54
@fischeti fischeti force-pushed the fischeti/error-handling branch from fc383f5 to 9cd009e Compare April 2, 2026 15:03
Copy link
Copy Markdown
Member

@micprog micprog left a comment

Choose a reason for hiding this comment

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

Love the upgrade, there look to be some nice usability and styling improvements! I have some questions about some of the implementation, see comments.

Comment thread src/cmd/clean.rs
Comment thread src/cmd/fusesoc.rs Outdated
Comment thread src/cmd/pickle.rs Outdated
Comment thread src/cmd/script.rs
Comment thread src/cli.rs Outdated
Comment thread src/config.rs Outdated
Comment thread src/config.rs
Comment thread src/config.rs Outdated
Comment thread src/config.rs Outdated
Comment thread src/config.rs
@fischeti
Copy link
Copy Markdown
Contributor Author

fischeti commented Apr 7, 2026

Thanks a lot for the thorough review! I fixed all your suggestions where possible, see comments.

@fischeti fischeti force-pushed the fischeti/error-handling branch from f0bdec7 to 4fecc74 Compare April 7, 2026 13:46
Copy link
Copy Markdown
Member

@micprog micprog left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@micprog micprog merged commit 0a98f9e into master Apr 9, 2026
18 checks passed
@micprog micprog deleted the fischeti/error-handling branch April 9, 2026 12:49
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