-
Notifications
You must be signed in to change notification settings - Fork 348
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
Relax blanket implementation of Diagnostic #897
Conversation
2a580ed
to
169ae14
Compare
lambda-runtime/src/diagnostic.rs
Outdated
/// `Diagnostic` is automatically derived for types that implement | ||
/// [`Display`][std::fmt::Display]; e.g., [`Error`][std::error::Error]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: with these changes I think it's too broad to say that Diagnostic
is derived for types that implement Display
. Perhaps instead "...for some common types such as std::error::Error"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good call. I've updated the doc.
150b3d4
to
cdca2ae
Compare
Instead of implementing Diagnostic for everything that implements Display, implement the trait only for a few well known types. This gives people more flexibility to implement Diagnostic. Signed-off-by: David Calavera <david.calavera@gmail.com>
cdca2ae
to
df35c5d
Compare
@calavera is this ready for review? |
@bnusunny yes. I've tested it manually with a bunch of the examples in the repo and it work fine. I've also tested it with some apps without any issue. |
This is quite an intrusive change, as it means you can no longer use e.g. anyhow or eyre in your handlers, at least without doing additional boxing. Would you be open to doing |
Also, the requirement For instance you will not be able to specify |
For anyone else having a hard time upgrading to v0.12 because of this PR, here is my work-around: struct DiagnosticWrapper(Diagnostic<'static>);
impl<'a> From<DiagnosticWrapper> for Diagnostic<'a> {
fn from(value: DiagnosticWrapper) -> Self {
value.0
}
}
impl std::fmt::Debug for DiagnosticWrapper {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
}
}
impl DiagnosticWrapper {
fn new<E>(err: E) -> Self
where
E: Display,
{
DiagnosticWrapper(Diagnostic {
error_type: Cow::Borrowed(std::any::type_name::<E>()),
error_message: Cow::Owned(err.to_string()),
})
}
} I then use |
I don't think adding dependencies ourselves for those crates makes sense either. I don't know what they return, but I'm guessing the implement the standard Error trait. If that's the case, it should not be necessary to do any conversion. Feel free to test it and send improvements. |
Issue #, if available:
Fixes #880
Description of changes:
Instead of implementing Diagnostic for everything that implements Display, implement the trait only for a few well known types. This gives people more flexibility to implement Diagnostic.
By submitting this pull request