using `errors.Wrap()` preserves the original error
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -3,7 +3,6 @@ package config // import "github.com/docker/docker/daemon/config" |
| 3 | 3 |
import ( |
| 4 | 4 |
"bytes" |
| 5 | 5 |
"encoding/json" |
| 6 |
- "errors" |
|
| 7 | 6 |
"fmt" |
| 8 | 7 |
"io" |
| 9 | 8 |
"io/ioutil" |
| ... | ... |
@@ -19,6 +18,7 @@ import ( |
| 19 | 19 |
"github.com/docker/docker/pkg/discovery" |
| 20 | 20 |
"github.com/docker/docker/registry" |
| 21 | 21 |
"github.com/imdario/mergo" |
| 22 |
+ "github.com/pkg/errors" |
|
| 22 | 23 |
"github.com/sirupsen/logrus" |
| 23 | 24 |
"github.com/spf13/pflag" |
| 24 | 25 |
) |
| ... | ... |
@@ -264,7 +264,7 @@ func ParseClusterAdvertiseSettings(clusterStore, clusterAdvertise string) (strin |
| 264 | 264 |
|
| 265 | 265 |
advertise, err := discovery.ParseAdvertise(clusterAdvertise) |
| 266 | 266 |
if err != nil {
|
| 267 |
- return "", fmt.Errorf("discovery advertise parsing failed (%v)", err)
|
|
| 267 |
+ return "", errors.Wrap(err, "discovery advertise parsing failed") |
|
| 268 | 268 |
} |
| 269 | 269 |
return advertise, nil |
| 270 | 270 |
} |
| ... | ... |
@@ -318,13 +318,13 @@ func Reload(configFile string, flags *pflag.FlagSet, reload func(*Config)) error |
| 318 | 318 |
newConfig, err := getConflictFreeConfiguration(configFile, flags) |
| 319 | 319 |
if err != nil {
|
| 320 | 320 |
if flags.Changed("config-file") || !os.IsNotExist(err) {
|
| 321 |
- return fmt.Errorf("unable to configure the Docker daemon with file %s: %v", configFile, err)
|
|
| 321 |
+ return errors.Wrapf(err, "unable to configure the Docker daemon with file %s", configFile) |
|
| 322 | 322 |
} |
| 323 | 323 |
newConfig = New() |
| 324 | 324 |
} |
| 325 | 325 |
|
| 326 | 326 |
if err := Validate(newConfig); err != nil {
|
| 327 |
- return fmt.Errorf("file configuration validation failed (%v)", err)
|
|
| 327 |
+ return errors.Wrap(err, "file configuration validation failed") |
|
| 328 | 328 |
} |
| 329 | 329 |
|
| 330 | 330 |
// Check if duplicate label-keys with different values are found |
| ... | ... |
@@ -355,7 +355,7 @@ func MergeDaemonConfigurations(flagsConfig *Config, flags *pflag.FlagSet, config |
| 355 | 355 |
} |
| 356 | 356 |
|
| 357 | 357 |
if err := Validate(fileConfig); err != nil {
|
| 358 |
- return nil, fmt.Errorf("configuration validation from file failed (%v)", err)
|
|
| 358 |
+ return nil, errors.Wrap(err, "configuration validation from file failed") |
|
| 359 | 359 |
} |
| 360 | 360 |
|
| 361 | 361 |
// merge flags configuration on top of the file configuration |
| ... | ... |
@@ -366,7 +366,7 @@ func MergeDaemonConfigurations(flagsConfig *Config, flags *pflag.FlagSet, config |
| 366 | 366 |
// We need to validate again once both fileConfig and flagsConfig |
| 367 | 367 |
// have been merged |
| 368 | 368 |
if err := Validate(fileConfig); err != nil {
|
| 369 |
- return nil, fmt.Errorf("merged configuration validation from file and command line flags failed (%v)", err)
|
|
| 369 |
+ return nil, errors.Wrap(err, "merged configuration validation from file and command line flags failed") |
|
| 370 | 370 |
} |
| 371 | 371 |
|
| 372 | 372 |
return fileConfig, nil |
| ... | ... |
@@ -438,7 +438,7 @@ func getConflictFreeConfiguration(configFile string, flags *pflag.FlagSet) (*Con |
| 438 | 438 |
logrus.Warn(`The "graph" config file option is deprecated. Please use "data-root" instead.`) |
| 439 | 439 |
|
| 440 | 440 |
if config.Root != "" {
|
| 441 |
- return nil, fmt.Errorf(`cannot specify both "graph" and "data-root" config file options`) |
|
| 441 |
+ return nil, errors.New(`cannot specify both "graph" and "data-root" config file options`) |
|
| 442 | 442 |
} |
| 443 | 443 |
|
| 444 | 444 |
config.Root = config.RootDeprecated |
| ... | ... |
@@ -2485,7 +2485,7 @@ func (s *DockerDaemonSuite) TestRunWithRuntimeFromConfigFile(c *check.C) {
|
| 2485 | 2485 |
|
| 2486 | 2486 |
content, err := s.d.ReadLogFile() |
| 2487 | 2487 |
c.Assert(err, checker.IsNil) |
| 2488 |
- c.Assert(string(content), checker.Contains, `file configuration validation failed (runtime name 'runc' is reserved)`) |
|
| 2488 |
+ c.Assert(string(content), checker.Contains, `file configuration validation failed: runtime name 'runc' is reserved`) |
|
| 2489 | 2489 |
|
| 2490 | 2490 |
// Check that we can select a default runtime |
| 2491 | 2491 |
config = ` |