-
Notifications
You must be signed in to change notification settings - Fork 16
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
Replacing unwraps with Errors in application code #492
Conversation
The linting won't pass until all unwraps have been removed |
Resolved conflicts |
Tests are fine, github actions has a problem right now. Will try again later. |
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.
Pretty nice overall.
I'd say we need ways to avoid developers pushing the usage of except, too. By maybe utilizing error handling to it's fullest (mentioned in #481), check scripts for PR's (reports the new except usages) or stricter reviews.
core/src/rpc/aggregator.rs
Outdated
let movetx_agg_nonce = nonce_agg_handle.await.unwrap()?; | ||
let movetx_agg_nonce = nonce_agg_handle | ||
.await | ||
.expect("cancelled task or panic in task")?; |
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't we return Status
instead?
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 think an inner panic should be propagated to an outer panic. We're now making it so that panics are unrecoverable errors, we shouldn't try to recover from them.
for cancelled task, I'm not sure what it actually means. I'll check
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.
This should be fine I think:
let movetx_agg_nonce = nonce_agg_handle
.await.map_err(|e| Status::aborted(format!("Failed to aggregate nonces: {:?}", e)))??;
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.
Just checked but the unwrap will only panic if the underlying task panics in our case. Check JoinError for more info.
Panics should happen with unrecoverable errors (like memory corruption, invariant violation, etc). In such cases, terminating the program is a better option than attempting to return an error IMO.
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.
Tracked in #493
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.
Ok but if that happens and except panics, doesn't aggregator server will stop responding instead of just returning an error code to the caller? Why would we want to aggregator to terminate? This could happen if one of the params is incorrect. This will punish an honest and correct aggregator.
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.
We shouldn't panic on an incorrect parameter, but I'll still return an internal error here.
There are some |
url, | ||
auth, | ||
client: rpc, | ||
} | ||
client: Arc::new(rpc), |
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 you please explain why the changes here?
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.
Client
is not Clone
but Arc<Client>
is, since Arc
has an infallible clone impl. The difference is, we're not constructing a new Client on every clone but sharing a reference to the same client. If the inner Client needs to be cloned, we now have a new clone_inner
function that's fallible.
All client RPC functions take the client by reference, so we don't need anything mutable anyway.
Description
This PR aims to resolve the usage of unwraps throughout the codebase. The aim is to add insightful error messages to all unwrap() callsites.
Linked Issues
Testing
Added a
unwrap_used
lint that will error whenunwrap
is used outside of tests.