From f69cfc41a2f1212182af8f2e239d11ef3ac03dac Mon Sep 17 00:00:00 2001 From: Daniel Canter Date: Thu, 14 Jan 2021 08:20:22 -0800 Subject: [PATCH] Wrap errors from computestorage package * Change from stringifying errors with fmt.Errorf to errors.Wrap everywhere Fixes: https://github.com/microsoft/hcsshim/issues/924 Signed-off-by: Daniel Canter --- computestorage/attach.go | 4 ++-- computestorage/destroy.go | 4 ++-- computestorage/detach.go | 4 ++-- computestorage/export.go | 4 ++-- computestorage/format.go | 4 ++-- computestorage/import.go | 4 ++-- computestorage/initialize.go | 4 ++-- computestorage/mount.go | 4 ++-- computestorage/setup.go | 7 +++---- 9 files changed, 19 insertions(+), 20 deletions(-) diff --git a/computestorage/attach.go b/computestorage/attach.go index 56901d926f..dcc61347c5 100644 --- a/computestorage/attach.go +++ b/computestorage/attach.go @@ -3,9 +3,9 @@ package computestorage import ( "context" "encoding/json" - "fmt" "github.com/Microsoft/hcsshim/internal/oc" + "github.com/pkg/errors" "go.opencensus.io/trace" ) @@ -32,7 +32,7 @@ func AttachLayerStorageFilter(ctx context.Context, layerPath string, layerData L err = hcsAttachLayerStorageFilter(layerPath, string(bytes)) if err != nil { - return fmt.Errorf("failed to attach layer storage filter: %s", err) + return errors.Wrap(err, "failed to attach layer storage filter") } return nil } diff --git a/computestorage/destroy.go b/computestorage/destroy.go index ecf3b550d5..39a9ba3812 100644 --- a/computestorage/destroy.go +++ b/computestorage/destroy.go @@ -2,9 +2,9 @@ package computestorage import ( "context" - "fmt" "github.com/Microsoft/hcsshim/internal/oc" + "github.com/pkg/errors" "go.opencensus.io/trace" ) @@ -20,7 +20,7 @@ func DestroyLayer(ctx context.Context, layerPath string) (err error) { err = hcsDestroyLayer(layerPath) if err != nil { - return fmt.Errorf("failed to destroy layer: %s", err) + return errors.Wrap(err, "failed to destroy layer") } return nil } diff --git a/computestorage/detach.go b/computestorage/detach.go index 2a4df4213f..9c144c066b 100644 --- a/computestorage/detach.go +++ b/computestorage/detach.go @@ -2,9 +2,9 @@ package computestorage import ( "context" - "fmt" "github.com/Microsoft/hcsshim/internal/oc" + "github.com/pkg/errors" "go.opencensus.io/trace" ) @@ -20,7 +20,7 @@ func DetachLayerStorageFilter(ctx context.Context, layerPath string) (err error) err = hcsDetachLayerStorageFilter(layerPath) if err != nil { - return fmt.Errorf("failed to detach layer storage filter: %s", err) + return errors.Wrap(err, "failed to detach layer storage filter") } return nil } diff --git a/computestorage/export.go b/computestorage/export.go index b1721ef25e..649b2602ae 100644 --- a/computestorage/export.go +++ b/computestorage/export.go @@ -3,9 +3,9 @@ package computestorage import ( "context" "encoding/json" - "fmt" "github.com/Microsoft/hcsshim/internal/oc" + "github.com/pkg/errors" "go.opencensus.io/trace" ) @@ -40,7 +40,7 @@ func ExportLayer(ctx context.Context, layerPath, exportFolderPath string, layerD err = hcsExportLayer(layerPath, exportFolderPath, string(ldbytes), string(obytes)) if err != nil { - return fmt.Errorf("failed to export layer: %s", err) + return errors.Wrap(err, "failed to export layer") } return nil } diff --git a/computestorage/format.go b/computestorage/format.go index 2952c8a667..fe0861d2a0 100644 --- a/computestorage/format.go +++ b/computestorage/format.go @@ -2,9 +2,9 @@ package computestorage import ( "context" - "fmt" "github.com/Microsoft/hcsshim/internal/oc" + "github.com/pkg/errors" "go.opencensus.io/trace" "golang.org/x/sys/windows" ) @@ -20,7 +20,7 @@ func FormatWritableLayerVhd(ctx context.Context, vhdHandle windows.Handle) (err err = hcsFormatWritableLayerVhd(vhdHandle) if err != nil { - return fmt.Errorf("failed to format writable layer vhd: %s", err) + return errors.Wrap(err, "failed to format writable layer vhd") } return nil } diff --git a/computestorage/import.go b/computestorage/import.go index 06e3297946..8ad2b085cb 100644 --- a/computestorage/import.go +++ b/computestorage/import.go @@ -3,9 +3,9 @@ package computestorage import ( "context" "encoding/json" - "fmt" "github.com/Microsoft/hcsshim/internal/oc" + "github.com/pkg/errors" "go.opencensus.io/trace" ) @@ -35,7 +35,7 @@ func ImportLayer(ctx context.Context, layerPath, sourceFolderPath string, layerD err = hcsImportLayer(layerPath, sourceFolderPath, string(bytes)) if err != nil { - return fmt.Errorf("failed to import layer: %s", err) + return errors.Wrap(err, "failed to import layer") } return nil } diff --git a/computestorage/initialize.go b/computestorage/initialize.go index 2e4810c457..a50afd821e 100644 --- a/computestorage/initialize.go +++ b/computestorage/initialize.go @@ -3,9 +3,9 @@ package computestorage import ( "context" "encoding/json" - "fmt" "github.com/Microsoft/hcsshim/internal/oc" + "github.com/pkg/errors" "go.opencensus.io/trace" ) @@ -32,7 +32,7 @@ func InitializeWritableLayer(ctx context.Context, layerPath string, layerData La // Options are not used in the platform as of RS5 err = hcsInitializeWritableLayer(layerPath, string(bytes), "") if err != nil { - return fmt.Errorf("failed to intitialize container layer: %s", err) + return errors.Wrap(err, "failed to intitialize container layer") } return nil } diff --git a/computestorage/mount.go b/computestorage/mount.go index 40652b99e4..1c16ff4094 100644 --- a/computestorage/mount.go +++ b/computestorage/mount.go @@ -2,10 +2,10 @@ package computestorage import ( "context" - "fmt" "github.com/Microsoft/hcsshim/internal/interop" "github.com/Microsoft/hcsshim/internal/oc" + "github.com/pkg/errors" "go.opencensus.io/trace" "golang.org/x/sys/windows" ) @@ -20,7 +20,7 @@ func GetLayerVhdMountPath(ctx context.Context, vhdHandle windows.Handle) (path s var mountPath *uint16 err = hcsGetLayerVhdMountPath(vhdHandle, &mountPath) if err != nil { - return "", fmt.Errorf("failed to get vhd mount path: %s", err) + return "", errors.Wrap(err, "failed to get vhd mount path") } path = interop.ConvertAndFreeCoTaskMemString(mountPath) return path, nil diff --git a/computestorage/setup.go b/computestorage/setup.go index 13ce0cd606..7506709ca6 100644 --- a/computestorage/setup.go +++ b/computestorage/setup.go @@ -3,11 +3,10 @@ package computestorage import ( "context" "encoding/json" - "errors" - "fmt" "github.com/Microsoft/hcsshim/internal/oc" "github.com/Microsoft/hcsshim/osversion" + "github.com/pkg/errors" "go.opencensus.io/trace" "golang.org/x/sys/windows" ) @@ -37,7 +36,7 @@ func SetupBaseOSLayer(ctx context.Context, layerPath string, vhdHandle windows.H err = hcsSetupBaseOSLayer(layerPath, vhdHandle, string(bytes)) if err != nil { - return fmt.Errorf("failed to setup base OS layer: %s", err) + return errors.Wrap(err, "failed to setup base OS layer") } return nil } @@ -69,7 +68,7 @@ func SetupBaseOSVolume(ctx context.Context, layerPath, volumePath string, option err = hcsSetupBaseOSVolume(layerPath, volumePath, string(bytes)) if err != nil { - return fmt.Errorf("failed to setup base OS layer: %s", err) + return errors.Wrap(err, "failed to setup base OS layer") } return nil }