Skip to content

Preserve the validation error when parsing a malformed statement - #1846

Open
DrVelvetFog wants to merge 1 commit into
sigstore:mainfrom
DrVelvetFog:fix/statement-parse-error-detail
Open

Preserve the validation error when parsing a malformed statement#1846
DrVelvetFog wants to merge 1 commit into
sigstore:mainfrom
DrVelvetFog:fix/statement-parse-error-detail

Conversation

@DrVelvetFog

Copy link
Copy Markdown

Statement(contents=...) discards the pydantic ValidationError, so callers get malformed in-toto statement with no indication of what was malformed — a rejected digest algorithm, a missing field and a bad _type are indistinguishable, and __cause__ is None.

StatementBuilder.build() in the same module already surfaces it:

except ValidationError as e:
    raise Error(f"invalid statement: {e}")

This makes the parsing path match.

Found while parsing a statement whose subject used gitCommit. That rejection is deliberate per #1018 and this doesn't change it — only what the caller is told about it.

The test asserts the cause is preserved and that the message names the offending field; it fails without the change:

AssertionError: assert None is not None
 +  where None = Error('malformed in-toto statement').__cause__

Statement(contents=...) discarded the pydantic ValidationError, leaving
callers with a bare "malformed in-toto statement" and no __cause__, so a
rejected digest algorithm, a missing field and a bad _type were
indistinguishable. StatementBuilder.build() already surfaces the underlying
error; this makes the parsing path match.

Signed-off-by: Antoni Jagodka <tjagodka@gmail.com>
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.

1 participant