Skip to content

Improve error messages for Rego compilation failures caused by version incompatibilities #3345

@st3penta

Description

@st3penta

When a user's policy rules use Rego syntax or OPA built-in features not supported by the OPA version bundled with ec-cli, the resulting error messages are raw compiler errors from OPA/conftest (e.g. rego_type_error, rego_parse_error) that are difficult to interpret and troubleshoot.

Currently, errors from runner.TestRunner.Run() and conftest.LoadWithData() in internal/evaluator/conftest_evaluator.go propagate directly to the user without any interception or enhancement. For example, a user might see:

Error: error validating image ... : load: loading policies: get compiler: 3 errors occurred:
/tmp/.../main.rego:14: rego_type_error: undefined function opa.runtime

This provides no indication that the issue is a version mismatch between the bundled OPA and the policy's Rego syntax.

Proposed improvements:

  1. Intercept rego_type_error and rego_parse_error from OPA/conftest compilation and wrap them with a user-friendly message explaining the likely cause (OPA/Rego version incompatibility).
  2. Include the bundled OPA version in the error output so users can cross-reference supported features.
  3. Suggest potential solutions (e.g. upgrading ec-cli, or adjusting the policy to use compatible syntax).
  4. Preserve the original low-level error as additional detail for debugging.

Acceptance Criteria:

  • ec-cli produces a helpful, actionable error message when it encounters Rego syntax or features not supported by the bundled OPA version
  • The error message includes the bundled OPA version number
  • The error message suggests potential solutions (upgrade ec-cli or adjust policy syntax)
  • The original compiler error is still available for debugging purposes

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions