From 831d7fb0d7ee007fc04b1b0ff24b77c7d5635f5e Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Wed, 28 Oct 2020 13:16:42 -0400 Subject: Stop excessive wrapping of errors Most of the builtin golang functions like os.Stat and os.Open report errors including the file system object path. We should not wrap these errors and put the file path in a second time, causing stuttering of errors when they get presented to the user. This patch tries to cleanup a bunch of these errors. Signed-off-by: Daniel J Walsh --- pkg/domain/infra/abi/cp.go | 6 +++--- pkg/domain/infra/abi/play.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'pkg/domain') diff --git a/pkg/domain/infra/abi/cp.go b/pkg/domain/infra/abi/cp.go index ab90c8183..8f4f5d3d7 100644 --- a/pkg/domain/infra/abi/cp.go +++ b/pkg/domain/infra/abi/cp.go @@ -214,7 +214,7 @@ func getPathInfo(path string) (string, os.FileInfo, error) { } srcfi, err := os.Stat(path) if err != nil { - return "", nil, errors.Wrapf(err, "error reading path %q", path) + return "", nil, err } return path, srcfi, nil } @@ -245,7 +245,7 @@ func containerCopy(srcPath, destPath, src, dest string, idMappingOpts storage.ID } _, err = os.Stat(destdir) if err != nil && !os.IsNotExist(err) { - return errors.Wrapf(err, "error checking directory %q", destdir) + return err } destDirIsExist := err == nil if err = os.MkdirAll(destdir, 0755); err != nil { @@ -292,7 +292,7 @@ func containerCopy(srcPath, destPath, src, dest string, idMappingOpts storage.ID destfi, err := os.Stat(destPath) if err != nil { if !os.IsNotExist(err) || strings.HasSuffix(dest, string(os.PathSeparator)) { - return errors.Wrapf(err, "failed to get stat of dest path %s", destPath) + return err } } if destfi != nil && destfi.IsDir() { diff --git a/pkg/domain/infra/abi/play.go b/pkg/domain/infra/abi/play.go index 348570a20..57de0f3b1 100644 --- a/pkg/domain/infra/abi/play.go +++ b/pkg/domain/infra/abi/play.go @@ -251,7 +251,7 @@ func (ic *ContainerEngine) playKubePod(ctx context.Context, podName string, podY case v1.HostPathDirectoryOrCreate: if _, err := os.Stat(hostPath.Path); os.IsNotExist(err) { if err := os.Mkdir(hostPath.Path, kubeDirectoryPermission); err != nil { - return nil, errors.Errorf("error creating HostPath %s", volume.Name) + return nil, err } } // Label a newly created volume @@ -262,7 +262,7 @@ func (ic *ContainerEngine) playKubePod(ctx context.Context, podName string, podY if _, err := os.Stat(hostPath.Path); os.IsNotExist(err) { f, err := os.OpenFile(hostPath.Path, os.O_RDONLY|os.O_CREATE, kubeFilePermission) if err != nil { - return nil, errors.Errorf("error creating HostPath %s", volume.Name) + return nil, errors.Wrap(err, "error creating HostPath") } if err := f.Close(); err != nil { logrus.Warnf("Error in closing newly created HostPath file: %v", err) -- cgit v1.2.3-54-g00ecf