You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I did a quick search through the code from #923 using ripgrep to get a sense of how many times we manually map one error type to another, and this is what I found:
# Not a perfect search, but gives a good rough idea> rg "map_err\(Error::" --stats
...
122 matches
122 matched lines
36 files contained matches
...
Correct me if I'm wrong @soareschen, but if we had an impl From<SourceErrorType> for Error for each kind of error we want to map, we could simply just use ? to return and we could cut out the extra map_err step, right? I did this for some of the code in the tendermint-p2p crate for errors that should be mapped from std::io::Error and it seemed to work quite well.
If so, I'd recommend we go ahead and replace all the map_err calls with ? and implement infallible conversions from their respective error types to each crate's respective Error type.
This would, of course, only work for errors where we don't need additional parameters beyond just the source error.
What's the definition of "done" for this issue?
When all the .map_err calls throughout the codebase (wherever possible) for concrete source error types are replaced with automatic conversions (?).
The text was updated successfully, but these errors were encountered:
Sounds reasonable. This should be possible with newer versions of flex-error, since it now defines the error type in the crate that uses it. It may be tricky to generate the instances from the macros, as there can be multiple sub-errors that have the same error sources. So I think it would be better that we derive the From instances manually.
Follow-up on #923.
I did a quick search through the code from #923 using
ripgrep
to get a sense of how many times we manually map one error type to another, and this is what I found:Correct me if I'm wrong @soareschen, but if we had an
impl From<SourceErrorType> for Error
for each kind of error we want to map, we could simply just use?
to return and we could cut out the extramap_err
step, right? I did this for some of the code in thetendermint-p2p
crate for errors that should be mapped fromstd::io::Error
and it seemed to work quite well.If so, I'd recommend we go ahead and replace all the
map_err
calls with?
and implement infallible conversions from their respective error types to each crate's respectiveError
type.This would, of course, only work for errors where we don't need additional parameters beyond just the source error.
What's the definition of "done" for this issue?
When all the
.map_err
calls throughout the codebase (wherever possible) for concrete source error types are replaced with automatic conversions (?
).The text was updated successfully, but these errors were encountered: