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

Replace panic with Result #113

Merged
merged 11 commits into from
May 27, 2024
Merged

Replace panic with Result #113

merged 11 commits into from
May 27, 2024

Conversation

dpaiton
Copy link
Contributor

@dpaiton dpaiton commented May 23, 2024

Resolved Issues

#99 #64 #65 #66

Description

Our use of both panic and result results in a worse developer experience, and should be changed to using Result everywhere possible. This PR removes almost all panic uses in the core libs; where functions once would panic but return a type T they now return an error with the typeResult<T>. I also removed unwrap() statements, which convert Result to panic, in most places around the repo.

Exceptions were made for core (anything with sugar like +, -, *) FixedPoint arithmetic (thus keeping any U256 panics), certain test-related cases, and macros.

I also improved some error messaging (in bindings mostly, but also elsewhere), added comments, & added a lint ignore.

I ran the fuzz testing with 10k FUZZ_RUNS and 50k FAST_FUZZ_RUNS twice without error locally.

Copy link
Contributor

@sentilesdal sentilesdal left a comment

Choose a reason for hiding this comment

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

Yeah this all seems fine to me. Add some more in the description if you can. Looks like you're:

  • getting rid of all explicit panic! calls in hyperdrive-math
  • fixedpoint pow returns result
  • fixedpoint exp returns result
  • error messaging improvements in bindings
  • catch overflow panics for max short/long

@dpaiton dpaiton force-pushed the dpaiton/stop-panicking branch from 8cb5007 to 3227ba8 Compare May 26, 2024 18:03
@dpaiton dpaiton force-pushed the dpaiton/stop-panicking branch 2 times, most recently from f4814d0 to e8081cd Compare May 27, 2024 00:12
@dpaiton dpaiton force-pushed the dpaiton/stop-panicking branch from e8081cd to a2f9714 Compare May 27, 2024 00:14
@dpaiton dpaiton merged commit 2561fae into main May 27, 2024
8 checks passed
@dpaiton dpaiton deleted the dpaiton/stop-panicking branch May 27, 2024 00:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants