From e4facef83b8edef00070055a8979fe4c37f1710a Mon Sep 17 00:00:00 2001 From: Charlie Egan Date: Mon, 10 Jun 2024 11:19:51 +0100 Subject: [PATCH] lint/fix: roll over empty config If a config file contains nothing or only comments, then we can roll over it with a more helpful message rather than erroring. Signed-off-by: Charlie Egan --- cmd/fix.go | 5 ++++- cmd/lint.go | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/cmd/fix.go b/cmd/fix.go index a19aafa9..d5746e45 100644 --- a/cmd/fix.go +++ b/cmd/fix.go @@ -219,7 +219,10 @@ func fix(args []string, params *fixCommandParams) error { log.Printf("found user config file: %s", userConfigFile.Name()) } - if err := yaml.NewDecoder(userConfigFile).Decode(&userConfig); err != nil { + err := yaml.NewDecoder(userConfigFile).Decode(&userConfig) + if errors.Is(err, io.EOF) { + log.Printf("user config file %q is empty, will use the default config", userConfigFile.Name()) + } else if err != nil { if regalDir != nil { return fmt.Errorf("failed to decode user config from %s: %w", regalDir.Name(), err) } diff --git a/cmd/lint.go b/cmd/lint.go index 11ecacbb..af549fb2 100644 --- a/cmd/lint.go +++ b/cmd/lint.go @@ -289,7 +289,10 @@ func lint(args []string, params *lintCommandParams) (report.Report, error) { log.Printf("found user config file: %s", userConfigFile.Name()) } - if err := yaml.NewDecoder(userConfigFile).Decode(&userConfig); err != nil { + err := yaml.NewDecoder(userConfigFile).Decode(&userConfig) + if errors.Is(err, io.EOF) { + log.Printf("user config file %q is empty, will use the default config", userConfigFile.Name()) + } else if err != nil { if regalDir != nil { return report.Report{}, fmt.Errorf("failed to decode user config from %s: %w", regalDir.Name(), err) }