Skip to content

Conversation

robmyersrobmyers
Copy link
Contributor

@robmyersrobmyers robmyersrobmyers commented Jun 14, 2025

Open Policy Agent prunes Position information from its AST tree prior to calling validator.ValidateSchemaDocument(), which causes a runtime error and panic when a bad schema is encountered because ErrorPosf() does not check for nil input.

This PR adds a test case and returns some default values if a nil pos is passed to ErrorPosf().

The default values I've chosen may not be the best as some people do not expect row/column information to be negative. See #254, for example. I'm not tied to these values - I just don't want a crash in this case.

I didn't see any related documentation that needed an update handling this case.

I have:

  • Added tests covering the bug / feature
  • Ran go test ./... to ensure no other tests fail as a result of this change

This resolves #375

Signed-off-by: Rob Myers <1243316+robmyersrobmyers@users.noreply.github.com>
@coveralls
Copy link

Coverage Status

coverage: 87.668% (+0.02%) from 87.649%
when pulling 99ae57e on robmyersrobmyers:errorposf_handle_nil_pos
into f7a3835 on vektah:master.

@StevenACoffman StevenACoffman merged commit eadea45 into vektah:master Jun 14, 2025
7 checks passed
@StevenACoffman
Copy link
Collaborator

Oh, thanks! That's great!

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.

ErrorPosf does not check for nil *ast.Position
3 participants