-
Notifications
You must be signed in to change notification settings - Fork 725
Chore/add custom error to clarity types #6751
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
base: develop
Are you sure you want to change the base?
Chore/add custom error to clarity types #6751
Conversation
…tioError Signed-off-by: Jacinta Ferrant <[email protected]>
… into chore/add-custom-error-to-clarity-types
… into chore/add-custom-error-to-clarity-types
…om/Jiloc/stacks-core into chore/add-custom-error-to-clarity-types
Codecov Report❌ Patch coverage is ❌ Your project check has failed because the head coverage (77.42%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## develop #6751 +/- ##
===========================================
- Coverage 77.90% 77.42% -0.48%
===========================================
Files 580 580
Lines 361187 361490 +303
===========================================
- Hits 281374 279877 -1497
- Misses 79813 81613 +1800
... and 91 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
826c4d7 to
9d27ff0
Compare
Signed-off-by: Jacinta Ferrant <[email protected]>
59cb8ff to
b8ca7dd
Compare
… into chore/add-custom-error-to-clarity-types
Signed-off-by: Jacinta Ferrant <[email protected]>
federico-stacks
left a comment
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.
Did a first pass. In the meantime, I’m sharing some thoughts
| /// TODO: Do we want to make these return errors? I know in theory its infallible, but there is a lot of | ||
| /// in theory infallible that return errors instead of straight expects. |
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.
Good point! I don’t have a definitive answer. On one hand, I’d prefer to eliminate the expect calls; on the other hand, they do help break the "error chain".
| } | ||
|
|
||
| fn admits_type_v2_1(&self, other: &TypeSignature) -> Result<bool, CommonCheckErrorKind> { | ||
| fn admits_type_v2_1(&self, other: &TypeSignature) -> Result<bool, ClarityTypeError> { |
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 sharing some reasoning on possibly changing admits_type_v2_0 and admits_type_v2_1 to return a plain bool instead of Result<bool, ClarityTypeError>:
- For both admits_type_v2_0 and admits_type_v2_1, it looks feasible to return only bool since they don’t meaningfully use the error channel.
- The only blocker comes from the top-level admits_type, which currently returns
StacksEpochId::Epoch10 => Err(ClarityTypeError::UnsupportedEpoch(*epoch))
If we could treat that case as StacksEpochId::Epoch10 => false instead, then all admits_type* methods could avoid returning ClarityTypeError entirely.
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 don't think they can do this. I had tried before and admits_type_v2_0 both rely on recognizing the type otherwise they return Err(ClarityTypeError::CouldNotDetermineType) which I think it important? I mean maybe at that point you can ALSO just return false? However, I am not 100 percent sure at this point and think it should be a sep ticket to look into the repercussions of treating any failure to determine the type as false.
brice-stacks
left a comment
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 left a couple of comments, but before going further, I think I'm having trouble seeing the overall goal of all of this.
| impl From<ClarityTypeError> for StaticCheckErrorKind { | ||
| fn from(err: ClarityTypeError) -> Self { | ||
| match err { | ||
| ClarityTypeError::ValueTooLarge => Self::ValueTooLarge, |
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'm finding all of these repeated errors confusing. It feels like there should instead be a StaticCheckErrorKind (and others) that contains a ClarityTypeError instead of replicating all of these.
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 am currently avoiding changing any of the StaticCheckErrorKind or CheckErrorKind. The idea is that underlying errors should be mapped only to the relevant ones in the *CheckErrorKind types. i.e. granularity can be lost as you go up through the chain and we are wanting as flat of a map as possible in the CheckError types. But perhaps this is wrong and we should just hold a TypeError but I am not 100% confident that these typerrors change their importance depending on WHGERE they are called. i.e. check error kinds may treat the same error type as fatal in some isntances vs not. Would do this sort of change in a sep PR.
Essentially we are trying to pry apart unnecessary coupling between underlying clarity type creation/serialization/deserialization etc from static checks and vm executions as these functions are used throughout the code base where no vm is even required and we are not actually performing static checks. This is basically the first step in enabling easier refactoring. If clarity-types returns CheckErrorKind, we've coupled the lowest layer to the VM/checker layer. That creates dependency inversion and makes refactors brutal. I do think there is currently a lot of redundancy but this is required until we can pull it all apart properly. Additionally, you can get better error messages/types at the lower level that then are mapped to whatever the caller cares about. Sorry if I am not explaining this well. |
…Data Signed-off-by: Jacinta Ferrant <[email protected]>
I have added a bunch of comments that I will need to rip out before merging this. Mostly around where I am changing what was previously an "Expect" into a Nonexpect error. Mostly cause they prob shouldn't ever happen/I don't know why they would actually invalidate a block. I also added an ExpectAcceptable and ExpectRejectable type.
Feedback would be good.