knuffel icon indicating copy to clipboard operation
knuffel copied to clipboard

fix!: prevent double printing of conversion errors

Open TheLostLambda opened this issue 1 year ago • 0 comments

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

TheLostLambda avatar Jan 25 '24 01:01 TheLostLambda