-
-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Relationship between Diagnostic and StdError #164
Comments
tl;dr: miette, as it is, is mostly a set of reporters for errors + a macro to make it easy to define extra things. In the long run, most of what you're talking about will be made moot, and there will be no |
Ah great! So you'd expose some |
yep. But that's quite a ways off. So |
Since this is nothing that can be solved now, I'll close the issue. |
Do you know if the current state of the Provider API (I think error-stack uses it now?) sufficient to achieve this now, or are there more capabilities needed? |
I believe the Provider API was basically abandoned, unfortunately |
Ah, I see that when
|
I would like to understand where miette currently tries to position itself in the 'Rust error story'. To do this, I'm opening this issue to see what I might have missed and/or not understood correctly.
Miette exposes a
Diagnostic
trait that extends on top of theError
trait with additional information so as to report better looking and more informative errors.To do so, it currently imposes the following relationship
Diagnostic: StdError
(StdError
is a supertrait ofDiagnostic
). This means that anyDiagnostic
is also anStdError
.StdError
has multiple advantages that speak for it:.source/cause
method that gives access to the error that 'cause'd itDiagnostic
builds on top of this with the ability to specify spans with labels, severity, etc... .This gives it several nice things that seperate it from
StdError
:.source
method ofStdError
on can get access to the underlying errors and print those too, potentially going as far as to the root error that caused it.This means that for a given
Diagnostic
and finallyReport
one can have the following relationship:Important to note is that while the Top-level Diagnostic/Report has multiple 'Diagnostics' below it, they are currently only 'related'. (For example multiple logically distinct errors in a configuration file).
It is also not possible to 'chain' Diagnostics, as there is no
.source
equivalent forDiagnostic
. This means that either a single diagnostic is created at the root (potentially wrapping a StdError) and then transported all the way to the base or that extra information is added later on. (Through for example thewith_source_code
transforms). An error, once made into aDiagnostic
cannot be re-integrated into the chain of errors except as a logically distinct 'related' issue.To me, this disconnect feels weird (and is mostly due to Rust constraints from its current state). I was expecting that I could effectively represent a 'tree' of
Diagnostics
with the following relationship:Where any
StdError
could be converted to aDiagnostic
to be used as part of the tree of errors an application may expose but thatDiagnostic
does not require the supertraitError
anymore.This brings its own problems with it though, as now libraries that expose a
Diagnostic
has no direct compatibility tostd::error::Error
.From what I understand, this is currently heavily geared towards maximum compatibility with the
StdError
ecosystem but at the same timeReport
does not implementStdError
anyway.This leaves me wondering, why does Diagnostic require
Error
as a supertrait? If one wants to keep compatibility withStdError
then one can just implement it (withthiserror
or manually). IfDiagnostic
simply has aDisplay
bound, then they are even compatible together (sincethiserror
implements Display for you too).NB: English is not my first language, and I hope I didn't miss my tone here: I am trying to understand how Miette came to be and where it would like to be in the future?
This is maybe related to #139?
I am using
StdError
to disambiguate on "Error"The text was updated successfully, but these errors were encountered: