diff --git a/cli/config/config.go b/cli/config/config.go index 90529ebd4c..143436b9ec 100644 --- a/cli/config/config.go +++ b/cli/config/config.go @@ -75,18 +75,18 @@ func Load(configDir string) (*configfile.ConfigFile, error) { if _, err := os.Stat(filename); err == nil { file, err := os.Open(filename) if err != nil { - return configFile, errors.Errorf("%s - %v", filename, err) + return configFile, errors.Wrap(err, filename) } defer file.Close() err = configFile.LoadFromReader(file) if err != nil { - err = errors.Errorf("%s - %v", filename, err) + err = errors.Wrap(err, filename) } 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, errors.Errorf("%s - %v", filename, err) + return configFile, errors.Wrap(err, filename) } // Can't find latest config file so check for the old one @@ -96,12 +96,12 @@ func Load(configDir string) (*configfile.ConfigFile, error) { } file, err := os.Open(confFile) if err != nil { - return configFile, errors.Errorf("%s - %v", confFile, err) + return configFile, errors.Wrap(err, confFile) } defer file.Close() err = configFile.LegacyLoadFromReader(file) if err != nil { - return configFile, errors.Errorf("%s - %v", confFile, err) + return configFile, errors.Wrap(err, confFile) } return configFile, nil } diff --git a/cli/config/config_test.go b/cli/config/config_test.go index 1314abe666..74c441a4b4 100644 --- a/cli/config/config_test.go +++ b/cli/config/config_test.go @@ -2,6 +2,7 @@ package config import ( "bytes" + "io" "io/ioutil" "os" "path/filepath" @@ -13,6 +14,7 @@ import ( "github.com/docker/docker/pkg/homedir" "github.com/gotestyourself/gotestyourself/assert" is "github.com/gotestyourself/gotestyourself/assert/cmp" + "github.com/pkg/errors" ) func setupConfigDir(t *testing.T) (string, func()) { @@ -77,7 +79,8 @@ func TestEmptyFile(t *testing.T) { assert.NilError(t, err) _, err = Load(tmpHome) - assert.ErrorContains(t, err, "EOF") + assert.Equal(t, errors.Cause(err), io.EOF) + assert.ErrorContains(t, err, ConfigFileName) } func TestEmptyJSON(t *testing.T) {