Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle compile errors #40

Merged
merged 2 commits into from
Mar 18, 2024
Merged

fix: handle compile errors #40

merged 2 commits into from
Mar 18, 2024

Conversation

matheusfm
Copy link
Contributor

Description

This PR handles compilation errors of validations and variables and implements unit test for Compile function.

How has this been tested?

  • Running the unit tests: make test
  • Scanning with a custom check with invalid variable or validation:
cat << 'EOF' > tmp/check.yaml
id: test
severity: High
message: "invalid validation"
match:
  resources:
    - group: ""
      version: v1
      resource: pods
validations:
  - expression: allContainers.all(variables.foo)
EOF
go run main.go scan --disable-builtin --checks /tmp/check.yaml 

Now we expect to see an error like this:

E0318 17:03:19.731543   54820 scan.go:218] "msg"="failed to compile check test" "error"="validations[0].expression: type-check error: ERROR: <input>:1:18: undeclared reference to 'all' (in container '')\n | allContainers.all(variables.test)\n | .................^\nERROR: <input>:1:19: undeclared reference to 'variables' (in container '')\n | allContainers.all(variables.test)\n | ..................^" "check"="test"
I0318 17:03:19.731708   54820 scan.go:186] "msg"="scan finished with errors" 
SEVERITY   ID     CHECK                STATUS   FAILED   PASSED   SKIPPED 
High       test   invalid validation   ERROR    0        0        0         
exit status 2

Checklist

  • I have labeled this PR with the relevant Type labels
  • I have documented my code (if applicable)
  • My changes are covered by tests

@matheusfm matheusfm added the bug Something isn't working label Mar 18, 2024
@matheusfm matheusfm requested a review from knrc March 18, 2024 20:04
@matheusfm matheusfm self-assigned this Mar 18, 2024
@matheusfm matheusfm merged commit bf022c9 into main Mar 18, 2024
4 checks passed
@matheusfm matheusfm deleted the UD-1296-handle-errors branch March 18, 2024 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants