Skip to content

Include the error in literal validator messages - #1674

Merged
TristonianJones merged 1 commit into
cel-expr:masterfrom
stefanvanburen:svanburen/validator-literal-errors
Nov 18, 2026
Merged

TristonianJones merged 1 commit into
cel-expr:masterfrom
stefanvanburen:svanburen/validator-literal-errors

Conversation

@stefanvanburen

Copy link
Copy Markdown
Contributor

formatValidator.Validate drops the error from its check and only reports invalid <function> argument, which doesn't say what's actually wrong with the literal. This appends the error, the same way networkFormatValidator in ext/network.go already does, so e.g. ValidateRegexLiterals goes from:

ERROR: <input>:1:17: invalid matches argument

to:

ERROR: <input>:1:17: invalid matches argument: error parsing regexp: invalid nested repetition operator: `++`

Evaluating the same expression (or building the program with OptOptimize) already returns the full error parsing regexp: ... error, so this just makes the compile-time check match.

Noticed this while trying out ValidateRegexLiterals in buf lint for protovalidate rules, where the old message leaves you guessing which part of the regex is broken. The duration and timestamp validators share formatValidator, so they pick up the extra detail too (the duration one is less helpful, since evalCall just gives back a type conversion error, but it's no worse than before).

`formatValidator.Validate` reports an invalid literal as only
`invalid <function> argument`, dropping the error returned by the check.
For `ValidateRegexLiterals` that error says what is wrong with the
pattern, which is the part a user needs to fix it.

Report the error after the message, matching what
`networkFormatValidator` in `ext/network.go` already does. This applies
to `ValidateDurationLiterals`, `ValidateTimestampLiterals`, and
`ValidateRegexLiterals`, which share `formatValidator`.
@stefanvanburen
stefanvanburen marked this pull request as ready for review November 18, 2026 22:08
@TristonianJones

Copy link
Copy Markdown
Collaborator

/gcbrun

@TristonianJones
TristonianJones merged commit 9b68b5c into cel-expr:master Nov 18, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants