diff --git a/go.mod b/go.mod index e1f59430b5..959c0a2b91 100644 --- a/go.mod +++ b/go.mod @@ -33,7 +33,7 @@ require ( github.com/jpillora/backoff v1.0.0 github.com/json-iterator/go v1.1.12 github.com/kanisterio/errkit v0.0.2 - github.com/kanisterio/safecli v0.0.8 + github.com/kanisterio/safecli v0.0.9-0.20241121134252-2ffd9801dcad github.com/kopia/kopia v0.17.1-0.20240927044625-1bceb7155ede github.com/kubernetes-csi/external-snapshotter/client/v4 v4.2.0 github.com/lib/pq v1.10.9 diff --git a/go.sum b/go.sum index 7512c046b2..8bd11209a6 100644 --- a/go.sum +++ b/go.sum @@ -375,8 +375,8 @@ github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1 github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= github.com/kanisterio/errkit v0.0.2 h1:3v3HGz9lHIbZR6Jr9qIJpRjaqUX0rsJSLMEQGsMHiUk= github.com/kanisterio/errkit v0.0.2/go.mod h1:ViQ6kPJ2gTJDEvRytmwde7pzG9/sndObF9BPZoEZixc= -github.com/kanisterio/safecli v0.0.8 h1:flvTiGksy/a0+zvqjaBSJwxESu/nFcG65yttmR0XwiA= -github.com/kanisterio/safecli v0.0.8/go.mod h1:KBraqj8mdv2cwAr9wecknGUb8jztTzUik0r7uE6yRA8= +github.com/kanisterio/safecli v0.0.9-0.20241121134252-2ffd9801dcad h1:JaC21jpch32i3hfUE3m1So06CvPoi+sdQ2KKIRCRKCo= +github.com/kanisterio/safecli v0.0.9-0.20241121134252-2ffd9801dcad/go.mod h1:y1oYVoT2eqsmySCIS5yOzrxaYVywlMSEdWEKfLhBjgs= github.com/kastenhq/check v0.0.0-20180626002341-0264cfcea734 h1:qulsCaCv+O2y9/sQ9nd5KChnAgFOWakTHQ9ZADjs6DQ= github.com/kastenhq/check v0.0.0-20180626002341-0264cfcea734/go.mod h1:rdqSnvOJuKCPFW/h2rVLuXOAkRnHHdp9PZcKx4HCoDM= github.com/kastenhq/stow v0.2.6-kasten.1.0.20231101232131-9321daa23aae h1:2cl4yuAJpdmLCx7G8eIsfNlQBLEfw0JDj6mTTyqc5qg= diff --git a/pkg/kopia/cli/errors.go b/pkg/kopia/cli/errors.go index 68153212d5..4d08eb48cc 100644 --- a/pkg/kopia/cli/errors.go +++ b/pkg/kopia/cli/errors.go @@ -15,29 +15,29 @@ package cli import ( - "github.com/pkg/errors" + "github.com/kanisterio/errkit" ) // Common errors var ( // ErrInvalidID is returned when the ID is empty. - ErrInvalidID = errors.New("invalid ID") + ErrInvalidID = errkit.NewSentinelErr("invalid ID") ) // storage errors var ( // ErrUnsupportedStorage is returned when the storage is not supported. - ErrUnsupportedStorage = errors.New("unsupported storage") + ErrUnsupportedStorage = errkit.NewSentinelErr("unsupported storage") // ErrInvalidRepoPath is returned when the repoPath is empty. - ErrInvalidRepoPath = errors.New("repository path cannot be empty") + ErrInvalidRepoPath = errkit.NewSentinelErr("repository path cannot be empty") // ErrInvalidPrefix is returned when the prefix is empty. - ErrInvalidPrefix = errors.New("prefix cannot be empty") + ErrInvalidPrefix = errkit.NewSentinelErr("prefix cannot be empty") // ErrInvalidBucketName is returned when the bucketName is empty. - ErrInvalidBucketName = errors.New("bucket name cannot be empty") + ErrInvalidBucketName = errkit.NewSentinelErr("bucket name cannot be empty") // ErrInvalidCredentialsFile is returned when the credentials file is empty. - ErrInvalidCredentialsFile = errors.New("credentials file cannot be empty") + ErrInvalidCredentialsFile = errkit.NewSentinelErr("credentials file cannot be empty") // ErrInvalidContainerName is returned when the containerName is empty. - ErrInvalidContainerName = errors.New("container name cannot be empty") + ErrInvalidContainerName = errkit.NewSentinelErr("container name cannot be empty") // ErrInvalidServerURL is returned when the serverURL is empty. - ErrInvalidServerURL = errors.New("server URL cannot be empty") + ErrInvalidServerURL = errkit.NewSentinelErr("server URL cannot be empty") ) diff --git a/pkg/kopia/cli/internal/test/command_suite.go b/pkg/kopia/cli/internal/test/command_suite.go index 57a8c2f96d..660909dc6d 100644 --- a/pkg/kopia/cli/internal/test/command_suite.go +++ b/pkg/kopia/cli/internal/test/command_suite.go @@ -15,9 +15,9 @@ package test import ( + "github.com/kanisterio/errkit" "github.com/kanisterio/safecli" "github.com/kanisterio/safecli/test" - "github.com/pkg/errors" "gopkg.in/check.v1" ) @@ -62,8 +62,7 @@ func (t *CommandTest) assertNoError(c *check.C, err error) { // assertError checks the error against ExpectedErr. func (t *CommandTest) assertError(c *check.C, err error) { - actualErr := errors.Cause(err) - c.Assert(actualErr, check.Equals, t.ExpectedErr) + c.Assert(errkit.Is(err, t.ExpectedErr), check.Equals, true) } // assertCLI asserts the builder's CLI output against ExpectedCLI. diff --git a/pkg/kopia/cli/repository/opts.go b/pkg/kopia/cli/repository/opts.go index 31c92ab0e5..fd05a901ca 100644 --- a/pkg/kopia/cli/repository/opts.go +++ b/pkg/kopia/cli/repository/opts.go @@ -15,11 +15,12 @@ package repository import ( + "fmt" "time" "github.com/go-openapi/strfmt" + "github.com/kanisterio/errkit" "github.com/kanisterio/safecli/command" - "github.com/pkg/errors" "github.com/kanisterio/kanister/pkg/kopia/cli" "github.com/kanisterio/kanister/pkg/kopia/cli/internal" @@ -91,7 +92,7 @@ func optStorage(l internal.Location, repoPathPrefix string, logger log.Logger) c } func errUnsupportedStorageType(t rs.LocType) command.Applier { - err := errors.Wrapf(cli.ErrUnsupportedStorage, "storage location: %v", t) + err := errkit.Wrap(cli.ErrUnsupportedStorage, fmt.Sprintf("storage location: %v", t)) return command.NewErrorArgument(err) } diff --git a/pkg/kopia/errors/utils_test.go b/pkg/kopia/errors/utils_test.go index e4370f0406..7ef1debfd9 100644 --- a/pkg/kopia/errors/utils_test.go +++ b/pkg/kopia/errors/utils_test.go @@ -18,7 +18,6 @@ import ( "testing" "github.com/kanisterio/errkit" - "github.com/pkg/errors" "gopkg.in/check.v1" ) @@ -31,17 +30,14 @@ var _ = check.Suite(&KopiaErrorsTestSuite{}) // TestErrCheck verifies that error types are properly detected after wrapping them func (s *KopiaErrorsTestSuite) TestErrCheck(c *check.C) { - origErr := errors.New("Some error") + origErr := errkit.New("Some error") - errWithMessage := errors.WithMessage(origErr, ErrInvalidPasswordStr) errWrapped := errkit.Wrap(origErr, ErrInvalidPasswordStr) - c.Assert(IsInvalidPasswordError(errWithMessage), check.Equals, true) c.Assert(IsInvalidPasswordError(errWrapped), check.Equals, true) c.Assert(IsRepoNotFoundError(errWrapped), check.Equals, false) permittedErrors := []ErrorType{ErrorInvalidPassword, ErrorRepoNotFound} - c.Assert(CheckKopiaErrors(errWithMessage, permittedErrors), check.Equals, true) c.Assert(CheckKopiaErrors(errWrapped, permittedErrors), check.Equals, true) wrongErrors := []ErrorType{ErrorRepoNotFound}