-
Notifications
You must be signed in to change notification settings - Fork 177
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
Rust SDK: remove anyhow
, use thiserror
w/ structured error types
#2169
Conversation
Based on the lints failure, it seems we need to get #2111 merged, then get this updated to latest master. |
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.
I'd really prefer to combine all the flavors of disconnection errors, but I'm going to approve.
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.
Our use of `anyhow` in the Rust SDK was originally due to my being lazy. I figured I'd kick the can on writing actual error types as long as possible, and it turns out now's the time that's no longer possible, because while working on a follow-up I needed to `clone` an error, and `anyhow::Error: !Clone`. This commit removes the Rust SDK's use of `anyhow`, replacing it with a `thiserror`-annotated `enum Error`. This resulted in essentially simple mechanical changes to a lot of the SDK code, and also to the codegen, resulting in a truly enormous diff.
Per out-of-band suggestion from @jsdt, rework the `Error` type so that many former variants are now under `Error::Internal(InternalError)`, with `InternalError` not exposing its contents except via `std::error::Error`.
ceb0586
to
bb7fd06
Compare
Test failure is unrelated and is fixed by #2199 . |
Description of Changes
Our use of
anyhow
in the Rust SDK was originally due to my being lazy. I figured I'd kick the can on writing actual error types as long as possible, and it turns out now's the time that's no longer possible, because while working on another ticket I needed toclone
an error, andanyhow::Error: !Clone
.This commit removes the Rust SDK's use of
anyhow
, replacing it with athiserror
-annotatedenum Error
.This resulted in essentially simple mechanical changes to a lot of the SDK code, and also to the codegen, resulting in a truly enormous diff.
Advice for reviewers
Start in
crates/sdk/src/error.rs
and see if the error enum makes sense. Then look through the rest of the SDKsrc
to verify that I'm constructing them sensibly. Then checkcrates/cli/src/subcommands/generate/rust.rs
. Do not at any point look at the generated code insidecrates/sdk/tests
, as it will be uninteresting and verbose.API and ABI breaking changes
Yep! The errors returned from the SDK functions are now of a different type.
Expected complexity level and risk
1: large volume of mechanical changes. It was essentially impossible to depend on the actual nature of the emitted errors before, as
anyhow
isn't really useful for that, so we're effectively adding strictly more information in a way that should not break any existing client code.Testing