From 26d0bac8955903bc3a845358d159b2ec2f7c253f Mon Sep 17 00:00:00 2001 From: Tibor Vass Date: Tue, 17 Jan 2017 10:27:01 -0800 Subject: [PATCH] plugin: use pkg/errors in more places Also provide stack trace output in daemon logs. Signed-off-by: Tibor Vass --- api/server/server.go | 2 +- plugin/manager.go | 2 +- plugin/manager_linux.go | 8 ++++---- plugin/v2/plugin_linux.go | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/api/server/server.go b/api/server/server.go index d8b716e100..0bf33329d0 100644 --- a/api/server/server.go +++ b/api/server/server.go @@ -138,7 +138,7 @@ func (s *Server) makeHTTPHandler(handler httputils.APIFunc) http.HandlerFunc { } if err := handlerFunc(ctx, w, r, vars); err != nil { - logrus.Errorf("Handler for %s %s returned error: %v", r.Method, r.URL.Path, err) + logrus.Errorf("Handler for %s %s returned error: %+v", r.Method, r.URL.Path, err) httputils.MakeErrorHandler(err)(w, r) } } diff --git a/plugin/manager.go b/plugin/manager.go index 3126097250..a25b254a4a 100644 --- a/plugin/manager.go +++ b/plugin/manager.go @@ -237,7 +237,7 @@ func (pm *Manager) save(p *v2.Plugin) error { return errors.Wrap(err, "failed to marshal plugin json") } if err := ioutils.AtomicWriteFile(filepath.Join(pm.config.Root, p.GetID(), configFileName), pluginJSON, 0600); err != nil { - return err + return errors.Wrap(err, "failed to write atomically plugin json") } return nil } diff --git a/plugin/manager_linux.go b/plugin/manager_linux.go index ef91ce3120..458b6c4a26 100644 --- a/plugin/manager_linux.go +++ b/plugin/manager_linux.go @@ -42,12 +42,12 @@ func (pm *Manager) enable(p *v2.Plugin, c *controller, force bool) error { if p.PropagatedMount != "" { if err := mount.MakeRShared(p.PropagatedMount); err != nil { - return err + return errors.WithStack(err) } } if err := initlayer.Setup(filepath.Join(pm.config.Root, p.PluginObj.ID, rootFSFileName), 0, 0); err != nil { - return err + return errors.WithStack(err) } if err := pm.containerdClient.Create(p.GetID(), "", "", specs.Spec(*spec), attachToLog(p.GetID())); err != nil { @@ -56,7 +56,7 @@ func (pm *Manager) enable(p *v2.Plugin, c *controller, force bool) error { logrus.Warnf("Could not unmount %s: %v", p.PropagatedMount, err) } } - return err + return errors.WithStack(err) } return pm.pluginPostStart(p, c) @@ -67,7 +67,7 @@ func (pm *Manager) pluginPostStart(p *v2.Plugin, c *controller) error { if err != nil { c.restart = false shutdownPlugin(p, c, pm.containerdClient) - return err + return errors.WithStack(err) } p.SetPClient(client) diff --git a/plugin/v2/plugin_linux.go b/plugin/v2/plugin_linux.go index f1c2da0bc7..e980e7f29a 100644 --- a/plugin/v2/plugin_linux.go +++ b/plugin/v2/plugin_linux.go @@ -3,7 +3,6 @@ package v2 import ( - "errors" "os" "path/filepath" "strings" @@ -12,6 +11,7 @@ import ( "github.com/docker/docker/oci" "github.com/docker/docker/pkg/system" specs "github.com/opencontainers/runtime-spec/specs-go" + "github.com/pkg/errors" ) // InitSpec creates an OCI spec from the plugin's config. @@ -29,7 +29,7 @@ func (p *Plugin) InitSpec(execRoot string) (*specs.Spec, error) { execRoot = filepath.Join(execRoot, p.PluginObj.ID) if err := os.MkdirAll(execRoot, 0700); err != nil { - return nil, err + return nil, errors.WithStack(err) } mounts := append(p.PluginObj.Config.Mounts, types.PluginMount{ @@ -95,7 +95,7 @@ func (p *Plugin) InitSpec(execRoot string) (*specs.Spec, error) { path := *dev.Path d, dPermissions, err := oci.DevicesFromPath(path, path, "rwm") if err != nil { - return nil, err + return nil, errors.WithStack(err) } s.Linux.Devices = append(s.Linux.Devices, d...) s.Linux.Resources.Devices = append(s.Linux.Resources.Devices, dPermissions...)