mirror of
https://github.com/grafana/grafana.git
synced 2025-02-03 20:21:01 -06:00
Chore: Remove Wrapf (#50128)
* Chore: Remove Wrapf * Remove all Wrapf refs * Remove last Wrapf ref * Fix lint errors * Remove Wrap and Wrapf definitions * Remove unnecessary colon
This commit is contained in:
parent
56eb131715
commit
31630edf0c
@ -77,7 +77,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/thumbs"
|
||||
"github.com/grafana/grafana/pkg/services/updatechecker"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/util/errutil"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
)
|
||||
|
||||
@ -380,19 +379,19 @@ func (hs *HTTPServer) getListener() (net.Listener, error) {
|
||||
case setting.HTTPScheme, setting.HTTPSScheme, setting.HTTP2Scheme:
|
||||
listener, err := net.Listen("tcp", hs.httpSrv.Addr)
|
||||
if err != nil {
|
||||
return nil, errutil.Wrapf(err, "failed to open listener on address %s", hs.httpSrv.Addr)
|
||||
return nil, fmt.Errorf("failed to open listener on address %s: %w", hs.httpSrv.Addr, err)
|
||||
}
|
||||
return listener, nil
|
||||
case setting.SocketScheme:
|
||||
listener, err := net.ListenUnix("unix", &net.UnixAddr{Name: hs.Cfg.SocketPath, Net: "unix"})
|
||||
if err != nil {
|
||||
return nil, errutil.Wrapf(err, "failed to open listener for socket %s", hs.Cfg.SocketPath)
|
||||
return nil, fmt.Errorf("failed to open listener for socket %s: %w", hs.Cfg.SocketPath, err)
|
||||
}
|
||||
|
||||
// Make socket writable by group
|
||||
// nolint:gosec
|
||||
if err := os.Chmod(hs.Cfg.SocketPath, 0660); err != nil {
|
||||
return nil, errutil.Wrapf(err, "failed to change socket permissions")
|
||||
return nil, fmt.Errorf("failed to change socket permissions: %w", err)
|
||||
}
|
||||
|
||||
return listener, nil
|
||||
|
@ -12,7 +12,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
"github.com/grafana/grafana/pkg/util/errutil"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -72,11 +71,14 @@ func migrateColumn(session *sqlstore.DBSession, column string) (int, error) {
|
||||
err := session.Find(&rows)
|
||||
|
||||
if err != nil {
|
||||
return 0, errutil.Wrapf(err, "failed to select column: %s", column)
|
||||
return 0, fmt.Errorf("failed to select column: %s: %w", column, err)
|
||||
}
|
||||
|
||||
rowsUpdated, err := updateRows(session, rows, column)
|
||||
return rowsUpdated, errutil.Wrapf(err, "failed to update column: %s", column)
|
||||
if err != nil {
|
||||
return rowsUpdated, fmt.Errorf("failed to update column: %s: %w", column, err)
|
||||
}
|
||||
return rowsUpdated, err
|
||||
}
|
||||
|
||||
func updateRows(session *sqlstore.DBSession, rows []map[string][]byte, passwordFieldName string) (int, error) {
|
||||
|
@ -19,7 +19,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
|
||||
"github.com/grafana/grafana/pkg/cmd/grafana-cli/utils"
|
||||
"github.com/grafana/grafana/pkg/plugins/manager/installer"
|
||||
"github.com/grafana/grafana/pkg/util/errutil"
|
||||
|
||||
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
|
||||
)
|
||||
@ -147,7 +146,7 @@ func InstallPlugin(pluginName, version string, c utils.CommandLine, client utils
|
||||
res, _ := services.ReadPlugin(pluginFolder, pluginName)
|
||||
for _, v := range res.Dependencies.Plugins {
|
||||
if err := InstallPlugin(v.ID, "", c, client); err != nil {
|
||||
return errutil.Wrapf(err, "failed to install plugin '%s'", v.ID)
|
||||
return fmt.Errorf("failed to install plugin '%s': %w", v.ID, err)
|
||||
}
|
||||
|
||||
logger.Infof("Installed dependency: %v ✔\n", v.ID)
|
||||
@ -313,7 +312,7 @@ func extractSymlink(file *zip.File, filePath string) error {
|
||||
return fmt.Errorf("%v: %w", "failed to copy symlink contents", err)
|
||||
}
|
||||
if err := os.Symlink(strings.TrimSpace(buf.String()), filePath); err != nil {
|
||||
return errutil.Wrapf(err, "failed to make symbolic link for %v", filePath)
|
||||
return fmt.Errorf("failed to make symbolic link for %v: %w", filePath, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
"github.com/grafana/grafana/pkg/util/errutil"
|
||||
)
|
||||
|
||||
const AdminUserId = 1
|
||||
@ -57,7 +56,7 @@ func resetPasswordCommand(c utils.CommandLine, sqlStore *sqlstore.SQLStore) erro
|
||||
}
|
||||
|
||||
if err := sqlStore.ChangeUserPassword(context.Background(), &cmd); err != nil {
|
||||
return errutil.Wrapf(err, "failed to update user password")
|
||||
return fmt.Errorf("failed to update user password: %w", err)
|
||||
}
|
||||
|
||||
logger.Infof("\n")
|
||||
|
@ -1,11 +1,12 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
|
||||
"github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
|
||||
"github.com/grafana/grafana/pkg/cmd/grafana-cli/utils"
|
||||
"github.com/grafana/grafana/pkg/util/errutil"
|
||||
)
|
||||
|
||||
func (cmd Command) upgradeCommand(c utils.CommandLine) error {
|
||||
@ -25,7 +26,7 @@ func (cmd Command) upgradeCommand(c utils.CommandLine) error {
|
||||
|
||||
if shouldUpgrade(localPlugin.Info.Version, &plugin) {
|
||||
if err := services.RemoveInstalledPlugin(pluginsDir, pluginName); err != nil {
|
||||
return errutil.Wrapf(err, "failed to remove plugin '%s'", pluginName)
|
||||
return fmt.Errorf("failed to remove plugin '%s': %w", pluginName, err)
|
||||
}
|
||||
|
||||
return InstallPlugin(pluginName, "", c, cmd.Client)
|
||||
|
@ -16,7 +16,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/migrator"
|
||||
"github.com/grafana/grafana/pkg/util/errutil"
|
||||
)
|
||||
|
||||
type file struct {
|
||||
@ -480,7 +479,7 @@ func (s dbFileStorage) CreateFolder(ctx context.Context, path string) error {
|
||||
|
||||
if insertErr != nil {
|
||||
if rollErr := sess.Rollback(); rollErr != nil {
|
||||
return errutil.Wrapf(insertErr, "Rolling back transaction due to error failed: %s", rollErr)
|
||||
return fmt.Errorf("rolling back transaction due to error failed: %s: %w", rollErr, insertErr)
|
||||
}
|
||||
return insertErr
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/infra/log/level"
|
||||
"github.com/grafana/grafana/pkg/infra/log/term"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
"github.com/grafana/grafana/pkg/util/errutil"
|
||||
"github.com/mattn/go-isatty"
|
||||
"gopkg.in/ini.v1"
|
||||
)
|
||||
@ -392,7 +391,7 @@ func ReadLoggingConfig(modes []string, logsPath string, cfg *ini.File) error {
|
||||
sec, err := cfg.GetSection("log." + mode)
|
||||
if err != nil {
|
||||
_ = level.Error(root).Log("Unknown log mode", "mode", mode)
|
||||
return errutil.Wrapf(err, "failed to get config section log.%s", mode)
|
||||
return fmt.Errorf("failed to get config section log. %s: %w", mode, err)
|
||||
}
|
||||
|
||||
// Log level.
|
||||
|
@ -10,7 +10,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/util/errutil"
|
||||
|
||||
"golang.org/x/oauth2"
|
||||
"gopkg.in/square/go-jose.v2/jwt"
|
||||
@ -58,12 +57,12 @@ func (s *SocialAzureAD) UserInfo(client *http.Client, token *oauth2.Token) (*Bas
|
||||
|
||||
parsedToken, err := jwt.ParseSigned(idToken.(string))
|
||||
if err != nil {
|
||||
return nil, errutil.Wrapf(err, "error parsing id token")
|
||||
return nil, fmt.Errorf("error parsing id token: %w", err)
|
||||
}
|
||||
|
||||
var claims azureClaims
|
||||
if err := parsedToken.UnsafeClaimsWithoutVerification(&claims); err != nil {
|
||||
return nil, errutil.Wrapf(err, "error getting claims from id token")
|
||||
return nil, fmt.Errorf("error getting claims from id token: %w", err)
|
||||
}
|
||||
|
||||
email := extractEmail(claims)
|
||||
@ -186,12 +185,12 @@ func extractGroups(client *http.Client, claims azureClaims, token *oauth2.Token)
|
||||
// See https://docs.microsoft.com/en-us/graph/migrate-azure-ad-graph-overview
|
||||
parsedToken, err := jwt.ParseSigned(token.AccessToken)
|
||||
if err != nil {
|
||||
return nil, errutil.Wrapf(err, "error parsing id token")
|
||||
return nil, fmt.Errorf("error parsing id token: %w", err)
|
||||
}
|
||||
|
||||
var accessClaims azureAccessClaims
|
||||
if err := parsedToken.UnsafeClaimsWithoutVerification(&accessClaims); err != nil {
|
||||
return nil, errutil.Wrapf(err, "error getting claims from access token")
|
||||
return nil, fmt.Errorf("error getting claims from access token: %w", err)
|
||||
}
|
||||
endpoint = fmt.Sprintf("https://graph.microsoft.com/v1.0/%s/users/%s/getMemberObjects", accessClaims.TenantID, claims.ID)
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/grafana/grafana/pkg/util/errutil"
|
||||
"github.com/jmespath/go-jmespath"
|
||||
)
|
||||
|
||||
@ -88,7 +87,7 @@ func (s *SocialBase) searchJSONForAttr(attributePath string, data []byte) (inter
|
||||
|
||||
val, err := jmespath.Search(attributePath, buf)
|
||||
if err != nil {
|
||||
return "", errutil.Wrapf(err, "failed to search user info JSON response with provided path: %q", attributePath)
|
||||
return "", fmt.Errorf("failed to search user info JSON response with provided path: %q: %w", attributePath, err)
|
||||
}
|
||||
|
||||
return val, nil
|
||||
|
@ -7,7 +7,6 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/util/errutil"
|
||||
"golang.org/x/oauth2"
|
||||
"gopkg.in/square/go-jose.v2/jwt"
|
||||
)
|
||||
@ -59,12 +58,12 @@ func (s *SocialOkta) UserInfo(client *http.Client, token *oauth2.Token) (*BasicU
|
||||
|
||||
parsedToken, err := jwt.ParseSigned(idToken.(string))
|
||||
if err != nil {
|
||||
return nil, errutil.Wrapf(err, "error parsing id token")
|
||||
return nil, fmt.Errorf("error parsing id token: %w", err)
|
||||
}
|
||||
|
||||
var claims OktaClaims
|
||||
if err := parsedToken.UnsafeClaimsWithoutVerification(&claims); err != nil {
|
||||
return nil, errutil.Wrapf(err, "error getting claims from id token")
|
||||
return nil, fmt.Errorf("error getting claims from id token: %w", err)
|
||||
}
|
||||
|
||||
email := claims.extractEmail()
|
||||
@ -105,7 +104,7 @@ func (s *SocialOkta) extractAPI(data *OktaUserInfoJson, client *http.Client) err
|
||||
rawUserInfoResponse, err := s.httpGet(client, s.apiUrl)
|
||||
if err != nil {
|
||||
s.log.Debug("Error getting user info response", "url", s.apiUrl, "error", err)
|
||||
return errutil.Wrapf(err, "error getting user info response")
|
||||
return fmt.Errorf("error getting user info response: %w", err)
|
||||
}
|
||||
data.rawJSON = rawUserInfoResponse.Body
|
||||
|
||||
@ -113,7 +112,7 @@ func (s *SocialOkta) extractAPI(data *OktaUserInfoJson, client *http.Client) err
|
||||
if err != nil {
|
||||
s.log.Debug("Error decoding user info response", "raw_json", data.rawJSON, "error", err)
|
||||
data.rawJSON = []byte{}
|
||||
return errutil.Wrapf(err, "error decoding user info response")
|
||||
return fmt.Errorf("error decoding user info response: %w", err)
|
||||
}
|
||||
|
||||
s.log.Debug("Received user info response", "raw_json", string(data.rawJSON), "data", data)
|
||||
|
@ -24,7 +24,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
"github.com/grafana/grafana/pkg/util/errutil"
|
||||
)
|
||||
|
||||
type Installer struct {
|
||||
@ -170,7 +169,7 @@ func (i *Installer) Install(ctx context.Context, pluginID, version, pluginsDir,
|
||||
for _, dep := range res.Dependencies.Plugins {
|
||||
i.log.Infof("Fetching %s dependencies...", res.ID)
|
||||
if err := i.Install(ctx, dep.ID, normalizeVersion(dep.Version), pluginsDir, "", pluginRepoURL); err != nil {
|
||||
return errutil.Wrapf(err, "failed to install plugin %s", dep.ID)
|
||||
return fmt.Errorf("failed to install plugin %s: %w", dep.ID, err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -609,7 +608,7 @@ func extractSymlink(file *zip.File, filePath string) error {
|
||||
return fmt.Errorf("%v: %w", "failed to copy symlink contents", err)
|
||||
}
|
||||
if err := os.Symlink(strings.TrimSpace(buf.String()), filePath); err != nil {
|
||||
return errutil.Wrapf(err, "failed to make symbolic link for %v", filePath)
|
||||
return fmt.Errorf("failed to make symbolic link for %v: %w", filePath, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -17,7 +17,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/alerting"
|
||||
"github.com/grafana/grafana/pkg/util/errutil"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -221,8 +220,8 @@ func (c *QueryCondition) executeQuery(context *alerting.EvalContext, timeRange l
|
||||
for _, frame := range frames {
|
||||
ss, err := FrameToSeriesSlice(frame)
|
||||
if err != nil {
|
||||
return nil, errutil.Wrapf(err,
|
||||
`request handler failed to convert dataframe "%v" to plugins.DataTimeSeriesSlice`, frame.Name)
|
||||
return nil, fmt.Errorf(
|
||||
`request handler failed to convert dataframe "%v" to plugins.DataTimeSeriesSlice: %w`, frame.Name, err)
|
||||
}
|
||||
result = append(result, ss...)
|
||||
}
|
||||
@ -399,8 +398,8 @@ func FrameToSeriesSlice(frame *data.Frame) (legacydata.DataTimeSeriesSlice, erro
|
||||
for rowIdx := 0; rowIdx < field.Len(); rowIdx++ { // for each value in the field, make a TimePoint
|
||||
val, err := field.FloatAt(rowIdx)
|
||||
if err != nil {
|
||||
return nil, errutil.Wrapf(err,
|
||||
"failed to convert frame to DataTimeSeriesSlice, can not convert value %v to float", field.At(rowIdx))
|
||||
return nil, fmt.Errorf(
|
||||
"failed to convert frame to DataTimeSeriesSlice, can not convert value %v to float: %w", field.At(rowIdx), err)
|
||||
}
|
||||
ts.Points[rowIdx] = legacydata.DataTimePoint{
|
||||
null.FloatFrom(val),
|
||||
|
@ -2,11 +2,11 @@ package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
"github.com/grafana/grafana/pkg/util/errutil"
|
||||
)
|
||||
|
||||
// retrieves public dashboard configuration
|
||||
@ -136,7 +136,7 @@ func (d *DashboardStore) SavePublicDashboardConfig(cmd models.SavePublicDashboar
|
||||
} else {
|
||||
uid, err := generateNewPublicDashboardUid(sess)
|
||||
if err != nil {
|
||||
return errutil.Wrapf(err, "Failed to generate UID for public dashboard")
|
||||
return fmt.Errorf("failed to generate UID for public dashboard: %w", err)
|
||||
}
|
||||
cmd.PublicDashboardConfig.PublicDashboard.Uid = uid
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/util/errutil"
|
||||
gomail "gopkg.in/mail.v2"
|
||||
)
|
||||
|
||||
@ -49,7 +48,7 @@ func (sc *SmtpClient) Send(messages ...*Message) (int, error) {
|
||||
emailsSentFailed.Inc()
|
||||
}
|
||||
|
||||
err = errutil.Wrapf(innerError, "Failed to send notification to email addresses: %s", strings.Join(msg.To, ";"))
|
||||
err = fmt.Errorf("failed to send notification to email addresses: %s: %w", strings.Join(msg.To, ";"), innerError)
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/provisioning/utils"
|
||||
"github.com/grafana/grafana/pkg/util/errutil"
|
||||
)
|
||||
|
||||
// DashboardProvisioner is responsible for syncing dashboard from disk to
|
||||
@ -70,7 +69,7 @@ func (provider *Provisioner) Provision(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
return errutil.Wrapf(err, "Failed to provision config %v", reader.Cfg.Name)
|
||||
return fmt.Errorf("failed to provision config %v: %w", reader.Cfg.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -132,7 +131,7 @@ func getFileReaders(
|
||||
case "file":
|
||||
fileReader, err := NewDashboardFileReader(config, logger.New("type", config.Type, "name", config.Name), service, store)
|
||||
if err != nil {
|
||||
return nil, errutil.Wrapf(err, "Failed to create file reader for config %v", config.Name)
|
||||
return nil, fmt.Errorf("failed to create file reader for config %v: %w", config.Name, err)
|
||||
}
|
||||
readers = append(readers, fileReader)
|
||||
default:
|
||||
|
@ -15,7 +15,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
ac "github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
"github.com/grafana/grafana/pkg/util/errutil"
|
||||
)
|
||||
|
||||
// GetDataSource adds a datasource to the query model by querying by org_id as well as
|
||||
@ -146,7 +145,7 @@ func (ss *SQLStore) AddDataSource(ctx context.Context, cmd *models.AddDataSource
|
||||
if cmd.Uid == "" {
|
||||
uid, err := generateNewDatasourceUid(sess, cmd.OrgId)
|
||||
if err != nil {
|
||||
return errutil.Wrapf(err, "Failed to generate UID for datasource %q", cmd.Name)
|
||||
return fmt.Errorf("failed to generate UID for datasource %q: %w", cmd.Name, err)
|
||||
}
|
||||
cmd.Uid = uid
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/util/errutil"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -238,7 +237,7 @@ func (mg *Migrator) InTransaction(callback dbTransactionFunc) error {
|
||||
|
||||
if err := callback(sess); err != nil {
|
||||
if rollErr := sess.Rollback(); rollErr != nil {
|
||||
return errutil.Wrapf(err, "failed to roll back transaction due to error: %s", rollErr)
|
||||
return fmt.Errorf("failed to roll back transaction due to error: %s: %w", rollErr, err)
|
||||
}
|
||||
|
||||
return err
|
||||
|
@ -10,7 +10,6 @@ import (
|
||||
"github.com/VividCortex/mysqlerr"
|
||||
"github.com/go-sql-driver/mysql"
|
||||
"github.com/golang-migrate/migrate/v4/database"
|
||||
"github.com/grafana/grafana/pkg/util/errutil"
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
@ -141,7 +140,7 @@ func (db *MySQLDialect) CleanDB() error {
|
||||
return fmt.Errorf("%v: %w", "failed to disable foreign key checks", err)
|
||||
}
|
||||
if _, err := sess.Exec("drop table " + table.Name + " ;"); err != nil {
|
||||
return errutil.Wrapf(err, "failed to delete table %q", table.Name)
|
||||
return fmt.Errorf("failed to delete table %q: %w", table.Name, err)
|
||||
}
|
||||
if _, err := sess.Exec("set foreign_key_checks = 1"); err != nil {
|
||||
return fmt.Errorf("%v: %w", "failed to disable foreign key checks", err)
|
||||
@ -169,14 +168,14 @@ func (db *MySQLDialect) TruncateDBTables() error {
|
||||
case "dashboard_acl":
|
||||
// keep default dashboard permissions
|
||||
if _, err := sess.Exec(fmt.Sprintf("DELETE FROM %v WHERE dashboard_id != -1 AND org_id != -1;", db.Quote(table.Name))); err != nil {
|
||||
return errutil.Wrapf(err, "failed to truncate table %q", table.Name)
|
||||
return fmt.Errorf("failed to truncate table %q: %w", table.Name, err)
|
||||
}
|
||||
if _, err := sess.Exec(fmt.Sprintf("ALTER TABLE %v AUTO_INCREMENT = 3;", db.Quote(table.Name))); err != nil {
|
||||
return errutil.Wrapf(err, "failed to reset table %q", table.Name)
|
||||
return fmt.Errorf("failed to reset table %q: %w", table.Name, err)
|
||||
}
|
||||
default:
|
||||
if _, err := sess.Exec(fmt.Sprintf("TRUNCATE TABLE %v;", db.Quote(table.Name))); err != nil {
|
||||
return errutil.Wrapf(err, "failed to truncate table %q", table.Name)
|
||||
return fmt.Errorf("failed to truncate table %q: %w", table.Name, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ import (
|
||||
"github.com/golang-migrate/migrate/v4/database"
|
||||
"github.com/lib/pq"
|
||||
|
||||
"github.com/grafana/grafana/pkg/util/errutil"
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
@ -162,17 +161,17 @@ func (db *PostgresDialect) TruncateDBTables() error {
|
||||
case "dashboard_acl":
|
||||
// keep default dashboard permissions
|
||||
if _, err := sess.Exec(fmt.Sprintf("DELETE FROM %v WHERE dashboard_id != -1 AND org_id != -1;", db.Quote(table.Name))); err != nil {
|
||||
return errutil.Wrapf(err, "failed to truncate table %q", table.Name)
|
||||
return fmt.Errorf("failed to truncate table %q: %w", table.Name, err)
|
||||
}
|
||||
if _, err := sess.Exec(fmt.Sprintf("ALTER SEQUENCE %v RESTART WITH 3;", db.Quote(fmt.Sprintf("%v_id_seq", table.Name)))); err != nil {
|
||||
return errutil.Wrapf(err, "failed to reset table %q", table.Name)
|
||||
return fmt.Errorf("failed to reset table %q: %w", table.Name, err)
|
||||
}
|
||||
default:
|
||||
if _, err := sess.Exec(fmt.Sprintf("TRUNCATE TABLE %v RESTART IDENTITY CASCADE;", db.Quote(table.Name))); err != nil {
|
||||
if db.isUndefinedTable(err) {
|
||||
continue
|
||||
}
|
||||
return errutil.Wrapf(err, "failed to truncate table %q", table.Name)
|
||||
return fmt.Errorf("failed to truncate table %q: %w", table.Name, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -218,7 +217,7 @@ func (db *PostgresDialect) PostInsertId(table string, sess *xorm.Session) error
|
||||
|
||||
// sync primary key sequence of org table
|
||||
if _, err := sess.Exec("SELECT setval('org_id_seq', (SELECT max(id) FROM org));"); err != nil {
|
||||
return errutil.Wrapf(err, "failed to sync primary key for org table")
|
||||
return fmt.Errorf("failed to sync primary key for org table: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/grafana/grafana/pkg/util/errutil"
|
||||
"github.com/mattn/go-sqlite3"
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
@ -106,19 +105,19 @@ func (db *SQLite3) TruncateDBTables() error {
|
||||
case "dashboard_acl":
|
||||
// keep default dashboard permissions
|
||||
if _, err := sess.Exec(fmt.Sprintf("DELETE FROM %q WHERE dashboard_id != -1 AND org_id != -1;", table.Name)); err != nil {
|
||||
return errutil.Wrapf(err, "failed to truncate table %q", table.Name)
|
||||
return fmt.Errorf("failed to truncate table %q: %w", table.Name, err)
|
||||
}
|
||||
if _, err := sess.Exec("UPDATE sqlite_sequence SET seq = 2 WHERE name = '%s';", table.Name); err != nil {
|
||||
return errutil.Wrapf(err, "failed to cleanup sqlite_sequence")
|
||||
return fmt.Errorf("failed to cleanup sqlite_sequence: %w", err)
|
||||
}
|
||||
default:
|
||||
if _, err := sess.Exec(fmt.Sprintf("DELETE FROM %s;", table.Name)); err != nil {
|
||||
return errutil.Wrapf(err, "failed to truncate table %q", table.Name)
|
||||
return fmt.Errorf("failed to truncate table %q: %w", table.Name, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
if _, err := sess.Exec("UPDATE sqlite_sequence SET seq = 0 WHERE name != 'dashboard_acl';"); err != nil {
|
||||
return errutil.Wrapf(err, "failed to cleanup sqlite_sequence")
|
||||
return fmt.Errorf("failed to cleanup sqlite_sequence: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -28,7 +28,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/sqlutil"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
"github.com/grafana/grafana/pkg/util/errutil"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -265,7 +264,7 @@ func (ss *SQLStore) buildConnectionString() (string, error) {
|
||||
case migrator.Postgres:
|
||||
addr, err := util.SplitHostPortDefault(ss.dbCfg.Host, "127.0.0.1", "5432")
|
||||
if err != nil {
|
||||
return "", errutil.Wrapf(err, "Invalid host specifier '%s'", ss.dbCfg.Host)
|
||||
return "", fmt.Errorf("invalid host specifier '%s': %w", ss.dbCfg.Host, err)
|
||||
}
|
||||
|
||||
if ss.dbCfg.Pwd == "" {
|
||||
@ -318,7 +317,7 @@ func (ss *SQLStore) initEngine(engine *xorm.Engine) error {
|
||||
!strings.HasPrefix(connectionString, "file::memory:") {
|
||||
exists, err := fs.Exists(ss.dbCfg.Path)
|
||||
if err != nil {
|
||||
return errutil.Wrapf(err, "can't check for existence of %q", ss.dbCfg.Path)
|
||||
return fmt.Errorf("can't check for existence of %q: %w", ss.dbCfg.Path, err)
|
||||
}
|
||||
|
||||
const perms = 0640
|
||||
@ -326,15 +325,15 @@ func (ss *SQLStore) initEngine(engine *xorm.Engine) error {
|
||||
ss.log.Info("Creating SQLite database file", "path", ss.dbCfg.Path)
|
||||
f, err := os.OpenFile(ss.dbCfg.Path, os.O_CREATE|os.O_RDWR, perms)
|
||||
if err != nil {
|
||||
return errutil.Wrapf(err, "failed to create SQLite database file %q", ss.dbCfg.Path)
|
||||
return fmt.Errorf("failed to create SQLite database file %q: %w", ss.dbCfg.Path, err)
|
||||
}
|
||||
if err := f.Close(); err != nil {
|
||||
return errutil.Wrapf(err, "failed to create SQLite database file %q", ss.dbCfg.Path)
|
||||
return fmt.Errorf("failed to create SQLite database file %q: %w", ss.dbCfg.Path, err)
|
||||
}
|
||||
} else {
|
||||
fi, err := os.Lstat(ss.dbCfg.Path)
|
||||
if err != nil {
|
||||
return errutil.Wrapf(err, "failed to stat SQLite database file %q", ss.dbCfg.Path)
|
||||
return fmt.Errorf("failed to stat SQLite database file %q: %w", ss.dbCfg.Path, err)
|
||||
}
|
||||
m := fi.Mode() & os.ModePerm
|
||||
if m|perms != perms {
|
||||
|
@ -11,7 +11,6 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/util/errutil"
|
||||
)
|
||||
|
||||
var tsclogger = log.New("sqlstore.transactions")
|
||||
@ -63,7 +62,7 @@ func inTransactionWithRetryCtx(ctx context.Context, engine *xorm.Engine, callbac
|
||||
var sqlError sqlite3.Error
|
||||
if errors.As(err, &sqlError) && retry < 5 && (sqlError.Code == sqlite3.ErrLocked || sqlError.Code == sqlite3.ErrBusy) {
|
||||
if rollErr := sess.Rollback(); rollErr != nil {
|
||||
return errutil.Wrapf(err, "Rolling back transaction due to error failed: %s", rollErr)
|
||||
return fmt.Errorf("rolling back transaction due to error failed: %s: %w", rollErr, err)
|
||||
}
|
||||
|
||||
time.Sleep(time.Millisecond * time.Duration(10))
|
||||
@ -73,7 +72,7 @@ func inTransactionWithRetryCtx(ctx context.Context, engine *xorm.Engine, callbac
|
||||
|
||||
if err != nil {
|
||||
if rollErr := sess.Rollback(); rollErr != nil {
|
||||
return errutil.Wrapf(err, "Rolling back transaction due to error failed: %s", rollErr)
|
||||
return fmt.Errorf("rolling back transaction due to error failed: %s: %w", rollErr, err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ import (
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
"github.com/grafana/grafana-plugin-sdk-go/data"
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
"github.com/grafana/grafana/pkg/util/errutil"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
@ -120,7 +119,7 @@ func (e *cloudWatchExecutor) executeLogAction(ctx context.Context, model *simple
|
||||
data, err = e.handleGetLogEvents(ctx, logsClient, model)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, errutil.Wrapf(err, "failed to execute log action with subtype: %s", subType)
|
||||
return nil, fmt.Errorf("failed to execute log action with subtype: %s: %w", subType, err)
|
||||
}
|
||||
|
||||
return data, nil
|
||||
|
@ -16,7 +16,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/tsdb/sqleng"
|
||||
"github.com/grafana/grafana/pkg/util/errutil"
|
||||
)
|
||||
|
||||
var logger = log.New("tsdb.postgres")
|
||||
@ -131,7 +130,7 @@ func (s *Service) generateConnectionString(dsInfo sqleng.DataSourceInfo) (string
|
||||
var err error
|
||||
port, err = strconv.Atoi(sp[1])
|
||||
if err != nil {
|
||||
return "", errutil.Wrapf(err, "invalid port in host specifier %q", sp[1])
|
||||
return "", fmt.Errorf("invalid port in host specifier %q: %w", sp[1], err)
|
||||
}
|
||||
|
||||
logger.Debug("Generating connection string with network host/port pair", "host", host, "port", port)
|
||||
@ -144,7 +143,7 @@ func (s *Service) generateConnectionString(dsInfo sqleng.DataSourceInfo) (string
|
||||
var err error
|
||||
port, err = strconv.Atoi(dsInfo.URL[index+1:])
|
||||
if err != nil {
|
||||
return "", errutil.Wrapf(err, "invalid port in host specifier %q", dsInfo.URL[index+1:])
|
||||
return "", fmt.Errorf("invalid port in host specifier %q: %w", dsInfo.URL[index+1:], err)
|
||||
}
|
||||
|
||||
logger.Debug("Generating ipv6 connection string with network host/port pair", "host", host, "port", port)
|
||||
|
@ -14,7 +14,6 @@ import (
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
"github.com/grafana/grafana-plugin-sdk-go/data"
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
"github.com/grafana/grafana/pkg/util/errutil"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -787,7 +786,7 @@ func predictableCSVWave(query backend.DataQuery, model *simplejson.Json) ([]*dat
|
||||
default:
|
||||
f, err := strconv.ParseFloat(rawValue, 64)
|
||||
if err != nil {
|
||||
return nil, errutil.Wrapf(err, "failed to parse value '%v' into nullable float", rawValue)
|
||||
return nil, fmt.Errorf("failed to parse value '%v' into nullable float: %w", rawValue, err)
|
||||
}
|
||||
val = &f
|
||||
}
|
||||
|
@ -1,24 +0,0 @@
|
||||
package errutil
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Wrap is a simple wrapper around fmt.Errorf that wraps errors.
|
||||
func Wrap(message string, err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("%v: %w", message, err)
|
||||
}
|
||||
|
||||
// Wrapf is a simple wrapper around fmt.Errorf that wraps errors.
|
||||
// Wrapf allows you to send a format and args instead of just a message.
|
||||
func Wrapf(err error, message string, a ...interface{}) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return Wrap(fmt.Sprintf(message, a...), err)
|
||||
}
|
@ -4,8 +4,6 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
"github.com/grafana/grafana/pkg/util/errutil"
|
||||
)
|
||||
|
||||
type NetworkAddress struct {
|
||||
@ -43,7 +41,7 @@ func SplitHostPortDefault(input, defaultHost, defaultPort string) (NetworkAddres
|
||||
|
||||
host, port, err := net.SplitHostPort(input)
|
||||
if err != nil {
|
||||
return addr, errutil.Wrapf(err, "net.SplitHostPort failed for '%s'", input)
|
||||
return addr, fmt.Errorf("net.SplitHostPort failed for '%s': %w", input, err)
|
||||
}
|
||||
|
||||
if len(host) > 0 {
|
||||
|
Loading…
Reference in New Issue
Block a user