feat(#3345): improve error messages for Rego compilation failures#3381
feat(#3345): improve error messages for Rego compilation failures#3381fullsend-ai-coder[bot] wants to merge 2 commits into
Conversation
Intercept rego_type_error and rego_parse_error from OPA/conftest compilation and wrap them with a user-friendly message that includes the bundled OPA version and remediation guidance. Changes: - Add internal/evaluator/rego_errors.go with isRegoCompilationError, bundledOPAVersion, and wrapRegoError helper functions - Apply wrapRegoError in conftest_evaluator.go error paths from TestRunner.Run() and LoadWithData() - Apply wrapRegoError in opa_evaluator.go error path from LoadWithData() - Add unit tests for all new functions covering rego and non-rego error cases, OPA version lookup, and error preservation The original low-level error is preserved via fmt.Errorf %w wrapping so it remains available for debugging. Closes #3345
|
🤖 Finished Review · ✅ Success · Started 8:53 AM UTC · Completed 8:59 AM UTC |
Review — PR #3381Verdict: request-changes OverviewThis PR adds user-friendly error wrapping for OPA/Rego compilation failures, fulfilling all four acceptance criteria from issue #3345. The implementation is clean and well-tested:
The code logic is correct. However, there is one blocking issue. Findings🔴 HIGH — Acceptance test snapshot not updatedFile: The "Dropping rego capabilities" acceptance test ( After this PR, Remediation: Run the acceptance test with 🟡 LOW — Error message refers to "ec-cli" instead of current project nameFile: The wrapped error message says "the one bundled in ec-cli" and "Upgrade ec-cli". The project has been renamed — Remediation: Replace 🟡 LOW — Hardcoded restricted-function list creates maintenance couplingFile: The error message hardcodes Remediation (follow-up): Consider extracting the disallowed builtins into a shared package-level variable that both 🟡 LOW —
|
|
/fs-fix |
|
🤖 Finished Fix · ✅ Success · Started 12:00 PM UTC · Completed 12:12 PM UTC |
Update wrapRegoError to mention capability restrictions (opa.runtime, http.send, net.lookup_ip_addr) as a possible cause alongside version mismatch, so users hitting the security sandbox are not misled into thinking they need to upgrade ec-cli. Addresses review feedback on #3381
|
🤖 Finished Review · ✅ Success · Started 12:12 PM UTC · Completed 12:25 PM UTC |
| return fmt.Errorf("policy compilation error: the policy uses Rego features or built-in "+ | ||
| "functions not available in this configuration. Possible causes:\n\n"+ | ||
| " 1. Version mismatch: the policy requires a newer OPA version than the one bundled "+ | ||
| "in ec-cli (%s)\n"+ |
There was a problem hiding this comment.
[low] naming
Error message refers to "ec-cli" but the project has been renamed to "Conforma CLI" (see cmd/root/root_cmd.go:69). User-facing messages should use the current name.
Suggested fix: Replace "ec-cli" with "conforma" or "Conforma CLI" in the error message template.
| " 1. Version mismatch: the policy requires a newer OPA version than the one bundled "+ | ||
| "in ec-cli (%s)\n"+ | ||
| " 2. Capability restriction: ec-cli disables certain built-in functions for security "+ | ||
| "(e.g. opa.runtime, http.send, net.lookup_ip_addr). If your policy uses any of these, "+ |
There was a problem hiding this comment.
[low] maintainability
The restricted-function list (opa.runtime, http.send, net.lookup_ip_addr) is hardcoded in the error message but the authoritative list lives in strictCapabilities() at conftest_evaluator.go:1199-1205. The lists could diverge over time.
Suggested fix: Extract the disallowed builtins into a shared variable, or add cross-reference comments.
| return false | ||
| } | ||
| msg := err.Error() | ||
| return strings.Contains(msg, "rego_type_error") || strings.Contains(msg, "rego_parse_error") |
There was a problem hiding this comment.
[low] coverage-gap
Only rego_type_error and rego_parse_error are detected. OPA also defines rego_compile_error, rego_unsafe_var_error, and rego_recursion_error. Consider adding rego_compile_error at minimum.
Suggested fix: Add strings.Contains(msg, "rego_compile_error") to isRegoCompilationError.
Intercept rego_type_error and rego_parse_error from OPA/conftest compilation and wrap them with a user-friendly message that includes the bundled OPA version and remediation guidance.
Changes:
bundledOPAVersion, and wrapRegoError helper functions
TestRunner.Run() and LoadWithData()
LoadWithData()
error cases, OPA version lookup, and error preservation
The original low-level error is preserved via fmt.Errorf %w wrapping so it remains available for debugging.
Closes #3345
Post-script verification
agent/3345-rego-error-messages)d134e495b18cf8493cfea8791e310b58f0320797..HEAD)