Skip to content

Commit

Permalink
job parsing: fix panic when variable validation is missing condition (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross authored Feb 1, 2023
1 parent 67f8f22 commit 00d5749
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/16018.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
parser: Fixed a panic in the job spec parser when a variable validation block was missing its condition
```
11 changes: 11 additions & 0 deletions jobspec2/types.variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ func (v *Variable) validateValue(val VariableAssignment) (diags hcl.Diagnostics)
for _, validation := range v.Validations {
const errInvalidCondition = "Invalid variable validation result"

if validation.Condition == nil {
diags = append(diags, &hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: "Invalid variable validation specification",
Detail: "validation requires a condition.",
Subject: validation.DeclRange.Ptr(),
EvalContext: hclCtx,
})
continue
}

result, moreDiags := validation.Condition.Value(hclCtx)
diags = append(diags, moreDiags...)
if !result.IsKnown() {
Expand Down

0 comments on commit 00d5749

Please sign in to comment.