Skip to content

Commit c34b80b

Browse files
authored
Merge pull request #5567 from thaJeztah/config_fix_err
cli/config: improve error when failing to parse config file
2 parents ea511f0 + d96f8b7 commit c34b80b

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

cli/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func load(configDir string) (*configfile.ConfigFile, error) {
143143
defer file.Close()
144144
err = configFile.LoadFromReader(file)
145145
if err != nil {
146-
err = errors.Wrapf(err, "loading config file: %s: ", filename)
146+
err = errors.Wrapf(err, "parsing config file (%s)", filename)
147147
}
148148
return configFile, err
149149
}

cli/config/config_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,17 @@ func TestEmptyJSON(t *testing.T) {
118118
saveConfigAndValidateNewFormat(t, config, tmpHome)
119119
}
120120

121+
func TestMalformedJSON(t *testing.T) {
122+
tmpHome := t.TempDir()
123+
124+
fn := filepath.Join(tmpHome, ConfigFileName)
125+
err := os.WriteFile(fn, []byte("{"), 0o600)
126+
assert.NilError(t, err)
127+
128+
_, err = Load(tmpHome)
129+
assert.Check(t, is.ErrorContains(err, fmt.Sprintf(`parsing config file (%s):`, fn)))
130+
}
131+
121132
func TestNewJSON(t *testing.T) {
122133
tmpHome := t.TempDir()
123134

0 commit comments

Comments
 (0)