From 6b2c53f0067a88da3c6637e34b05745ed0380e22 Mon Sep 17 00:00:00 2001 From: James Rasell Date: Thu, 9 Sep 2021 11:18:11 +0200 Subject: [PATCH 1/2] jobspec2: ensure consistent error handling between var-file & var. --- command/helpers.go | 1 + jobspec2/types.variables.go | 14 ++++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/command/helpers.go b/command/helpers.go index 4bf8b66e6ec..ee0de86a84b 100644 --- a/command/helpers.go +++ b/command/helpers.go @@ -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 { diff --git a/jobspec2/types.variables.go b/jobspec2/types.variables.go index 4d4e92cd4b1..688018a19da 100644 --- a/jobspec2/types.variables.go +++ b/jobspec2/types.variables.go @@ -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. "+ From e8efbd83757c252331df80afca772585010f8a0b Mon Sep 17 00:00:00 2001 From: James Rasell Date: Thu, 4 Nov 2021 15:35:02 +0100 Subject: [PATCH 2/2] changelog: add entry for #11165 --- .changelog/11165.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/11165.txt diff --git a/.changelog/11165.txt b/.changelog/11165.txt new file mode 100644 index 00000000000..6db3f0d0fbb --- /dev/null +++ b/.changelog/11165.txt @@ -0,0 +1,3 @@ +```release-note:bug +jobspec: ensure consistent error handling between var-file & cli vars +```