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

Replacing unwraps with Errors in application code #492

Merged
merged 9 commits into from
Jan 31, 2025
Merged

Conversation

mmtftr
Copy link

@mmtftr mmtftr commented Jan 30, 2025

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 when unwrap is used outside of tests.

@mmtftr
Copy link
Author

mmtftr commented Jan 30, 2025

The linting won't pass until all unwraps have been removed

@ceyhunsen
Copy link
Member

So, you really are going to convert ALL of the unwraps. Damn.

image

@mmtftr mmtftr marked this pull request as ready for review January 30, 2025 14:14
@mmtftr
Copy link
Author

mmtftr commented Jan 30, 2025

Resolved conflicts

@mmtftr
Copy link
Author

mmtftr commented Jan 30, 2025

Tests are fine, github actions has a problem right now. Will try again later.

Copy link
Member

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

let movetx_agg_nonce = nonce_agg_handle.await.unwrap()?;
let movetx_agg_nonce = nonce_agg_handle
.await
.expect("cancelled task or panic in task")?;
Copy link
Member

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?

Copy link
Author

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

Copy link
Member

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)))??;

Copy link
Author

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.

Copy link
Author

Choose a reason for hiding this comment

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

Tracked in #493

Copy link
Member

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.

Copy link
Author

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.

@mmtftr mmtftr added the HOLD MERGE Hold the merge while you see this label label Jan 31, 2025
@mmtftr
Copy link
Author

mmtftr commented Jan 31, 2025

There are some panic! calls that need to be removed. These are not shown by the lint

url,
auth,
client: rpc,
}
client: Arc::new(rpc),
Copy link
Contributor

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?

Copy link
Author

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.

@mmtftr mmtftr requested a review from ceyhunsen January 31, 2025 09:27
@mmtftr mmtftr added code quality Improves code quality while not affecting any other and removed HOLD MERGE Hold the merge while you see this label labels Jan 31, 2025
@mmtftr mmtftr changed the title Removing unwraps Replacing unwraps with Errors in application code Jan 31, 2025
@mmtftr mmtftr merged commit fac7127 into dev Jan 31, 2025
9 checks passed
@mmtftr mmtftr deleted the efe/unwrap-removal branch January 31, 2025 13:03
@mmtftr mmtftr mentioned this pull request Jan 31, 2025
@mmtftr mmtftr self-assigned this Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code quality Improves code quality while not affecting any other
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants