Skip to content

Set field descriptor on map entry violations#324

Open
haines wants to merge 1 commit into
bufbuild:mainfrom
haines:map-violation-field-descriptor
Open

Set field descriptor on map entry violations#324
haines wants to merge 1 commit into
bufbuild:mainfrom
haines:map-violation-field-descriptor

Conversation

@haines

@haines haines commented Jun 15, 2026

Copy link
Copy Markdown

Fixes #322

Signed-off-by: Andrew Haines <andrew@haines.org.nz>
haines added a commit to cerbos/cerbos that referenced this pull request Jun 16, 2026
This PR removes `util.ReadJSONOrYAML` in favour of our custom parser, so
that we get consistent behaviour and richer errors everywhere. This
means we can remove the workaround of validating test files with the
JSON schema in favour of protovalidate.

I did run into one drawback of protovalidate, which is that it reports
errors based on the numeric enum values
(bufbuild/protovalidate-go#125). I've added
custom handling for `enum.in` validation failures (which are the only
enum-based rules we have) to construct a friendlier error message.
Unfortunately, I then ran into bugs in protovalidate
(bufbuild/protovalidate-go#322,
bufbuild/protovalidate-go#323), so I've had to
fork it and add a `replace` directive until my PR
(bufbuild/protovalidate-go#324) is merged. We'll
need to copy that to Hub.

I've done all the internal YAML/JSON parsing (mainly test cases) with
the custom parser too, which is probably not strictly necessary, but did
help to surface several bugs in the parser, so I think it's worthwhile.

Signed-off-by: Andrew Haines <haines@cerbos.dev>
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.

[BUG] Violation.FieldDescriptor is nil for map.values violations

1 participant