Merge pull request #37695 from thaJeztah/wrap_wrap_wrapper
Use errors.Wrap() in daemon errors, and cleanup messages
This commit is contained in:
commit
0d9d86107d
3 changed files with 15 additions and 15 deletions
|
@ -103,7 +103,7 @@ func (cli *DaemonCli) start(opts *daemonOptions) (err error) {
|
|||
system.InitLCOW(cli.Config.Experimental)
|
||||
|
||||
if err := setDefaultUmask(); err != nil {
|
||||
return fmt.Errorf("Failed to set umask: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
// Create the daemon root before we create ANY other files (PID, or migrate keys)
|
||||
|
@ -119,7 +119,7 @@ func (cli *DaemonCli) start(opts *daemonOptions) (err error) {
|
|||
if cli.Pidfile != "" {
|
||||
pf, err := pidfile.New(cli.Pidfile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error starting daemon: %v", err)
|
||||
return errors.Wrap(err, "failed to start daemon")
|
||||
}
|
||||
defer func() {
|
||||
if err := pf.Remove(); err != nil {
|
||||
|
@ -130,13 +130,13 @@ func (cli *DaemonCli) start(opts *daemonOptions) (err error) {
|
|||
|
||||
serverConfig, err := newAPIServerConfig(cli)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to create API server: %v", err)
|
||||
return errors.Wrap(err, "failed to create API server")
|
||||
}
|
||||
cli.api = apiserver.New(serverConfig)
|
||||
|
||||
hosts, err := loadListeners(cli, serverConfig)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to load listeners: %v", err)
|
||||
return errors.Wrap(err, "failed to load listeners")
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
@ -144,13 +144,13 @@ func (cli *DaemonCli) start(opts *daemonOptions) (err error) {
|
|||
opts, err := cli.getContainerdDaemonOpts()
|
||||
if err != nil {
|
||||
cancel()
|
||||
return fmt.Errorf("Failed to generate containerd options: %v", err)
|
||||
return errors.Wrap(err, "failed to generate containerd options")
|
||||
}
|
||||
|
||||
r, err := supervisor.Start(ctx, filepath.Join(cli.Config.Root, "containerd"), filepath.Join(cli.Config.ExecRoot, "containerd"), opts...)
|
||||
if err != nil {
|
||||
cancel()
|
||||
return fmt.Errorf("Failed to start containerd: %v", err)
|
||||
return errors.Wrap(err, "failed to start containerd")
|
||||
}
|
||||
|
||||
cli.Config.ContainerdAddr = r.Address()
|
||||
|
@ -176,20 +176,20 @@ func (cli *DaemonCli) start(opts *daemonOptions) (err error) {
|
|||
|
||||
d, err := daemon.NewDaemon(ctx, cli.Config, pluginStore)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error starting daemon: %v", err)
|
||||
return errors.Wrap(err, "failed to start daemon")
|
||||
}
|
||||
|
||||
d.StoreHosts(hosts)
|
||||
|
||||
// validate after NewDaemon has restored enabled plugins. Dont change order.
|
||||
if err := validateAuthzPlugins(cli.Config.AuthorizationPlugins, pluginStore); err != nil {
|
||||
return fmt.Errorf("Error validating authorization plugin: %v", err)
|
||||
return errors.Wrap(err, "failed to validate authorization plugin")
|
||||
}
|
||||
|
||||
// TODO: move into startMetricsServer()
|
||||
if cli.Config.MetricsAddress != "" {
|
||||
if !d.HasExperimental() {
|
||||
return fmt.Errorf("metrics-addr is only supported when experimental is enabled")
|
||||
return errors.Wrap(err, "metrics-addr is only supported when experimental is enabled")
|
||||
}
|
||||
if err := startMetricsServer(cli.Config.MetricsAddress); err != nil {
|
||||
return err
|
||||
|
@ -243,7 +243,7 @@ func (cli *DaemonCli) start(opts *daemonOptions) (err error) {
|
|||
cancel()
|
||||
|
||||
if errAPI != nil {
|
||||
return fmt.Errorf("Shutting down due to ServeAPI error: %v", errAPI)
|
||||
return errors.Wrap(errAPI, "shutting down due to ServeAPI error")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -412,14 +412,14 @@ func loadDaemonCliConfig(opts *daemonOptions) (*config.Config, error) {
|
|||
}
|
||||
|
||||
if flags.Changed("graph") && flags.Changed("data-root") {
|
||||
return nil, fmt.Errorf(`cannot specify both "--graph" and "--data-root" option`)
|
||||
return nil, errors.New(`cannot specify both "--graph" and "--data-root" option`)
|
||||
}
|
||||
|
||||
if opts.configFile != "" {
|
||||
c, err := config.MergeDaemonConfigurations(conf, flags, opts.configFile)
|
||||
if err != nil {
|
||||
if flags.Changed("config-file") || !os.IsNotExist(err) {
|
||||
return nil, fmt.Errorf("unable to configure the Docker daemon with file %s: %v", opts.configFile, err)
|
||||
return nil, errors.Wrapf(err, "unable to configure the Docker daemon with file %s", opts.configFile)
|
||||
}
|
||||
}
|
||||
// the merged configuration can be nil if the config file didn't exist.
|
||||
|
@ -592,7 +592,7 @@ func loadListeners(cli *DaemonCli, serverConfig *apiserver.Config) ([]string, er
|
|||
for i := 0; i < len(cli.Config.Hosts); i++ {
|
||||
var err error
|
||||
if cli.Config.Hosts[i], err = dopts.ParseHost(cli.Config.TLS, cli.Config.Hosts[i]); err != nil {
|
||||
return nil, fmt.Errorf("error parsing -H %s : %v", cli.Config.Hosts[i], err)
|
||||
return nil, errors.Wrapf(err, "error parsing -H %s", cli.Config.Hosts[i])
|
||||
}
|
||||
|
||||
protoAddr := cli.Config.Hosts[i]
|
||||
|
|
|
@ -570,7 +570,7 @@ func (s *DockerDaemonSuite) TestDaemonExitOnFailure(c *check.C) {
|
|||
c.Fatalf("Expected daemon not to start, got %v", err)
|
||||
}
|
||||
// look in the log and make sure we got the message that daemon is shutting down
|
||||
icmd.RunCommand("grep", "Error starting daemon", s.d.LogFileName()).Assert(c, icmd.Success)
|
||||
icmd.RunCommand("grep", "failed to start daemon", s.d.LogFileName()).Assert(c, icmd.Success)
|
||||
} else {
|
||||
//if we didn't get an error and the daemon is running, this is a failure
|
||||
c.Fatal("Conflicting options should cause the daemon to error out with a failure")
|
||||
|
|
|
@ -201,7 +201,7 @@ func (d *Daemon) Start(t testingT, args ...string) {
|
|||
ht.Helper()
|
||||
}
|
||||
if err := d.StartWithError(args...); err != nil {
|
||||
t.Fatalf("Error starting daemon with arguments %v : %v", args, err)
|
||||
t.Fatalf("failed to start daemon with arguments %v : %v", args, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue