Add the filename to the error message while trying to parse the config file

Notice this while looking at #18634. W/o this extra text we're not sure if
its complaining about the old or new config file.

Signed-off-by: Doug Davis <dug@us.ibm.com>
This commit is contained in:
Doug Davis 2015-12-15 18:24:10 -08:00
Родитель 61a94411b5
Коммит b0a18d57a7
2 изменённых файлов: 12 добавлений и 7 удалений

Просмотреть файл

@ -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 {

Просмотреть файл

@ -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)
}
}