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
+6 -7
View File
@@ -31,7 +31,6 @@ import (
"time"
"github.com/dchest/uniuri"
"github.com/pkg/errors"
"go.uber.org/zap"
"github.com/fission/fission/pkg/info"
@@ -206,7 +205,7 @@ func (builder *Builder) reply(ctx context.Context, w http.ResponseWriter, pkgFil
rBody, err := json.Marshal(resp)
if err != nil {
e := errors.Wrap(err, "error encoding response body")
e := fmt.Errorf("error encoding response body: %w", err)
rBody = []byte(fmt.Sprintf(`{"buildLogs": "%s"}`, e.Error()))
statusCode = http.StatusInternalServerError
}
@@ -247,12 +246,12 @@ func (builder *Builder) build(ctx context.Context, command string, args []string
stdout, err := cmd.StdoutPipe()
if err != nil {
return "", errors.Wrap(err, "error creating stdout pipe for cmd")
return "", fmt.Errorf("error creating stdout pipe for cmd: %w", err)
}
stderr, err := cmd.StderrPipe()
if err != nil {
return "", errors.Wrap(err, "error creating stderr pipe for cmd")
return "", fmt.Errorf("error creating stderr pipe for cmd: %w", err)
}
// Init logs
@@ -263,7 +262,7 @@ func (builder *Builder) build(ctx context.Context, command string, args []string
err = cmd.Start()
if err != nil {
return "", errors.Wrap(err, "error starting cmd")
return "", fmt.Errorf("error starting cmd: %w", err)
}
fmt.Printf("========= START =========\n")
defer fmt.Printf("========= END ===========\n")
@@ -276,14 +275,14 @@ func (builder *Builder) build(ctx context.Context, command string, args []string
}
if err := scanner.Err(); err != nil {
scanErr := errors.Wrap(err, "error reading cmd output")
scanErr := fmt.Errorf("error reading cmd output: %w", err)
fmt.Println(scanErr)
return buildLogs, scanErr
}
err = cmd.Wait()
if err != nil {
cmdErr := errors.Wrapf(err, "error waiting for cmd %q", command)
cmdErr := fmt.Errorf("error waiting for cmd %q: %w", command, err)
fmt.Println(cmdErr)
return buildLogs, cmdErr
}
+6 -6
View File
@@ -20,12 +20,12 @@ import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"strings"
"github.com/hashicorp/go-retryablehttp"
"github.com/pkg/errors"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
"go.uber.org/zap"
"golang.org/x/net/context/ctxhttp"
@@ -68,26 +68,26 @@ func (c *client) Build(ctx context.Context, req *builder.PackageBuildRequest) (*
body, err := json.Marshal(req)
if err != nil {
return nil, errors.Wrap(err, "error marshaling json")
return nil, fmt.Errorf("error marshaling json: %w", err)
}
resp, err := ctxhttp.Post(ctx, c.httpClient.StandardClient(), c.url, "application/json", bytes.NewReader(body))
if err != nil {
return nil, err
return nil, fmt.Errorf("error sending request: %w", err)
}
defer resp.Body.Close()
rBody, err := io.ReadAll(resp.Body)
if err != nil {
logger.Error("error reading resp body", zap.Error(err))
return nil, err
return nil, fmt.Errorf("error reading response body: %w", err)
}
pkgBuildResp := builder.PackageBuildResponse{}
err = json.Unmarshal(rBody, &pkgBuildResp)
if err != nil {
logger.Error("error parsing resp body", zap.Error(err))
return nil, err
return nil, fmt.Errorf("error parsing response body: %w", err)
}
return &pkgBuildResp, ferror.MakeErrorFromHTTP(resp)
@@ -98,7 +98,7 @@ func (c *client) Clean(ctx context.Context, srcPkgFilename string) error {
req, err := http.NewRequest(http.MethodDelete, c.getCleanUrl(srcPkgFilename), http.NoBody)
if err != nil {
return errors.Wrap(err, "failed to create http request for clean api")
return fmt.Errorf("error creating http request: %w", err)
}
resp, err := ctxhttp.Do(ctx, c.httpClient.StandardClient(), req)