-
Notifications
You must be signed in to change notification settings - Fork 3
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
Return visitor errors over skip_decode errors if there are any #58
Conversation
is it possible to add a test to check for this behaviour? |
Good comment; lemme look at doing that! |
scale-decode/src/visitor/decode.rs
Outdated
@@ -123,10 +123,17 @@ impl<'temp, 'scale, 'resolver, V: Visitor> ResolvedTypeVisitor<'resolver> | |||
let res = self.visitor.visit_composite(&mut items, self.type_id); | |||
|
|||
// Skip over any bytes that the visitor chose not to decode: | |||
items.skip_decoding()?; | |||
*self.data = items.bytes_from_undecoded(); | |||
let skip_res = items.skip_decoding(); |
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.
Is it possible to extract "this logic" to a helper function that we can re-use instead repeating it for the other visitors?
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.
the types are all a bit different and just happen to have the same method names; it could be a macro though :)
I added tests to confirm the behaviour, all of which fail on |
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.
lgtm
Before this, if we hit an error when skipping over any remaining composite/variant/tuple/sequence items, we'd return that error, even if the visitor which we called returned an error of its own. This would obscure more meaningful errors behind vague skip_decode ones.
Now we prioritize returning visitor errors if there are any, to get somehting more useful back!