From 2fed6988fe91403dbeb1acedf7c4c312a6178ff1 Mon Sep 17 00:00:00 2001 From: Eugene Sumin <95425330+e-sumin@users.noreply.github.com> Date: Tue, 3 Dec 2024 17:34:14 +0100 Subject: [PATCH] chore: Errkit migration 8.4 migrate remaining piece of `pkg/kando`, `pkg/kanx`, `pkg.ksprig` to errkit (#3257) Signed-off-by: Eugen Sumin Co-authored-by: Rajat Gupta <37516416+r4rajat@users.noreply.github.com> --- pkg/kando/chronicle_pull.go | 4 ++-- pkg/kando/kando.go | 4 ++-- pkg/kando/location.go | 12 ++++++------ pkg/kando/output.go | 6 ++++-- pkg/kanx/server.go | 9 ++++----- pkg/ksprig/fipsonly_sprig_test.go | 4 ++-- 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/pkg/kando/chronicle_pull.go b/pkg/kando/chronicle_pull.go index 941ee4b335..a61866f449 100644 --- a/pkg/kando/chronicle_pull.go +++ b/pkg/kando/chronicle_pull.go @@ -20,7 +20,7 @@ import ( "io" "os" - "github.com/pkg/errors" + "github.com/kanisterio/errkit" "github.com/spf13/cobra" "github.com/kanisterio/kanister/pkg/chronicle" @@ -51,7 +51,7 @@ type locationParams struct { func unmarshalProfile(prof string) (*param.Profile, error) { p := ¶m.Profile{} err := json.Unmarshal([]byte(prof), p) - return p, errors.Wrap(err, "failed to unmarshal profile") + return p, errkit.Wrap(err, "failed to unmarshal profile") } //nolint:unparam diff --git a/pkg/kando/kando.go b/pkg/kando/kando.go index b02ebb8d0e..cc6f2b257c 100644 --- a/pkg/kando/kando.go +++ b/pkg/kando/kando.go @@ -17,7 +17,7 @@ package kando import ( "os" - "github.com/pkg/errors" + "github.com/kanisterio/errkit" "github.com/sirupsen/logrus" "github.com/spf13/cobra" @@ -60,7 +60,7 @@ func newRootCommand() *cobra.Command { func setLogLevel(v string) error { l, err := logrus.ParseLevel(v) if err != nil { - return errors.Wrap(err, "Invalid log level: "+v) + return errkit.Wrap(err, "Invalid log level: "+v) } logrus.SetLevel(l) return nil diff --git a/pkg/kando/location.go b/pkg/kando/location.go index f6c4e16f75..603c36672a 100644 --- a/pkg/kando/location.go +++ b/pkg/kando/location.go @@ -17,7 +17,7 @@ package kando import ( "encoding/json" - "github.com/pkg/errors" + "github.com/kanisterio/errkit" "github.com/spf13/cobra" "github.com/kanisterio/kanister/pkg/datamover" @@ -63,10 +63,10 @@ func validateCommandArgs(cmd *cobra.Command) error { profileFlag := cmd.Flags().Lookup(profileFlagName).Value.String() repositoryServerFlag := cmd.Flags().Lookup(repositoryServerFlagName).Value.String() if profileFlag != "" && repositoryServerFlag != "" { - return errors.New("Either --profile or --repository-server should be provided") + return errkit.New("Either --profile or --repository-server should be provided") } if profileFlag == "" && repositoryServerFlag == "" { - return errors.New("Please provide either --profile or --repository-server as per the datamover you want to use") + return errkit.New("Please provide either --profile or --repository-server as per the datamover you want to use") } return nil } @@ -96,7 +96,7 @@ func dataMoverFromCMD(cmd *cobra.Command, kopiaSnapshot, outputName string) (dat } return datamover.NewRepositoryServerDataMover(repositoryServerRef, outputName, kopiaSnapshot, cmd.Flag(repositoryServerUserHostnameFlagName).Value.String()), nil default: - return nil, errors.New("Could not initialize DataMover.") + return nil, errkit.New("Could not initialize DataMover.") } } @@ -104,14 +104,14 @@ func unmarshalProfileFlag(cmd *cobra.Command) (*param.Profile, error) { profileJSON := cmd.Flag(profileFlagName).Value.String() p := ¶m.Profile{} err := json.Unmarshal([]byte(profileJSON), p) - return p, errors.Wrap(err, "failed to unmarshal profile") + return p, errkit.Wrap(err, "failed to unmarshal profile") } func unmarshalRepositoryServerFlag(cmd *cobra.Command) (*param.RepositoryServer, error) { repositoryServerJSON := cmd.Flag(repositoryServerFlagName).Value.String() rs := ¶m.RepositoryServer{} err := json.Unmarshal([]byte(repositoryServerJSON), rs) - return rs, errors.Wrap(err, "failed to unmarshal kopia repository server CR") + return rs, errkit.Wrap(err, "failed to unmarshal kopia repository server CR") } func dataMoverTypeFromCMD(c *cobra.Command) DataMoverType { diff --git a/pkg/kando/output.go b/pkg/kando/output.go index 3c8e092da5..fd92b03dff 100644 --- a/pkg/kando/output.go +++ b/pkg/kando/output.go @@ -15,7 +15,9 @@ package kando import ( - "github.com/pkg/errors" + "fmt" + + "github.com/kanisterio/errkit" "github.com/spf13/cobra" "github.com/kanisterio/kanister/pkg/output" @@ -34,7 +36,7 @@ func newOutputCommand() *cobra.Command { func validateArguments(c *cobra.Command, args []string) error { if len(args) != 2 { - return errors.Errorf("Command accepts 2 arguments, received %d arguments", len(args)) + return errkit.New(fmt.Sprintf("Command accepts 2 arguments, received %d arguments", len(args))) } return output.ValidateKey(args[0]) } diff --git a/pkg/kanx/server.go b/pkg/kanx/server.go index 50883ff938..eab13e1f22 100644 --- a/pkg/kanx/server.go +++ b/pkg/kanx/server.go @@ -3,7 +3,6 @@ package kanx import ( "bytes" "context" - "fmt" "io" "net" "os" @@ -12,7 +11,7 @@ import ( "syscall" "time" - "github.com/pkg/errors" + "github.com/kanisterio/errkit" "google.golang.org/grpc" "github.com/kanisterio/kanister/pkg/field" @@ -117,12 +116,12 @@ func (s *processServiceServer) ListProcesses(lpr *ListProcessesRequest, lps Proc return nil } -var errProcessNotFound = fmt.Errorf("Process not found") +var errProcessNotFound = errkit.NewSentinelErr("Process not found") func (s *processServiceServer) Stdout(por *ProcessOutputRequest, ss ProcessService_StdoutServer) error { p, ok := s.processes[por.Pid] if !ok { - return errors.WithStack(errProcessNotFound) + return errkit.WithStack(errProcessNotFound) } fh, err := os.Open(p.stdout.Name()) if err != nil { @@ -134,7 +133,7 @@ func (s *processServiceServer) Stdout(por *ProcessOutputRequest, ss ProcessServi func (s *processServiceServer) Stderr(por *ProcessOutputRequest, ss ProcessService_StderrServer) error { p, ok := s.processes[por.Pid] if !ok { - return errors.WithStack(errProcessNotFound) + return errkit.WithStack(errProcessNotFound) } fh, err := os.Open(p.stderr.Name()) if err != nil { diff --git a/pkg/ksprig/fipsonly_sprig_test.go b/pkg/ksprig/fipsonly_sprig_test.go index 7a2ea4968c..e45409c72e 100644 --- a/pkg/ksprig/fipsonly_sprig_test.go +++ b/pkg/ksprig/fipsonly_sprig_test.go @@ -15,11 +15,11 @@ package ksprig_test import ( - "errors" "strings" "testing" "text/template" + "github.com/kanisterio/errkit" "gopkg.in/check.v1" "github.com/kanisterio/kanister/pkg/ksprig" @@ -74,7 +74,7 @@ func (f *FipsOnlySprigSuite) TestUnsupportedTxtFuncMapUsage(c *check.C) { err = temp.Execute(nil, "") var sprigErr ksprig.UnsupportedSprigUsageErr - c.Assert(errors.As(err, &sprigErr), check.Equals, true) + c.Assert(errkit.As(err, &sprigErr), check.Equals, true) c.Assert(sprigErr.Usage, check.Equals, tc.usageErr) } }