Skip to content

Modernize and improve error handling#279

Open
fischeti wants to merge 6 commits intomasterfrom
fischeti/error-handling
Open

Modernize and improve error handling#279
fischeti wants to merge 6 commits intomasterfrom
fischeti/error-handling

Conversation

@fischeti
Copy link
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 emit_or_error() function has been introduced to support downgrading errors to warnings. The suppressible error is still defined as a Warning e.g. with code W30, but the function will check whether E30 has been suppressed and change the severity/code and return Err. Otherwise, it will emit the warning as usual and return Ok. This cleans up the usage of suppressible errors in the code:

Warnings::FileMissing { ... }.emit_or_error()?

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 5 times, most recently from f3595d4 to abb7778 Compare February 27, 2026 09:32
@fischeti fischeti force-pushed the fischeti/error-handling branch 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
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.

1 participant