Skip to content

Commit

Permalink
chore: Errkit migration 8.4 migrate remaining piece of pkg/kando, `…
Browse files Browse the repository at this point in the history
…pkg/kanx`, `pkg.ksprig` to errkit (#3257)

Signed-off-by: Eugen Sumin <[email protected]>
Co-authored-by: Rajat Gupta <[email protected]>
  • Loading branch information
e-sumin and r4rajat authored Dec 3, 2024
1 parent 5215164 commit 2fed698
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 19 deletions.
4 changes: 2 additions & 2 deletions pkg/kando/chronicle_pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -51,7 +51,7 @@ type locationParams struct {
func unmarshalProfile(prof string) (*param.Profile, error) {
p := &param.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
Expand Down
4 changes: 2 additions & 2 deletions pkg/kando/kando.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package kando
import (
"os"

"github.com/pkg/errors"
"github.com/kanisterio/errkit"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"

Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions pkg/kando/location.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -96,22 +96,22 @@ 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.")
}
}

func unmarshalProfileFlag(cmd *cobra.Command) (*param.Profile, error) {
profileJSON := cmd.Flag(profileFlagName).Value.String()
p := &param.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 := &param.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 {
Expand Down
6 changes: 4 additions & 2 deletions pkg/kando/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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])
}
Expand Down
9 changes: 4 additions & 5 deletions pkg/kanx/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package kanx
import (
"bytes"
"context"
"fmt"
"io"
"net"
"os"
Expand All @@ -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"
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/ksprig/fipsonly_sprig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 2fed698

Please sign in to comment.