Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Nov 4, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions command/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 8 additions & 6 deletions jobspec2/types.variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 "+
Expand Down Expand Up @@ -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. "+
Expand Down