Add impl<E: std::error::Error> From<E> for savvy::Error
#324
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.
Third attempt. Close #305
This pull request makes conversion from other error to
savvy::Error
easily, just like anyhow. This is a breaking change, so this bumps the version.Good things
To put simply, such
.map_err()
will no longer be needed.Before
After
Breaking changes
No
From<&str>
conversionOn the other hand,
savvy::Error
losesFrom<String>
andFrom<&str>
. If savvy has these impl, it conflicts with the error conversion. I for got what this error means, but, considering the fact thatanyhow::Error
doesn't haveFrom<String>
as well, this is probably unavoidable.As a workaround, savvy provides
savvy_err!()
macro, which is a shorthand ofsavvy::Error::new(format!(...))
. This follows the idea ofanyhow!()
macro.So, if the current implementation uses
.into()
conversion from a string, it needs to replaced withsavvy_err!()
.Before
After
Conflicts with custom error conversion
impl<E: std::error::Error> From<E> for savvy::Error
will conflict if the R package uses its own error and the conversion tosavvy::Error
. In order to avoid this, this pull request addsuse-custom-error
feature.Minor technical note
anyhow::Error
requiresSend
andSync
(so, the above code ofMutex
doesn't work foranyhow::Error
). If I understand correctly, this is becausestd::error::Error
by accessing vtable directly. So, if the origin is notSend
orSync
,anyhow::Error
is the same.On the other hand, savvy creates a string immediately on conversion. Because only a string can be propagated to R session anyway. A string is
Send
andSync
no matter whether the original error isSend
and/orSync
or not. So, savvy's conversion doesn't requireSend
andSync
.