Skip to content
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

fix!: prevent double printing of conversion errors #33

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

TheLostLambda
Copy link

Most of this is just the commit description, but here's a picture of the sort of diff this change produces on my end:
image
You can see that I used to get the same error message twice (all errors coming from DecodeError::Conversion have been doubled!), but now the second, duplicate source line is removed.

Okay, then just the commit description:

Fields named source are treated as magical by thiserror and, when using #[derive(Error)] are assumed to contain a sub-error. When a DecodeError::Conversion is then formatted by miette, the conversion error message contained in source is then printed twice: once by the #[error("{}", source)] tag on DecodeError::Conversion, then a second time, implicitly, because miette believes that
DecodeError::Conversion contains an unprinted sub-error.

This change simply renames the source field of
DecodeError::Conversion to error, side-stepping thiserrors special treatment of fields named source.

BREAKING CHANGE: renamed public field source to error

Fields named `source` are treated as magical by `thiserror` and, when
using `#[derive(Error)]` are assumed to contain a sub-error. When a
`DecodeError::Conversion` is then formatted by `miette`, the conversion
error message contained in `source` is then printed twice: once by the
`#[error("{}", source)]` tag on `DecodeError::Conversion`, then a second
time, implicitly, because `miette` believes that
`DecodeError::Conversion` contains an unprinted sub-error.

This change simply renames the `source` field of
`DecodeError::Conversion` to `error`, side-stepping `thiserror`s special
treatment of fields named `source`.

BREAKING CHANGE: renamed public field `source` to `error`
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