Skip to content

Commit

Permalink
Migrate remaining piece of pkg/kopia to errkit
Browse files Browse the repository at this point in the history
Signed-off-by: Eugen Sumin <[email protected]>
  • Loading branch information
e-sumin committed Nov 25, 2024
1 parent 5c7ac49 commit dbf761d
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 22 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
18 changes: 9 additions & 9 deletions pkg/kopia/cli/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
5 changes: 2 additions & 3 deletions pkg/kopia/cli/internal/test/command_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions pkg/kopia/cli/repository/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}

Expand Down
6 changes: 1 addition & 5 deletions pkg/kopia/errors/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"testing"

"github.com/kanisterio/errkit"
"github.com/pkg/errors"
"gopkg.in/check.v1"
)

Expand All @@ -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}
Expand Down

0 comments on commit dbf761d

Please sign in to comment.