Skip to content

fix: surface proper parsing errors for malformed v2 contracts#2992

Merged
Piskoo merged 1 commit into
chainloop-dev:mainfrom
Piskoo:pfm-5338
Apr 7, 2026
Merged

fix: surface proper parsing errors for malformed v2 contracts#2992
Piskoo merged 1 commit into
chainloop-dev:mainfrom
Piskoo:pfm-5338

Conversation

@Piskoo

@Piskoo Piskoo commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

When a user provided a v2 contract YAML with valid metadata but a structural error in the spec (e.g., materials: ref: vulnerabilities instead of materials: - ref: vulnerabilities), the server returned a misleading "name is required" error. The actual parsing error was silently swallowed in extractMetadata().

The fix uses a lenient proto parse to detect v2 fields (apiVersion and kind) even when the contract has structural errors. When a v2 contract is detected but has parse errors, the actual error is now surfaced to the user.

Before

$ chainloop apply -f testcontract.yml 
WRN API contacted in insecure mode
ERR parsing file testcontract.yml: missing 'metadata.name' field in YAML document of kind "Contract"
exit status 1

After

$ chainlooop apply -f testcontract.yml 
WRN API contacted in insecure mode
ERR invalid contract: error unmarshalling raw message: :8:13 expected sequence, got mapping
   8 |             ref: vulnerabilities
   8 | ............^

exit status 1

Signed-off-by: Sylwester Piskozub <sylwesterpiskozub@gmail.com>
@Piskoo Piskoo marked this pull request as ready for review April 7, 2026 11:06

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 2 files

@migmartri

Copy link
Copy Markdown
Member

can you provide an example of the before and after?

@Piskoo Piskoo merged commit 7f66ba1 into chainloop-dev:main Apr 7, 2026
15 checks passed
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.

2 participants