cmd/abigen: (v2) added a package-level error for event signature mismatch - #34076
Merged
Conversation
Contributor
|
Makes sense to me. I'll tag this so we can discuss it as a team. |
Member
|
Generally makes sense. One question is if this error should be defined in the abigen package or like you have here where it is generated for each file. I don't have a great intuition which is more correct to be honest. |
jwasinger
reviewed
Mar 24, 2026
…ed from bind package errors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces the inline
errors.New("event signature mismatch")in generatedUnpackXxxEventmethods with per-event package-level sentinel errors (e.g.ErrTransferSignatureMismatch,ErrApprovalSignatureMismatch), allowing callers to reliably distinguish a topic mismatch from a genuine decoding failure viaerrors.Is.Each event gets its own sentinel, generated via the abigen template:
This scoping is intentional — it allows callers to be precise about which event was mismatched, which is useful when routing logs across multiple unpackers.
Motivation
Previously, all errors returned from
UnpackXxxEventwere indistinguishable without string matching. This is especially problematic when processing logs sourced frometh_getBlockReceipts, where a caller receives the full set of logs for a block across all contracts and event types. In that context, a signature mismatch is expected and should be skipped, while any other error (malformed data, topic parsing failure) indicates something is genuinely wrong and should halt execution:Changes:
abigentemplate: generates aErrXxxSignatureMismatchsentinel per event and returns it on topic mismatch instead of an inline errorImplements #34075