-
Notifications
You must be signed in to change notification settings - Fork 19
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
contract: return error rather than panic whenever possible #690
Conversation
957a030
to
0c8f97d
Compare
@ppca @ChaoticTempest @volovyks Sorry for jumping in, but I'd like to invite you to participate in the Race of Sloths - a fun and gamified open-source contributions program. Consider mentioning @race-of-sloths user in your github comment or PR description to join! See how the flow works here: near/nearcore#11778 |
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.
Changes to the contract looks good overall, I didn't know about handle_result
which will turn result into a failed action
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.
Looks cool!
chain-signatures/contract/src/lib.rs
Outdated
#[error("This sign request was removed from pending requests: timed out or completed.")] | ||
RequestNotInPending, | ||
#[error("Signature could not be verified.")] | ||
SignatureNotVerified, |
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.
Can we please separate errors by function or scope where they can appear?
The end goal here is to give users a finite number of errors that can happen for each call they are making.
In this case, we have Timeout
, which the user can get from sign()
and SignatureNotVerified
, which can only happen in respond
.
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.
sounds good. Will do.
@@ -130,11 +187,14 @@ impl MpcContract { | |||
} | |||
} | |||
|
|||
fn remove_request(&mut self, request: SignatureRequest) { | |||
fn remove_request(&mut self, request: SignatureRequest) -> Result<(), MpcContractError> { |
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.
Is it possible to add a similar return Error type for sign()
? This is the main function and it is a shame that it does not have strongly typed errors.
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.
no I tried, it doesn't work. It will return () instead of the actual yield/resume result. Let me ask Saketh if it's possible figured out a way to do it. will change
…onded to return Error types instead of anyhow
0c8f97d
to
0afe3e1
Compare
using the trick of mimicking cross contract call to return a promise from the yield/resume |
* fix contract tests, add attached and required to errors * error and error messages naming * return more specific errors in user facing functions * fix error conversion issue * separate user facing functions into one impl block * move some of the contract structs to primitives * API and envs README * revert MpcError -> SignError * fmt * Update chain-signatures/contract/src/errors.rs Co-authored-by: DavidM-D <[email protected]> * Update chain-signatures/contract/src/errors.rs Co-authored-by: DavidM-D <[email protected]> * Update chain-signatures/contract/src/errors.rs Co-authored-by: DavidM-D <[email protected]> * Update chain-signatures/contract/src/errors.rs Co-authored-by: DavidM-D <[email protected]> * ignore RUSTSEC-2024-0357 * make sign_helper private --------- Co-authored-by: DavidM-D <[email protected]>
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.
not a huge fan of adding another promise on top just to have the return type, but we can probably fix this later without breaking anything since the return promise isn't directly used, just dropped to invoke the promise call
Terraform Feature Environment Destroy (dev-690)Terraform Initialization ⚙️
|
all fn will return Result<_, MpcContractError>.