starknet_api: avoid double-parse in TryFrom<ProofFacts> for SnosProofFacts error path#14611
Open
gkaempfer wants to merge 3 commits into
Open
starknet_api: avoid double-parse in TryFrom<ProofFacts> for SnosProofFacts error path#14611gkaempfer wants to merge 3 commits into
gkaempfer wants to merge 3 commits into
Conversation
…Facts error path After #14598 introduced a custom Debug impl for ProofFacts that calls ProofFactsVariant::try_from internally, the error arm of TryFrom<ProofFacts> for SnosProofFacts was triggering a redundant second parse via the {proof_facts:?} format argument. Propagate the inner error from the first try_from call directly instead, and handle the Empty variant explicitly with a descriptive message. Also adds tests covering the success path, the empty-input rejection, and the inner-error propagation.
…tion - Capitalize 'Expected SNOS proof facts, got empty' to match the style of all other InvalidProofFacts messages in this file. - Rename test to drop the unverifiable 'without_reparsing' claim and add a positive assertion that the propagated inner error message contains 'Expected first field', pinning the actual content rather than only checking absence of the old wrapper string.
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
Follow-up optimization to #14598.
PR #14598 introduced a custom
Debugimpl forProofFactsthat internally callsProofFactsVariant::try_from. This exposed a latent inefficiency inTryFrom<ProofFacts> for SnosProofFacts: its error arm used{proof_facts:?}in the format string, which now triggers a redundant second call toProofFactsVariant::try_from— the inner error from the first call was being discarded and the data re-parsed just to build the error message.Change
_error arm with explicit matching: propagate the innerErrvia?(reusing its already-descriptive message), and handle theEmptyvariant separately with a clear message.Before / After
Before — error path triggered two parses:
After — inner error propagated directly:
Expected impact
Eliminates one redundant
ProofFactsVariant::try_fromcall on every error path throughTryFrom<ProofFacts> for SnosProofFacts. Also produces more specific error messages (the inner parse error explains exactly what was wrong, rather than a generic wrapper).Test plan
All 9 tests pass, including 3 new ones added by this PR.
Generated by Claude Code