diff --git a/cliconfig/config.go b/cliconfig/config.go index d3d109d122..e4ea948768 100644 --- a/cliconfig/config.go +++ b/cliconfig/config.go @@ -161,15 +161,18 @@ func Load(configDir string) (*ConfigFile, error) { if _, err := os.Stat(configFile.filename); err == nil { file, err := os.Open(configFile.filename) if err != nil { - return &configFile, err + return &configFile, fmt.Errorf("%s - %v", configFile.filename, err) } defer file.Close() err = configFile.LoadFromReader(file) + if err != nil { + err = fmt.Errorf("%s - %v", configFile.filename, err) + } return &configFile, err } else if !os.IsNotExist(err) { // if file is there but we can't stat it for any reason other // than it doesn't exist then stop - return &configFile, err + return &configFile, fmt.Errorf("%s - %v", configFile.filename, err) } // Can't find latest config file so check for the old one @@ -179,12 +182,12 @@ func Load(configDir string) (*ConfigFile, error) { } file, err := os.Open(confFile) if err != nil { - return &configFile, err + return &configFile, fmt.Errorf("%s - %v", confFile, err) } defer file.Close() err = configFile.LegacyLoadFromReader(file) if err != nil { - return &configFile, err + return &configFile, fmt.Errorf("%s - %v", confFile, err) } if configFile.HTTPHeaders == nil { diff --git a/cliconfig/config_test.go b/cliconfig/config_test.go index b6c8160001..147f5adbd6 100644 --- a/cliconfig/config_test.go +++ b/cliconfig/config_test.go @@ -138,8 +138,9 @@ email`: "Invalid Auth config file", } config, err := Load(tmpHome) - if err == nil || err.Error() != expectedError { - t.Fatalf("Should have failed, got: %q, %q", config, err) + // Use Contains instead of == since the file name will change each time + if err == nil || !strings.Contains(err.Error(), expectedError) { + t.Fatalf("Should have failed\nConfig: %v\nGot: %v\nExpected: %v", config, err, expectedError) } } @@ -207,7 +208,8 @@ func TestOldJsonInvalid(t *testing.T) { } config, err := Load(tmpHome) - if err == nil || err.Error() != "Invalid auth configuration file" { + // Use Contains instead of == since the file name will change each time + if err == nil || !strings.Contains(err.Error(), "Invalid auth configuration file") { t.Fatalf("Expected an error got : %v, %v", config, err) } }