Merge pull request #5567 from thaJeztah/config_fix_err

cli/config: improve error when failing to parse config file
This commit is contained in:
Sebastiaan van Stijn 2024-10-22 14:05:45 +02:00 committed by GitHub
commit c34b80bc65
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 1 deletions

View File

@ -143,7 +143,7 @@ func load(configDir string) (*configfile.ConfigFile, error) {
defer file.Close() defer file.Close()
err = configFile.LoadFromReader(file) err = configFile.LoadFromReader(file)
if err != nil { if err != nil {
err = errors.Wrapf(err, "loading config file: %s: ", filename) err = errors.Wrapf(err, "parsing config file (%s)", filename)
} }
return configFile, err return configFile, err
} }

View File

@ -118,6 +118,17 @@ func TestEmptyJSON(t *testing.T) {
saveConfigAndValidateNewFormat(t, config, tmpHome) 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) { func TestNewJSON(t *testing.T) {
tmpHome := t.TempDir() tmpHome := t.TempDir()