Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli/config: improve error when failing to parse config file #5567

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func load(configDir string) (*configfile.ConfigFile, error) {
defer file.Close()
err = configFile.LoadFromReader(file)
if err != nil {
err = errors.Wrapf(err, "loading config file: %s: ", filename)
err = errors.Wrapf(err, "parsing config file (%s)", filename)
}
return configFile, err
}
Expand Down
11 changes: 11 additions & 0 deletions cli/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@ func TestEmptyJSON(t *testing.T) {
saveConfigAndValidateNewFormat(t, config, tmpHome)
}

func TestMalformedJSON(t *testing.T) {
tmpHome := t.TempDir()

fn := filepath.Join(tmpHome, ConfigFileName)
err := os.WriteFile(fn, []byte("{"), 0o600)
assert.NilError(t, err)

_, err = Load(tmpHome)
assert.Check(t, is.ErrorContains(err, fmt.Sprintf(`parsing config file (%s):`, fn)))
}

func TestNewJSON(t *testing.T) {
tmpHome := t.TempDir()

Expand Down
Loading