소스 검색

plugin: use pkg/errors in more places

Also provide stack trace output in daemon logs.

Signed-off-by: Tibor Vass <tibor@docker.com>
Tibor Vass 8 년 전
부모
커밋
26d0bac895
4개의 변경된 파일9개의 추가작업 그리고 9개의 파일을 삭제
  1. 1 1
      api/server/server.go
  2. 1 1
      plugin/manager.go
  3. 4 4
      plugin/manager_linux.go
  4. 3 3
      plugin/v2/plugin_linux.go

+ 1 - 1
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 {
 		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)
 			httputils.MakeErrorHandler(err)(w, r)
 		}
 		}
 	}
 	}

+ 1 - 1
plugin/manager.go

@@ -237,7 +237,7 @@ func (pm *Manager) save(p *v2.Plugin) error {
 		return errors.Wrap(err, "failed to marshal plugin json")
 		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 {
 	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
 	return nil
 }
 }

+ 4 - 4
plugin/manager_linux.go

@@ -42,12 +42,12 @@ func (pm *Manager) enable(p *v2.Plugin, c *controller, force bool) error {
 
 
 	if p.PropagatedMount != "" {
 	if p.PropagatedMount != "" {
 		if err := mount.MakeRShared(p.PropagatedMount); err != nil {
 		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 {
 	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 {
 	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)
 				logrus.Warnf("Could not unmount %s: %v", p.PropagatedMount, err)
 			}
 			}
 		}
 		}
-		return err
+		return errors.WithStack(err)
 	}
 	}
 
 
 	return pm.pluginPostStart(p, c)
 	return pm.pluginPostStart(p, c)
@@ -67,7 +67,7 @@ func (pm *Manager) pluginPostStart(p *v2.Plugin, c *controller) error {
 	if err != nil {
 	if err != nil {
 		c.restart = false
 		c.restart = false
 		shutdownPlugin(p, c, pm.containerdClient)
 		shutdownPlugin(p, c, pm.containerdClient)
-		return err
+		return errors.WithStack(err)
 	}
 	}
 
 
 	p.SetPClient(client)
 	p.SetPClient(client)

+ 3 - 3
plugin/v2/plugin_linux.go

@@ -3,7 +3,6 @@
 package v2
 package v2
 
 
 import (
 import (
-	"errors"
 	"os"
 	"os"
 	"path/filepath"
 	"path/filepath"
 	"strings"
 	"strings"
@@ -12,6 +11,7 @@ import (
 	"github.com/docker/docker/oci"
 	"github.com/docker/docker/oci"
 	"github.com/docker/docker/pkg/system"
 	"github.com/docker/docker/pkg/system"
 	specs "github.com/opencontainers/runtime-spec/specs-go"
 	specs "github.com/opencontainers/runtime-spec/specs-go"
+	"github.com/pkg/errors"
 )
 )
 
 
 // InitSpec creates an OCI spec from the plugin's config.
 // 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)
 	execRoot = filepath.Join(execRoot, p.PluginObj.ID)
 	if err := os.MkdirAll(execRoot, 0700); err != nil {
 	if err := os.MkdirAll(execRoot, 0700); err != nil {
-		return nil, err
+		return nil, errors.WithStack(err)
 	}
 	}
 
 
 	mounts := append(p.PluginObj.Config.Mounts, types.PluginMount{
 	mounts := append(p.PluginObj.Config.Mounts, types.PluginMount{
@@ -95,7 +95,7 @@ func (p *Plugin) InitSpec(execRoot string) (*specs.Spec, error) {
 		path := *dev.Path
 		path := *dev.Path
 		d, dPermissions, err := oci.DevicesFromPath(path, path, "rwm")
 		d, dPermissions, err := oci.DevicesFromPath(path, path, "rwm")
 		if err != nil {
 		if err != nil {
-			return nil, err
+			return nil, errors.WithStack(err)
 		}
 		}
 		s.Linux.Devices = append(s.Linux.Devices, d...)
 		s.Linux.Devices = append(s.Linux.Devices, d...)
 		s.Linux.Resources.Devices = append(s.Linux.Resources.Devices, dPermissions...)
 		s.Linux.Resources.Devices = append(s.Linux.Resources.Devices, dPermissions...)