Loading
Stop reporting Rego parse refusals to Sentry
What does this MR do and why?
- The Policy Store backend now parses every custom Rego rule on policy save and refuses a program it cannot parse (work item https://gitlab.com/gitlab-org/gitlab/-/work_items/618556). The refusal comes back as a flat string in the mutation's
errorsfield, shapedrules[N] is invalid: <engine message> (at <line>:<column>). - The editor's
onSavehandler treated that refusal like a failed request: it showed the message in a page alert and also calledSentry.captureException. - Unparseable Rego is author input, not a bug, so it should not go to Sentry. Adds
isRuleRegoParseErrortoee/app/assets/javascripts/policy_store/utils.jsand guards the existing Sentry call with it inee/app/assets/javascripts/policy_store/components/editor/app.vue. The alert itself is unchanged. - The predicate matches the whole trimmed message with an anchored pattern instead of splitting on
;.RegoValidator#reported_errorsjoins one rule's engine errors with"; "in a single refusal, andwith_compiled_rulesraises on the first failing rule, so only onerules[N] is invalid:prefix can ever appear per message. Splitting on;would send an ordinary two-typo program to Sentry. - A merged-program refusal (
policy_rego is invalid: ..., raised byvalidate_merged_program!when rules parse alone but conflict once combined) is also author input but has a different shape, and it is still reported. https://gitlab.com/gitlab-org/gitlab/-/work_items/629577 notes merged-module engine faults surface as top-level GraphQL errors handled separately in https://gitlab.com/gitlab-org/gitlab/-/work_items/629203 — but a merged program that fails to parse raises aValidationErrorand does reach this same handler. Worth confirming against real Sentry events before 629577 is closed. - Nothing that is a genuine failure is suppressed: an engine fault, a 500, a network error, or a top-level GraphQL error does not arrive as a
PolicyStoreMutationError, soapiErrorMessagereturns undefined and the pattern does not match. - Where in the editor the refusal should live, and whether the API should return a structured shape instead of a flat string, are separate open decisions on https://gitlab.com/gitlab-org/gitlab/-/work_items/629577 and are deliberately not settled here.
References
- Issue: https://gitlab.com/gitlab-org/gitlab/-/work_items/629577
- Parent work item (backend validation): https://gitlab.com/gitlab-org/gitlab/-/work_items/618556
- Backend validator MR: !254245 (merged)
- Related, top-level GraphQL errors: https://gitlab.com/gitlab-org/gitlab/-/work_items/629203
Screenshots or screen recordings
N/A — no rendered output changes. The refusal alert is unchanged; only whether the refusal is captured as an exception.
How to set up and validate locally
- Enable the Policy Store experiment: the instance-level
policy_store_experiment_enabledapplication setting plus the organization setting. - Go to an organization's Policy Store and create a policy with a Custom Rule (Rego) whose program does not parse, for example a body of
package governancefollowed bydeny contains msg if {theninput.environment.name ==. - Save. The red alert still reports
rules[0] is invalid: ...and the wizard stays on the Review step. - Confirm no Sentry event is produced for it (check the browser console / Sentry stub in development).
- Run
node_modules/.bin/jest ee/spec/frontend/policy_store/utils_spec.js ee/spec/frontend/policy_store/components/editor/app_spec.js --no-coverage
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist.