Skip to content

Commit

Permalink
feat: Improve config invalid error report (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
j178 authored Jan 30, 2023
1 parent 580d446 commit 8028906
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 8 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,14 @@ var rootCmd = &cobra.Command{
return err
}
initLogger()
return config.Load(cmd == initCmd)
err = config.Load(cmd == initCmd)
if err != nil {
return fmt.Errorf(
"%w\nSeems like your configuration is not a valid YAML file, please paste your configuration to tools like https://www.yamllint.com/ to fix it.",
err,
)
}
return nil
},
}

Expand Down
6 changes: 3 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func Load(init bool) error {
}
return nil
}
return err
return fmt.Errorf("load config file %s failed: %w", cfg.GlobalConfigFile(), err)
}

// Don't read project config if we are running `init` command
Expand All @@ -333,14 +333,14 @@ func Load(init bool) error {
cfg.GlobalConfigFile(),
)
} else {
return err
return fmt.Errorf("load config file %s failed: %w", cfg.ProjectConfigFile(), err)
}
}
}

err = viper.Unmarshal(cfg)
if err != nil {
return err
return fmt.Errorf("config file is invalid: %s", err)
}
if err = verify(cfg); err != nil {
return fmt.Errorf("config file is invalid: %w", err)
Expand Down

0 comments on commit 8028906

Please sign in to comment.