Skip to content
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

Merged
merged 5 commits into from
Feb 5, 2025

Conversation

gefjon
Copy link
Contributor

@gefjon gefjon commented Jan 24, 2025

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 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.

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 SDK src to verify that I'm constructing them sensibly. Then check crates/cli/src/subcommands/generate/rust.rs. Do not at any point look at the generated code inside crates/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

  • I believe our existing automated tests are sufficient.

@gefjon gefjon added the api-break A PR that makes an API breaking change label Jan 24, 2025
@gefjon gefjon requested a review from jsdt January 24, 2025 16:24
@gefjon gefjon requested a review from Centril as a code owner January 24, 2025 16:24
@gefjon
Copy link
Contributor Author

gefjon commented Jan 24, 2025

Based on the lints failure, it seems we need to get #2111 merged, then get this updated to latest master.

Copy link
Contributor

@jsdt jsdt left a 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.

Copy link
Contributor

@Centril Centril left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bfops bfops added release-any To be landed in any release window release-1.0 and removed release-1.0 labels Jan 28, 2025
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`.
@gefjon
Copy link
Contributor Author

gefjon commented Feb 3, 2025

Test failure is unrelated and is fixed by #2199 .

@gefjon gefjon added this pull request to the merge queue Feb 5, 2025
Merged via the queue into master with commit 3a126bc Feb 5, 2025
12 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-break A PR that makes an API breaking change release-any To be landed in any release window
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants