jobspec2: ensure consistent error handling between var-file & var.

This commit is contained in:
James Rasell 2021-09-09 11:18:11 +02:00
parent 04a15b5c16
commit 257d63eec9
No known key found for this signature in database
GPG Key ID: AA7D460F5C8377AA
2 changed files with 9 additions and 6 deletions

View File

@ -459,6 +459,7 @@ func (j *JobGetter) ApiJobWithArgs(jpath string, vars []string, varfiles []strin
AllowFS: true,
VarFiles: varfiles,
Envs: os.Environ(),
Strict: true,
})
if err != nil {

View File

@ -536,6 +536,12 @@ func (c *jobConfig) collectInputVariableValues(env []string, files []*hcl.File,
})
}
// Define the severity of variable passed that are undefined.
undefSev := hcl.DiagWarning
if c.ParseConfig.Strict {
undefSev = hcl.DiagError
}
// files will contain files found in the folder then files passed as
// arguments.
for _, file := range files {
@ -583,12 +589,8 @@ func (c *jobConfig) collectInputVariableValues(env []string, files []*hcl.File,
for name, attr := range attrs {
variable, found := variables[name]
if !found {
sev := hcl.DiagWarning
if c.ParseConfig.Strict {
sev = hcl.DiagError
}
diags = append(diags, &hcl.Diagnostic{
Severity: sev,
Severity: undefSev,
Summary: "Undefined variable",
Detail: fmt.Sprintf("A %q variable was set but was "+
"not found in known variables. To declare "+
@ -630,7 +632,7 @@ func (c *jobConfig) collectInputVariableValues(env []string, files []*hcl.File,
variable, found := variables[name]
if !found {
diags = append(diags, &hcl.Diagnostic{
Severity: hcl.DiagError,
Severity: undefSev,
Summary: "Undefined -var variable",
Detail: fmt.Sprintf("A %q variable was passed in the command "+
"line but was not found in known variables. "+