Skip to content

Commit

Permalink
Fix admissionValidators
Browse files Browse the repository at this point in the history
`admissionValidators` doesn't aggregate errors correctly, as it
aggregates errors in `errs` reference yet it always returns the nil
`err`.

Here, we avoid shadowing `err`, and move variable declarations to where
they are used.
  • Loading branch information
Mahmood Ali committed Oct 28, 2019
1 parent 51484bf commit ba7f4fb
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions nomad/job_endpoint_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,23 @@ func (j *Job) admissionMutators(job *structs.Job) (_ *structs.Job, warnings []er

// admissionValidators returns a slice of validation warnings and a multierror
// of validation failures.
func (j *Job) admissionValidators(origJob *structs.Job) (warnings []error, err error) {
func (j *Job) admissionValidators(origJob *structs.Job) ([]error, error) {
// ensure job is not mutated
job := origJob.Copy()

var w []error
errs := new(multierror.Error)
var warnings []error
var errs error

for _, validator := range j.validators {
w, err = validator.Validate(job)
w, err := validator.Validate(job)
j.logger.Trace("job validate results", "validator", validator.Name(), "warnings", w, "error", err)
if err != nil {
multierror.Append(errs, err)
errs = multierror.Append(errs, err)
}
warnings = append(warnings, w...)
}
return warnings, err

return warnings, errs

}

Expand Down

0 comments on commit ba7f4fb

Please sign in to comment.