Errors: Remove direct dependencies on github.com/pkg/errors (#64026)
Co-authored-by: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com>
This commit is contained in:
co-authored by
Sofia Papagiannaki
parent
8c8f584b41
commit
10ee900beb
@@ -19,7 +19,6 @@ import (
|
||||
_ "github.com/jung-kurt/gofpdf"
|
||||
_ "github.com/linkedin/goavro/v2"
|
||||
_ "github.com/m3db/prometheus_remote_client_golang/promremote"
|
||||
_ "github.com/pkg/errors"
|
||||
_ "github.com/robfig/cron/v3"
|
||||
_ "github.com/russellhaering/goxmldsig"
|
||||
_ "github.com/stretchr/testify/require"
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"xorm.io/xorm"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
@@ -132,7 +131,7 @@ func (ss *sqlStore) AddAPIKey(ctx context.Context, cmd *apikey.AddCommand) error
|
||||
}
|
||||
|
||||
if _, err := sess.Insert(&t); err != nil {
|
||||
return errors.Wrap(err, "failed to insert token")
|
||||
return fmt.Errorf("%s: %w", "failed to insert token", err)
|
||||
}
|
||||
cmd.Result = &t
|
||||
return nil
|
||||
|
||||
@@ -3,6 +3,7 @@ package api
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
@@ -11,7 +12,6 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
@@ -206,13 +206,15 @@ func messageExtractor(resp *response.NormalResponse) (interface{}, error) {
|
||||
// ErrorResp creates a response with a visible error
|
||||
func ErrResp(status int, err error, msg string, args ...interface{}) *response.NormalResponse {
|
||||
if msg != "" {
|
||||
err = errors.WithMessagef(err, msg, args...)
|
||||
formattedMsg := fmt.Sprintf(msg, args...)
|
||||
err = fmt.Errorf("%s: %w", formattedMsg, err)
|
||||
}
|
||||
return response.Error(status, err.Error(), err)
|
||||
}
|
||||
|
||||
// accessForbiddenResp creates a response of forbidden access.
|
||||
func accessForbiddenResp() response.Response {
|
||||
//nolint:stylecheck // Grandfathered capitalization of error.
|
||||
return ErrResp(http.StatusForbidden, errors.New("Permission denied"), "")
|
||||
}
|
||||
|
||||
|
||||
@@ -243,7 +243,7 @@ func GetNamespacedKVStore(kv kvstore.KVStore) *kvstore.NamespacedKVStore {
|
||||
func IsPluginStartupErrorFatal(ctx context.Context, kvstore *kvstore.NamespacedKVStore) (bool, error) {
|
||||
_, exists, err := kvstore.Get(ctx, QuitOnPluginStartupFailureKey)
|
||||
if err != nil {
|
||||
return false, errors.New(fmt.Sprint("error retrieving key ", QuitOnPluginStartupFailureKey, " from kvstore. error: ", err.Error()))
|
||||
return false, fmt.Errorf("error retrieving key %s from kvstore. error: %w", QuitOnPluginStartupFailureKey, err)
|
||||
}
|
||||
return exists, nil
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/services/apikey"
|
||||
@@ -33,7 +33,10 @@ func (s *ServiceAccountsStoreImpl) ListTokens(
|
||||
sess = sess.Join("inner", quotedUser, quotedUser+".id = api_key.service_account_id").
|
||||
Asc("api_key.name")
|
||||
|
||||
return errors.Wrapf(sess.Find(&result), "list token error")
|
||||
if err := sess.Find(&result); err != nil {
|
||||
return fmt.Errorf("%s: %w", "list token error", err)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
return result, err
|
||||
}
|
||||
|
||||
@@ -5,13 +5,12 @@ import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const timeout = 4 * time.Second
|
||||
@@ -100,7 +99,7 @@ func (c *client) checkTokens(ctx context.Context, keyHashes []string) ([]Token,
|
||||
|
||||
jsonValue, err := json.Marshal(values)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to make http request")
|
||||
return nil, fmt.Errorf("%s: %w", "failed to make http request", err)
|
||||
}
|
||||
|
||||
// Build URL
|
||||
@@ -109,7 +108,7 @@ func (c *client) checkTokens(ctx context.Context, keyHashes []string) ([]Token,
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodPost,
|
||||
url, bytes.NewReader(jsonValue))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to make http request")
|
||||
return nil, fmt.Errorf("%s: %w", "failed to make http request", err)
|
||||
}
|
||||
|
||||
// Set headers
|
||||
@@ -120,7 +119,7 @@ func (c *client) checkTokens(ctx context.Context, keyHashes []string) ([]Token,
|
||||
// make http POST request to check for leaked tokens.
|
||||
resp, err := c.httpClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to do http request")
|
||||
return nil, fmt.Errorf("%s: %w", "failed to do http request", err)
|
||||
}
|
||||
|
||||
defer func() { _ = resp.Body.Close() }()
|
||||
@@ -132,7 +131,7 @@ func (c *client) checkTokens(ctx context.Context, keyHashes []string) ([]Token,
|
||||
// decode response body
|
||||
var tokens []Token
|
||||
if err := json.NewDecoder(resp.Body).Decode(&tokens); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to decode response body")
|
||||
return nil, fmt.Errorf("%s: %w", "failed to decode response body", err)
|
||||
}
|
||||
|
||||
return tokens, nil
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
@@ -12,7 +13,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var errWebHookURL = errors.New("webhook url must be https")
|
||||
@@ -76,7 +76,7 @@ func (wClient *webHookClient) Notify(ctx context.Context,
|
||||
|
||||
jsonValue, err := json.Marshal(values)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to marshal webhook request")
|
||||
return fmt.Errorf("%s: %w", "failed to marshal webhook request", err)
|
||||
}
|
||||
|
||||
// Build URL
|
||||
@@ -84,7 +84,7 @@ func (wClient *webHookClient) Notify(ctx context.Context,
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodPost,
|
||||
wClient.url, bytes.NewReader(jsonValue))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to make http request")
|
||||
return fmt.Errorf("%s: %w", "failed to make http request", err)
|
||||
}
|
||||
|
||||
// Set headers
|
||||
@@ -95,7 +95,7 @@ func (wClient *webHookClient) Notify(ctx context.Context,
|
||||
// make http POST request to check for leaked tokens.
|
||||
resp, err := wClient.httpClient.Do(req)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to webhook request")
|
||||
return fmt.Errorf("%s: %w", "failed to webhook request", err)
|
||||
}
|
||||
|
||||
defer func() { _ = resp.Body.Close() }()
|
||||
|
||||
Reference in New Issue
Block a user