Remove github.com/pkg/errors with appropriate replacements (#3172)

* errors.Wrap* removal

Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>

* remove errors.Errorf

Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>

* Remove remaining calls

Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>

* Few more errors

Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>

* Fix golint errors

Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>

---------

Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>
This commit is contained in:
Sanket Sudake
2025-02-20 08:58:37 +05:30
committed by GitHub
parent 2fd44174ce
commit caffed92f4
113 changed files with 585 additions and 588 deletions
+9 -10
View File
@@ -26,7 +26,6 @@ import (
"strings"
"time"
"github.com/pkg/errors"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/portforward"
@@ -50,7 +49,7 @@ func SetupPortForward(ctx context.Context, client cmd.Client, namespace, labelSe
lcPort, err := utils.FindFreePort()
if err != nil {
return "", errors.Wrap(err, "error finding unused port")
return "", fmt.Errorf("error finding unused port: %w", err)
}
localPort := strconv.Itoa(lcPort)
@@ -118,9 +117,9 @@ func runPortForward(ctx context.Context, client cmd.Client, labelSelector string
podList, err := client.KubernetesClient.CoreV1().Pods(ns).
List(ctx, metav1.ListOptions{LabelSelector: labelSelector})
if err != nil {
return nil, nil, errors.Wrapf(err, "error getting pod for port-forwarding with label selector %v", labelSelector)
return nil, nil, fmt.Errorf("error getting pod for port-forwarding with label selector %v: %w", labelSelector, err)
} else if len(podList.Items) == 0 {
return nil, nil, errors.Errorf("no available pod for port-forwarding with label selector %v", labelSelector)
return nil, nil, fmt.Errorf("no available pod for port-forwarding with label selector %v", labelSelector)
}
nsList := make([]string, 0)
@@ -136,7 +135,7 @@ func runPortForward(ctx context.Context, client cmd.Client, labelSelector string
namespaces[p.Namespace] = append(namespaces[p.Namespace], &p)
}
if len(nsList) > 1 {
return nil, nil, errors.Errorf("Found %v fission installs, set FISSION_NAMESPACE to one of: %v",
return nil, nil, fmt.Errorf("Found %v fission installs, set FISSION_NAMESPACE to one of: %v",
len(namespaces), strings.Join(nsList, " "))
}
}
@@ -146,7 +145,7 @@ func runPortForward(ctx context.Context, client cmd.Client, labelSelector string
ns = nsList[0]
pods, ok := namespaces[ns]
if !ok {
return nil, nil, errors.Errorf("Error finding fission install within the given namespace %v, please check FISSION_NAMESPACE is set properly", ns)
return nil, nil, fmt.Errorf("Error finding fission install within the given namespace %v, please check FISSION_NAMESPACE is set properly", ns)
}
var podName, podNameSpace string
@@ -164,10 +163,10 @@ func runPortForward(ctx context.Context, client cmd.Client, labelSelector string
svcs, err := client.KubernetesClient.CoreV1().Services(podNameSpace).
List(ctx, metav1.ListOptions{LabelSelector: labelSelector})
if err != nil {
return nil, nil, errors.Wrapf(err, "Error getting %v service", labelSelector)
return nil, nil, fmt.Errorf("Error getting %v service: %w", labelSelector, err)
}
if len(svcs.Items) == 0 {
return nil, nil, errors.Errorf("Service %v not found", labelSelector)
return nil, nil, fmt.Errorf("Service %v not found", labelSelector)
}
service := &svcs.Items[0]
@@ -192,7 +191,7 @@ func runPortForward(ctx context.Context, client cmd.Client, labelSelector string
// actually start the port-forwarding process here
transport, upgrader, err := spdy.RoundTripperFor(client.RestConfig)
if err != nil {
return nil, nil, errors.Errorf("Failed to connect to Fission service on Kubernetes")
return nil, nil, fmt.Errorf("Failed to connect to Fission service on Kubernetes")
}
dialer := spdy.NewDialer(upgrader, &http.Client{Transport: transport}, "POST", url)
@@ -202,7 +201,7 @@ func runPortForward(ctx context.Context, client cmd.Client, labelSelector string
}
fw, err := portforward.New(dialer, ports, stopChannel, readyChannel, outStream, os.Stderr)
if err != nil {
return nil, nil, errors.Wrap(err, "error creating port forwarder")
return nil, nil, fmt.Errorf("error creating port forwarder: %w", err)
}
go func() {
+13 -12
View File
@@ -32,8 +32,9 @@ import (
ignore "github.com/sabhiram/go-gitignore"
"errors"
"github.com/hashicorp/go-multierror"
"github.com/pkg/errors"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -254,7 +255,7 @@ func GetResourceReqs(input cli.Input, resReqs *v1.ResourceRequirements) (*v1.Res
mincpu := input.Int(flagkey.RuntimeMincpu)
cpuRequest, err := resource.ParseQuantity(strconv.Itoa(mincpu) + "m")
if err != nil {
e = multierror.Append(e, errors.Wrap(err, "Failed to parse mincpu"))
e = multierror.Append(e, fmt.Errorf("Failed to parse mincpu: %w", err))
}
r.Requests[v1.ResourceCPU] = cpuRequest
}
@@ -263,7 +264,7 @@ func GetResourceReqs(input cli.Input, resReqs *v1.ResourceRequirements) (*v1.Res
minmem := input.Int(flagkey.RuntimeMinmemory)
memRequest, err := resource.ParseQuantity(strconv.Itoa(minmem) + "Mi")
if err != nil {
e = multierror.Append(e, errors.Wrap(err, "Failed to parse minmemory"))
e = multierror.Append(e, fmt.Errorf("Failed to parse minmemory: %w", err))
}
r.Requests[v1.ResourceMemory] = memRequest
}
@@ -272,7 +273,7 @@ func GetResourceReqs(input cli.Input, resReqs *v1.ResourceRequirements) (*v1.Res
maxcpu := input.Int(flagkey.RuntimeMaxcpu)
cpuLimit, err := resource.ParseQuantity(strconv.Itoa(maxcpu) + "m")
if err != nil {
e = multierror.Append(e, errors.Wrap(err, "Failed to parse maxcpu"))
e = multierror.Append(e, fmt.Errorf("Failed to parse maxcpu: %w", err))
}
r.Limits[v1.ResourceCPU] = cpuLimit
}
@@ -281,7 +282,7 @@ func GetResourceReqs(input cli.Input, resReqs *v1.ResourceRequirements) (*v1.Res
maxmem := input.Int(flagkey.RuntimeMaxmemory)
memLimit, err := resource.ParseQuantity(strconv.Itoa(maxmem) + "Mi")
if err != nil {
e = multierror.Append(e, errors.Wrap(err, "Failed to parse maxmemory"))
e = multierror.Append(e, fmt.Errorf("Failed to parse maxmemory: %w", err))
}
r.Limits[v1.ResourceMemory] = memLimit
}
@@ -340,7 +341,7 @@ func GetSpecIgnoreParser(specDir, specIgnore string) (ignore.IgnoreParser, error
if _, err := os.Stat(specIgnorePath); errors.Is(err, os.ErrNotExist) {
// return error if it's custom spec ignore file
if specIgnore != SPEC_IGNORE_FILE {
return nil, errors.Errorf("Spec ignore file '%s' doesn't exist. "+
return nil, fmt.Errorf("Spec ignore file '%s' doesn't exist. "+
"Please check the file path: '%s'", specIgnore, specIgnorePath)
}
return ignore.CompileIgnoreLines(), nil
@@ -423,7 +424,7 @@ func ParseAnnotations(annotations []string) (map[string]string, error) {
}
}
if invalidAnnotations != "" {
return nil, errors.Errorf("invalid annotations: %s", invalidAnnotations)
return nil, fmt.Errorf("invalid annotations: %s", invalidAnnotations)
}
return annotationMap, nil
}
@@ -523,7 +524,7 @@ func GetSvcName(ctx context.Context, kClient kubernetes.Interface, application s
}
if len(services.Items) > 1 || len(services.Items) == 0 {
return "", errors.Errorf("more than one service found for application=%s", application)
return "", fmt.Errorf("more than one service found for application=%s", application)
}
service := services.Items[0]
return service.Name + "." + service.Namespace, nil
@@ -576,7 +577,7 @@ func FunctionPodLogs(ctx context.Context, fnName, ns string, client cmd.Client)
// get the pod with highest resource version
err = getContainerLog(ctx, client.KubernetesClient, f, &pods[0])
if err != nil {
return errors.Wrapf(err, "error getting container logs")
return fmt.Errorf("error getting container logs: %w", err)
}
return err
@@ -591,19 +592,19 @@ func getContainerLog(ctx context.Context, kubernetesClient kubernetes.Interface,
podLogs, err := podLogsReq.Stream(ctx)
if err != nil {
return errors.Wrapf(err, "error streaming pod log")
return fmt.Errorf("error streaming pod log: %w", err)
}
msg := fmt.Sprintf("\n%v\nFunction: %v\nEnvironment: %v\nNamespace: %v\nPod: %v\nContainer: %v\nNode: %v\n%v\n", seq,
fn.ObjectMeta.Name, fn.Spec.Environment.Name, pod.Namespace, pod.Name, container.Name, pod.Spec.NodeName, seq)
if _, err := io.WriteString(os.Stdout, msg); err != nil {
return errors.Wrapf(err, "error copying pod log")
return fmt.Errorf("error copying pod log: %w", err)
}
_, err = io.Copy(os.Stdout, podLogs)
if err != nil {
return errors.Wrapf(err, "error copying pod log")
return fmt.Errorf("error copying pod log: %w", err)
}
podLogs.Close()