diff --git a/command/arg_test.go b/command/arg_test.go index 54b61b3..f3f471c 100644 --- a/command/arg_test.go +++ b/command/arg_test.go @@ -19,15 +19,14 @@ import ( "gopkg.in/check.v1" - "github.com/pkg/errors" - + "github.com/kanisterio/errkit" "github.com/kanisterio/safecli" "github.com/kanisterio/safecli/command" "github.com/kanisterio/safecli/test" ) var ( - ErrArgument = errors.New("arg error") + ErrArgument = errkit.NewSentinelErr("arg error") ) // MockArg is a mock implementation of the Applier interface. diff --git a/command/errors.go b/command/errors.go index f703add..93deef7 100644 --- a/command/errors.go +++ b/command/errors.go @@ -15,12 +15,12 @@ package command import ( - "github.com/pkg/errors" + "github.com/kanisterio/errkit" ) var ( // ErrInvalidArgumentName is returned when the argument name is empty. - ErrInvalidArgumentName = errors.New("argument name is empty") + ErrInvalidArgumentName = errkit.NewSentinelErr("argument name is empty") // ErrInvalidOptionName is returned when the option name is empty or has no hyphen prefix. - ErrInvalidOptionName = errors.New("option name is empty or has no hyphen prefix") + ErrInvalidOptionName = errkit.NewSentinelErr("option name is empty or has no hyphen prefix") ) diff --git a/go.mod b/go.mod index d2fc0dc..82c4bf9 100644 --- a/go.mod +++ b/go.mod @@ -1,13 +1,16 @@ module github.com/kanisterio/safecli -go 1.20 +go 1.21.0 + +toolchain go1.22.4 require ( - github.com/pkg/errors v0.9.1 + github.com/kanisterio/errkit v0.0.2 gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c ) require ( - github.com/kr/pretty v0.2.1 // indirect - github.com/kr/text v0.1.0 // indirect + github.com/kr/pretty v0.3.1 // indirect + github.com/kr/text v0.2.0 // indirect + github.com/rogpeppe/go-internal v1.9.0 // indirect ) diff --git a/go.sum b/go.sum index 411a1f5..15b1297 100644 --- a/go.sum +++ b/go.sum @@ -1,9 +1,19 @@ -github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= +github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/kanisterio/errkit v0.0.2 h1:3v3HGz9lHIbZR6Jr9qIJpRjaqUX0rsJSLMEQGsMHiUk= +github.com/kanisterio/errkit v0.0.2/go.mod h1:ViQ6kPJ2gTJDEvRytmwde7pzG9/sndObF9BPZoEZixc= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= -github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= +github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= diff --git a/test/arg_suite.go b/test/arg_suite.go index fe8cc59..a899510 100644 --- a/test/arg_suite.go +++ b/test/arg_suite.go @@ -17,10 +17,8 @@ package test import ( "gopkg.in/check.v1" - "github.com/pkg/errors" - + "github.com/kanisterio/errkit" "github.com/kanisterio/safecli" - "github.com/kanisterio/safecli/command" ) @@ -69,8 +67,7 @@ func (t *ArgumentTest) assertNoError(c *check.C, err error) { // assertError checks the error against ExpectedErr. func (t *ArgumentTest) assertError(c *check.C, err error) { - actualErr := errors.Cause(err) - c.Assert(actualErr, check.Equals, t.ExpectedErr, t.comment()) + c.Assert(errkit.Is(err, t.ExpectedErr), check.Equals, true, t.comment()) } // assertErrorMsg checks the error message against ExpectedErrMsg. diff --git a/test/arg_suite_test.go b/test/arg_suite_test.go index 926a018..de404df 100644 --- a/test/arg_suite_test.go +++ b/test/arg_suite_test.go @@ -18,10 +18,9 @@ import ( "strings" "testing" - "github.com/pkg/errors" - "gopkg.in/check.v1" + "github.com/kanisterio/errkit" "github.com/kanisterio/safecli" "github.com/kanisterio/safecli/test" ) @@ -113,7 +112,7 @@ func (s *TestRunnerWithConfig) TestArgumentTestEmptyName(c *check.C) { // TestArgumentTestErrButReturnOK tests the ArgumentTest with an error but ArgumentTest returns no error. func (s *TestRunnerWithConfig) TestArgumentTestErrButReturnOK(c *check.C) { - err := errors.New("test error") + err := errkit.New("test error") cat := CustomArgumentTest{ name: "TestArgumentTestErrButReturnOK", argErr: nil, // no error @@ -122,13 +121,13 @@ func (s *TestRunnerWithConfig) TestArgumentTestErrButReturnOK(c *check.C) { } res := check.Run(&cat, s.cfg) out := strings.ReplaceAll(s.out.String(), "\n", "") - c.Assert(out, check.Matches, ".*FAIL:.*CustomArgumentTest\\.Test.*test error.*") + c.Assert(out, check.Matches, ".*FAIL:.*CustomArgumentTest\\.Test.*TestArgumentTestErrButReturnOK") c.Assert(res.Passed(), check.Equals, false) } // TestArgumentTestErr tests the ArgumentTest with an error. func (s *TestRunnerWithConfig) TestArgumentTestErr(c *check.C) { - err := errors.New("test error") + err := errkit.New("test error") cat := CustomArgumentTest{ name: "TestArgumentErr", argErr: err, @@ -142,8 +141,8 @@ func (s *TestRunnerWithConfig) TestArgumentTestErr(c *check.C) { // TestArgumentTestWrapperErr tests the ArgumentTest with a wrapped error. func (s *TestRunnerWithConfig) TestArgumentTestWrapperErr(c *check.C) { - err := errors.New("test error") - werr := errors.Wrap(err, "wrapper error") + err := errkit.New("test error") + werr := errkit.Wrap(err, "wrapper error") cat := CustomArgumentTest{ name: "TestArgumentTestWrapperErr", argErr: werr, @@ -156,7 +155,7 @@ func (s *TestRunnerWithConfig) TestArgumentTestWrapperErr(c *check.C) { // TestArgumentTestUnexpectedErr tests the ArgumentTest with an unexpected error. func (s *TestRunnerWithConfig) TestArgumentTestUnexpectedErr(c *check.C) { - err := errors.New("test error") + err := errkit.New("test error") cat := CustomArgumentTest{ name: "TestArgumentUnexpectedErr", arg: "--test",