mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user