mirror of
https://github.com/grafana/grafana.git
synced 2024-11-21 16:38:03 -06:00
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:
parent
8c8f584b41
commit
10ee900beb
@ -20,6 +20,7 @@ packages = ["io/ioutil"]
|
||||
[[linters-settings.depguard.packages-with-error-message]]
|
||||
"io/ioutil" = "Deprecated: As of Go 1.16, the same functionality is now provided by package io or package os, and those implementations should be preferred in new code. See the specific function documentation for details."
|
||||
"gopkg.in/yaml.v2" = "Grafana packages are not allowed to depend on gopkg.in/yaml.v2 as gopkg.in/yaml.v3 is now available"
|
||||
"github.com/pkg/errors" = "Deprecated: Go 1.13 supports the functionality provided by pkg/errors in the standard library."
|
||||
|
||||
[linters-settings.gocritic]
|
||||
enabled-checks = ["ruleguard"]
|
||||
|
2
go.mod
2
go.mod
@ -91,7 +91,7 @@ require (
|
||||
github.com/opentracing/opentracing-go v1.2.0
|
||||
github.com/patrickmn/go-cache v2.1.0+incompatible
|
||||
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/prometheus/alertmanager v0.25.0
|
||||
github.com/prometheus/client_golang v1.14.0
|
||||
github.com/prometheus/client_model v0.3.0
|
||||
|
2
go.sum
2
go.sum
@ -1283,8 +1283,6 @@ github.com/grafana/saml v0.4.13-0.20230203140620-5f476db5c00a h1:aWSTt/pTOI4uGY9
|
||||
github.com/grafana/saml v0.4.13-0.20230203140620-5f476db5c00a/go.mod h1:igEejV+fihTIlHXYP8zOec3V5A8y3lws5bQBFsTm4gA=
|
||||
github.com/grafana/sqlds/v2 v2.3.10 h1:HWKhE0vR6LoEiE+Is8CSZOgaB//D1yqb2ntkass9Fd4=
|
||||
github.com/grafana/sqlds/v2 v2.3.10/go.mod h1:c6ibxnxRVGxV/0YkEgvy7QpQH/lyifFyV7K/14xvdIs=
|
||||
github.com/grafana/thema v0.0.0-20230223160728-4226e958935a h1:5DSEQFi/pr7pYokTEvhVe94n5s6p771+PKD/GjaoP+s=
|
||||
github.com/grafana/thema v0.0.0-20230223160728-4226e958935a/go.mod h1:T6q1RVzq5fzVbm+QBeIsTmVzuXlMaArp4wxfLvcaMV0=
|
||||
github.com/grafana/thema v0.0.0-20230224141623-cb20887cb028 h1:6DXb3CmghXpjtd0VjK1FDEjvHhNcXfYSxUcEfxyMx9w=
|
||||
github.com/grafana/thema v0.0.0-20230224141623-cb20887cb028/go.mod h1:T6q1RVzq5fzVbm+QBeIsTmVzuXlMaArp4wxfLvcaMV0=
|
||||
github.com/grafana/xorm v0.8.3-0.20220614223926-2fcda7565af6 h1:I9dh1MXGX0wGyxdV/Sl7+ugnki4Dfsy8lv2s5Yf887o=
|
||||
|
@ -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() }()
|
||||
|
Loading…
Reference in New Issue
Block a user