-
Notifications
You must be signed in to change notification settings - Fork 800
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
Create coded exceptions for invariant violations #2242
Create coded exceptions for invariant violations #2242
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. Join @steveluscher and the rest of your teammates on |
f2a99cc
to
80f64a6
Compare
Add link to issue tracker |
80f64a6
to
097c92d
Compare
ea29eaa
to
9a1834c
Compare
throw new SolanaError(SOLANA_ERROR__INVARIANT_VIOLATION_SWITCH_MUST_BE_EXHAUSTIVE, { | ||
unexpectedValue: commitment satisfies never, | ||
}); |
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 one smells a little bit. I guess the only way this gets thrown is if someone isn't using TypeScript (or ignores it) and sends a string that isn't a valid Commitment
. Shouldn't the error say that, then? ie. SOLANA_ERROR__INVALID_COMMITMENT_VALUE
?
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.
Yeah, I was trying to make something that was generally usable for exhaustive switches. The error location will tell the developer where the unhandled value was thrown, which I figured was enough paired with the actual unexpected value.
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.
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 do actually like that we have utility errors for these sort of invariants.
097c92d
to
1041fb6
Compare
Merge activity
|
🎉 This PR is included in version 1.91.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Because there has been no activity on this PR for 14 days since it was merged, it has been automatically locked. Please open a new issue if it requires a follow up. |
Summary
Invariant violations are a kind of error that should never get hit ever, and if they do your program is broken.
In one sense we don't want error codes for them because they're not intended to be caught in downstream programs. On the other hand I've tried to come up with a reason not to give them codes and I can't.
Making them a
@solana/error
gives us compression and error decoding for free.Addresses #2118.