serde: serialize dyn Error
Value
s using collect_str
#89
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently,
valuable-serde
handlesValue::Error
variants incorrectly.When
valuable-serde
encounters aValue::Error
, it returns the errorimmediately as a serialization error:
valuable/valuable-serde/src/lib.rs
Line 267 in 1fc2ad5
This is not correct. If a
serde
serializer returns an error, thismeans something has gone wrong while serializing a value. Returning an
error makes the serialization fail. However, this is not what
valuable
'sValue::Error
means.Value::Error
represents that we arerecording a value which happens to be an
Error
, not that somethingwent wrong while recording the value. This means that
valuable-serde
will currently return an
Error
(indicating that serialization failed)any time it attempts to record an
Error
value, and serialization willfail.
This commit changes
valuable-serde
to record the error using itsDisplay
implementation, usingserde
'scollect_str
method. Now,Error
s will be serialized by recording their messages as a string,rather than causing the serialization to fail.
Using
collect_str
allows the serializer to write the displayrepresentation to its own internal buffer, rather than having to format
the error to a temporary
String
beforehand.Fixes #88