Skip to content

Commit

Permalink
Make "k0s config validate" display parsing and validation errors
Browse files Browse the repository at this point in the history
Before this, the "k0s config validate" was completely silent even in
case of any parsing or validation errors.

Here SilenceErrors was disabled to allow parsing errors to be shown and
a simple loop for displaying validation errors one by one was added.

Signed-off-by: Kimmo Lehto <[email protected]>
  • Loading branch information
kke committed Oct 9, 2023
1 parent 44cb1a5 commit 1d9378d
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions cmd/config/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,18 @@ func NewValidateCmd() *cobra.Command {

errs := cfg.Validate()
if len(errs) > 0 {
return fmt.Errorf("config validation failed: %w", errors.Join(errs...))
stderr := cmd.ErrOrStderr()
fmt.Fprintln(stderr, "Validation failed:")
for _, e := range errs {
fmt.Fprintln(stderr, "-", e.Error())
}
cmd.SilenceErrors = true
return errors.Join(errs...)
}

return nil
},
SilenceUsage: true,
SilenceErrors: true,
SilenceUsage: true,
}

cmd.PersistentFlags().AddFlagSet(config.GetPersistentFlagSet())
Expand Down

0 comments on commit 1d9378d

Please sign in to comment.