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

Return visitor errors over skip_decode errors if there are any #58

Merged
merged 6 commits into from
Jun 7, 2024

Conversation

jsdw
Copy link
Collaborator

@jsdw jsdw commented Jun 6, 2024

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!

@jsdw jsdw requested a review from a team as a code owner June 6, 2024 16:54
@pkhry
Copy link
Contributor

pkhry commented Jun 6, 2024

is it possible to add a test to check for this behaviour?

@jsdw
Copy link
Collaborator Author

jsdw commented Jun 6, 2024

is it possible to add a test to check for this behaviour?

Good comment; lemme look at doing that!

@@ -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();
Copy link
Member

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?

Copy link
Collaborator Author

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 :)

@jsdw
Copy link
Collaborator Author

jsdw commented Jun 7, 2024

I added tests to confirm the behaviour, all of which fail on main and pass here, amd macroized the code repetition

Copy link
Contributor

@pkhry pkhry left a comment

Choose a reason for hiding this comment

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

lgtm

@jsdw jsdw merged commit 5db248f into main Jun 7, 2024
10 checks passed
@jsdw jsdw deleted the jsdw-visitor-errors-first branch June 7, 2024 13:21
@jsdw jsdw mentioned this pull request Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants