1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

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
parent 61a94411b5
commit b0a18d57a7
2 changed files with 12 additions and 7 deletions

View file

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

View file

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