Skip to content
This repository has been archived by the owner on Jun 28, 2022. It is now read-only.

Improve Rego error location reporting #12

Open
jpeach opened this issue Aug 3, 2020 · 0 comments
Open

Improve Rego error location reporting #12

jpeach opened this issue Aug 3, 2020 · 0 comments

Comments

@jpeach
Copy link
Contributor

jpeach commented Aug 3, 2020

integration-tester creates implicit Rego packages for every document fragment that is detected as Rego, then compiled the whole conglomeration together in order to preflight compilation and syntax errors before making any cluster changes.

Since the Rego parser only ever sees the Rego language as strings, however, line numbers for error messages are relative to the fragment where the error is, not relative to the test document as a whole. This makes it awkward to correlate errors back to the original source (requires a bit of guesswork).

For example, this error is in part 1, but because it is a duplicate variable definition, we don't know until we compile the whole thing. Since the Rego compiler doesn't have the right line offsets to start with, it can't emit the right error location. The Rego parser has API to pass in the filename of a string to compile, but no API to set the initial line offsets.

$ ./run-test-case.sh ./httpproxy/012-https-fallback-certificate.yaml
TAP version 13
# reading document from ./httpproxy/012-https-fallback-certificate.yaml
# decoding document with 8 parts from ./httpproxy/012-https-fallback-certificate.yaml
# decoded part 0 as Kubernetes (lines 1-10)
# decoded part 1 as Rego (lines 12-42)
# decoded part 2 as Kubernetes (lines 44-121)
# decoded part 3 as Kubernetes (lines 123-131)
# decoded part 4 as Kubernetes (lines 133-141)
# decoded part 5 as Kubernetes (lines 143-158)
# decoded part 6 as Rego (lines 160-186)
# decoded part 7 as Rego (lines 188-214)
ok 1 - validating document "./httpproxy/012-https-fallback-certificate.yaml"
# test run ID is 52f423e6-504e-4e41-97ec-aa8c6349f05a
# Fatal - 1 error occurred: internal/check/ACnGakFqooos:28: rego_compile_error: var msg assigned above
not ok 2 - compiling test document
  ---
  - Message: '1 error occurred: internal/check/ACnGakFqooos:28: rego_compile_error:
      var msg assigned above'
    Severity: Fatal
    Timestamp: "2020-08-03T14:25:30.585828+10:00"

  ...
# skipping
ok 3 - deleting test objects
1..3
jpeach added a commit to jpeach/integration-tester that referenced this issue Aug 3, 2020
It is awkward to map the location of Rego erros back to the right
line on the test document, but we can improve things (in a hacky way)
by capturing the file and line number in the filename that we feed to
Rego when we compile a fragment.

This updates projectcontour#12.

Signed-off-by: James Peach <[email protected]>
jpeach added a commit that referenced this issue Aug 4, 2020
It is awkward to map the location of Rego erros back to the right
line on the test document, but we can improve things (in a hacky way)
by capturing the file and line number in the filename that we feed to
Rego when we compile a fragment.

This updates #12.

Signed-off-by: James Peach <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant