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

[Misc]: Improve error handling by adding contexts #3806

Merged
merged 24 commits into from
Apr 24, 2024

Conversation

satoshiotomakan
Copy link
Collaborator

Description

Currently, it's complicated to debug errors WalletCore returns, especially if the error is related to incorrect SigningInput parameters, as the error codes are too abstract, eg SigningError::Error_invalid_params, SigningError::Error_invalid_address and other.

In this PR, we introduce error contexts - an extension of the error messages that will help to find out which request parameter leads to the error.

Example:

A provided address (e.g. destination address) is invalid
Context:
0. Neither the private key nor the sender address is specified.

How to test

Run Rust, C++ tests

Types of changes

Checklist

  • Create pull request as draft initially, unless its complete.
  • Add tests to cover changes as needed.
  • Update documentation as needed.
  • If there is a related Issue, mention it in the description.

If you're adding a new blockchain

  • I have read the guidelines for adding a new blockchain.

Copy link
Contributor

@lamafab lamafab left a comment

Choose a reason for hiding this comment

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

I checked tw_coin_entry::error and it looks good imo. The intended usage of this seems to be for debugging purposes via the Display trait (ie. format_context), I assume?

@satoshiotomakan
Copy link
Collaborator Author

Hi @lamafab, exactly.
I think some of the conversions seem complicated. For example, From<KeyPairError> is implemented for TWError<SigningErrorType>, not for SigningErrorType as it suppose to be because the errors are declared in different crates (not in tw_coin_entry).
So we could actually implement From<KeyPairError> for SigningErrorType in tw_proto, but then tw_proto should depend on tw_key_pair

@satoshiotomakan satoshiotomakan marked this pull request as ready for review April 22, 2024 10:47
Copy link

github-actions bot commented Apr 22, 2024

Binary size comparison

➡️ aarch64-apple-ios:

- 11.50 MB
+ 11.72 MB 	 +232 KB

➡️ aarch64-apple-ios-sim:

- 11.50 MB
+ 11.72 MB 	 +232 KB

➡️ aarch64-linux-android:

- 14.84 MB
+ 15.22 MB 	 +383 KB

➡️ armv7-linux-androideabi:

- 12.48 MB
+ 12.71 MB 	 +239 KB

➡️ wasm32-unknown-emscripten:

- 10.25 MB
+ 10.55 MB 	 +307 KB

Milerius
Milerius previously approved these changes Apr 24, 2024
@satoshiotomakan satoshiotomakan marked this pull request as draft April 24, 2024 09:46
@satoshiotomakan satoshiotomakan marked this pull request as ready for review April 24, 2024 14:45
@satoshiotomakan satoshiotomakan merged commit 406abe4 into master Apr 24, 2024
13 checks passed
@satoshiotomakan satoshiotomakan deleted the s/rust-tw-error branch April 24, 2024 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants