Skip to content

Commit

Permalink
ensure validation errors include names for better context (#253)
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Mason <[email protected]>
  • Loading branch information
mikemrm authored Aug 7, 2024
1 parent 53c0413 commit 80e37d9
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions internal/iapl/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,22 +394,22 @@ func (v *policy) validateActionBindings() error {
}

if _, ok := bindingMap[key]; ok {
return fmt.Errorf("%d: %w", i, ErrorActionBindingExists)
return fmt.Errorf("%d (%s:%s): %w", i, binding.TypeName, binding.ActionName, ErrorActionBindingExists)
}

bindingMap[key] = struct{}{}

if _, ok := v.ac[binding.ActionName]; !ok {
return fmt.Errorf("%d: %s: %w", i, binding.ActionName, ErrorUnknownAction)
return fmt.Errorf("%d (%s:%s): %s: %w", i, binding.TypeName, binding.ActionName, binding.ActionName, ErrorUnknownAction)
}

rt, ok := v.rt[binding.TypeName]
if !ok {
return fmt.Errorf("%d: %s: %w", i, binding.TypeName, ErrorUnknownType)
return fmt.Errorf("%d (%s:%s): %s: %w", i, binding.TypeName, binding.ActionName, binding.TypeName, ErrorUnknownType)
}

if err := v.validateConditions(rt, binding.Conditions); err != nil {
return fmt.Errorf("%d: conditions: %w", i, err)
return fmt.Errorf("%d (%s:%s): conditions: %w", i, binding.TypeName, binding.ActionName, err)
}
}

Expand Down

0 comments on commit 80e37d9

Please sign in to comment.