-
Notifications
You must be signed in to change notification settings - Fork 347
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
Error handling improvements #907
Conversation
Change how we handle error types to be more ergonomic: - Replace Cow with String: Diagnostics are serialized into JSON as soon as the function returns, which means that their value is copied right away. The performance improvement of using Cow is minimal in this case, but it has some ergonomic implications because we have to handle their lifetimes. By removing the explicit lifetimes, people can return Diagnostic values with static lifetimes which was not possible before. - Add `IntoDiagnostic` trait. This is a helper trait to facilitate transforming value types into Diagnostic. It gives external crates a better mechanism to transform values into `Diagnostic`. - Add features to implement `IntoDiagnostic` for anyhow, eyre, and miette error types. This helps people that use those creates to transform their errors into `Diagnostic` without double boxing their errors.
I think this is a overall pretty good trade-off.
|
Thanks for the feedback @TethysSvensson
It would be possible, but then we'd break even more people 🙈 I would recommend implementing |
Signed-off-by: David Calavera <[email protected]>
eb97b25
to
0e10bdd
Compare
Actually on re-visiting this, I am not even sure I understand the purpose of the IntoDiagnostic trait at all. It seems to do the exact same thing as Wouldn't it be possible to get rid of IntoDiagnostic instead and instead do feature-gate a |
We can implement `From<T> for Diagnostic` for error crates.
Yeah, you're right. For some reason I thought it was not possible, but it totally is. I made the update and things look much more simple now. |
Hi, thanks for improving this, looks a lot clearer and better to me. Docs helped me as a naive user a lot to understand the point of the breaking change. One thing confuses me still though, the I think, it would make more sense to implement neither. And if the user really wants to use the simpel catchall conversion it is possible to go through |
Signed-off-by: David Calavera <[email protected]>
Thanks for the feedback @tim3z. I agree with you. I've removed the implementation. |
lambda-runtime/Cargo.toml
Outdated
@@ -17,11 +17,16 @@ readme = "../README.md" | |||
default = ["tracing"] | |||
tracing = ["lambda_runtime_api_client/tracing"] | |||
opentelemetry = ["opentelemetry-semantic-conventions"] | |||
anyhow = ["dep:anyhow"] |
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.
Since there is no standard way of documenting features yet (rust-lang/rfcs#3485), shall we add # enables From<T> for Diagnostic for anyhow error types, see ReadMe for more info
here?
Add the same for eyre, and miette or merge into a single comment.
The features are described in the ReadMe, but that's likely to be missed on the first read.
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 idea. I've documented them all since I was there.
Signed-off-by: David Calavera <[email protected]>
📬 Issue #, if available:
Fixes #901
✍️ Description of changes:
Change how we handle error types to be more ergonomic:
Replace Cow with String: Diagnostics are serialized into JSON as soon as the function returns, which means that their value is copied right away. The performance improvement of using Cow is minimal in this case, but it has some ergonomic implications because we have to handle their lifetimes. By removing the explicit lifetimes, people can return Diagnostic values with static lifetimes which was not possible before.
Add features to implement
From<T> for Diagnostic
for anyhow, eyre, and miette error types. This helps people that use those creates to transform their errors intoDiagnostic
without double boxing their errors.🔏 By submitting this pull request
cargo +nightly fmt
.cargo clippy --fix
.