Skip to content

Commit

Permalink
fix error handling if .chartsnap.yaml is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
jlandowner committed Dec 20, 2023
1 parent 9285f4c commit e19578e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,11 @@ func run(cmd *cobra.Command, args []string) error {
if f.Name() == o.ConfigFile {
cfg, err = charts.LoadSnapshotConfig(path.Join(o.ValuesFile, f.Name()))
if err != nil {
// err
if o.FailFast {
return fmt.Errorf("failed to load snapshot config: %w", err)
} else {
log.Error("warning: failed to load snapshot config", "path", path.Join(o.ValuesFile, f.Name()), "err", err)
}
}
continue
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/charts/testspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ func LoadSnapshotConfig(file string) (SnapshotConfig, error) {
cfg := SnapshotConfig{}
f, err := os.Open(file)
if err != nil {
return cfg, nil
if os.IsNotExist(err) {
return cfg, nil // ignore not found
} else {
return cfg, fmt.Errorf("failed to open config file '%s': %w", file, err)
}
}
defer f.Close()

Expand Down

0 comments on commit e19578e

Please sign in to comment.