mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Remove Wrap (#50048)
* Chore: Remove Wrap and Wrapf * Fix: Add error check
This commit is contained in:
@@ -215,7 +215,7 @@ func (c *QueryCondition) executeQuery(context *alerting.EvalContext, timeRange l
|
||||
if useDataframes { // convert the dataframes to plugins.DataTimeSeries
|
||||
frames, err := v.Dataframes.Decoded()
|
||||
if err != nil {
|
||||
return nil, errutil.Wrap("request handler failed to unmarshal arrow dataframes from bytes", err)
|
||||
return nil, fmt.Errorf("%v: %w", "request handler failed to unmarshal arrow dataframes from bytes", err)
|
||||
}
|
||||
|
||||
for _, frame := range frames {
|
||||
|
||||
@@ -17,7 +17,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/guardian"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
"github.com/grafana/grafana/pkg/util/errutil"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -402,7 +401,7 @@ func (dr *DashboardServiceImpl) deleteDashboard(ctx context.Context, dashboardId
|
||||
if validateProvisionedDashboard {
|
||||
provisionedData, err := dr.GetProvisionedDashboardDataByDashboardID(dashboardId)
|
||||
if err != nil {
|
||||
return errutil.Wrap("failed to check if dashboard is provisioned", err)
|
||||
return fmt.Errorf("%v: %w", "failed to check if dashboard is provisioned", err)
|
||||
}
|
||||
|
||||
if provisionedData != nil {
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/util/errutil"
|
||||
)
|
||||
|
||||
// Config holds list of connections to LDAP
|
||||
@@ -123,18 +122,18 @@ func readConfig(configFile string) (*Config, error) {
|
||||
// We can ignore the gosec G304 warning on this one because `filename` comes from grafana configuration file
|
||||
fileBytes, err := ioutil.ReadFile(configFile)
|
||||
if err != nil {
|
||||
return nil, errutil.Wrap("Failed to load LDAP config file", err)
|
||||
return nil, fmt.Errorf("%v: %w", "Failed to load LDAP config file", err)
|
||||
}
|
||||
|
||||
// interpolate full toml string (it can contain ENV variables)
|
||||
stringContent, err := setting.ExpandVar(string(fileBytes))
|
||||
if err != nil {
|
||||
return nil, errutil.Wrap("Failed to expand variables", err)
|
||||
return nil, fmt.Errorf("%v: %w", "Failed to expand variables", err)
|
||||
}
|
||||
|
||||
_, err = toml.Decode(stringContent, result)
|
||||
if err != nil {
|
||||
return nil, errutil.Wrap("Failed to load LDAP config file", err)
|
||||
return nil, fmt.Errorf("%v: %w", "Failed to load LDAP config file", err)
|
||||
}
|
||||
|
||||
if len(result.Servers) == 0 {
|
||||
@@ -145,11 +144,11 @@ func readConfig(configFile string) (*Config, error) {
|
||||
for _, server := range result.Servers {
|
||||
err = assertNotEmptyCfg(server.SearchFilter, "search_filter")
|
||||
if err != nil {
|
||||
return nil, errutil.Wrap("Failed to validate SearchFilter section", err)
|
||||
return nil, fmt.Errorf("%v: %w", "Failed to validate SearchFilter section", err)
|
||||
}
|
||||
err = assertNotEmptyCfg(server.SearchBaseDNs, "search_base_dns")
|
||||
if err != nil {
|
||||
return nil, errutil.Wrap("Failed to validate SearchBaseDNs section", err)
|
||||
return nil, fmt.Errorf("%v: %w", "Failed to validate SearchBaseDNs section", err)
|
||||
}
|
||||
|
||||
for _, groupMap := range server.Groups {
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
"github.com/grafana/grafana/pkg/services/live/orgchannel"
|
||||
"github.com/grafana/grafana/pkg/services/live/pipeline"
|
||||
"github.com/grafana/grafana/pkg/util/errutil"
|
||||
|
||||
"github.com/centrifugal/centrifuge"
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
@@ -80,7 +79,7 @@ func (g *ContextGetter) GetPluginContext(ctx context.Context, user *models.Signe
|
||||
|
||||
ds, err := g.dataSourceCache.GetDatasourceByUID(ctx, datasourceUID, user, skipCache)
|
||||
if err != nil {
|
||||
return backend.PluginContext{}, false, errutil.Wrap("Failed to get datasource", err)
|
||||
return backend.PluginContext{}, false, fmt.Errorf("%v: %w", "Failed to get datasource", err)
|
||||
}
|
||||
return g.pluginContextProvider.GetWithDataSource(ctx, pluginID, user, ds)
|
||||
}
|
||||
|
||||
@@ -40,12 +40,12 @@ func New(ctx context.Context, configDirectory string, provisioner dashboards.Das
|
||||
cfgReader := &configReader{path: configDirectory, log: logger, orgStore: orgStore}
|
||||
configs, err := cfgReader.readConfig(ctx)
|
||||
if err != nil {
|
||||
return nil, errutil.Wrap("Failed to read dashboards config", err)
|
||||
return nil, fmt.Errorf("%v: %w", "Failed to read dashboards config", err)
|
||||
}
|
||||
|
||||
fileReaders, err := getFileReaders(configs, logger, provisioner, dashboardStore)
|
||||
if err != nil {
|
||||
return nil, errutil.Wrap("Failed to initialize file readers", err)
|
||||
return nil, fmt.Errorf("%v: %w", "Failed to initialize file readers", err)
|
||||
}
|
||||
|
||||
d := &Provisioner{
|
||||
|
||||
@@ -2,6 +2,7 @@ package provisioning
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
|
||||
@@ -21,7 +22,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/provisioning/utils"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/util/errutil"
|
||||
)
|
||||
|
||||
func ProvideService(cfg *setting.Cfg, sqlStore *sqlstore.SQLStore, pluginStore plugifaces.Store,
|
||||
@@ -161,7 +161,7 @@ func (ps *ProvisioningServiceImpl) Run(ctx context.Context) error {
|
||||
func (ps *ProvisioningServiceImpl) ProvisionDatasources(ctx context.Context) error {
|
||||
datasourcePath := filepath.Join(ps.Cfg.ProvisioningPath, "datasources")
|
||||
if err := ps.provisionDatasources(ctx, datasourcePath, ps.datasourceService, ps.SQLStore); err != nil {
|
||||
err = errutil.Wrap("Datasource provisioning error", err)
|
||||
err = fmt.Errorf("%v: %w", "Datasource provisioning error", err)
|
||||
ps.log.Error("Failed to provision data sources", "error", err)
|
||||
return err
|
||||
}
|
||||
@@ -171,7 +171,7 @@ func (ps *ProvisioningServiceImpl) ProvisionDatasources(ctx context.Context) err
|
||||
func (ps *ProvisioningServiceImpl) ProvisionPlugins(ctx context.Context) error {
|
||||
appPath := filepath.Join(ps.Cfg.ProvisioningPath, "plugins")
|
||||
if err := ps.provisionPlugins(ctx, appPath, ps.SQLStore, ps.pluginStore, ps.pluginsSettings); err != nil {
|
||||
err = errutil.Wrap("app provisioning error", err)
|
||||
err = fmt.Errorf("%v: %w", "app provisioning error", err)
|
||||
ps.log.Error("Failed to provision plugins", "error", err)
|
||||
return err
|
||||
}
|
||||
@@ -181,7 +181,7 @@ func (ps *ProvisioningServiceImpl) ProvisionPlugins(ctx context.Context) error {
|
||||
func (ps *ProvisioningServiceImpl) ProvisionNotifications(ctx context.Context) error {
|
||||
alertNotificationsPath := filepath.Join(ps.Cfg.ProvisioningPath, "notifiers")
|
||||
if err := ps.provisionNotifiers(ctx, alertNotificationsPath, ps.alertingService, ps.SQLStore, ps.EncryptionService, ps.NotificationService); err != nil {
|
||||
err = errutil.Wrap("Alert notification provisioning error", err)
|
||||
err = fmt.Errorf("%v: %w", "Alert notification provisioning error", err)
|
||||
ps.log.Error("Failed to provision alert notifications", "error", err)
|
||||
return err
|
||||
}
|
||||
@@ -192,7 +192,7 @@ func (ps *ProvisioningServiceImpl) ProvisionDashboards(ctx context.Context) erro
|
||||
dashboardPath := filepath.Join(ps.Cfg.ProvisioningPath, "dashboards")
|
||||
dashProvisioner, err := ps.newDashboardProvisioner(ctx, dashboardPath, ps.dashboardProvisioningService, ps.SQLStore, ps.dashboardService)
|
||||
if err != nil {
|
||||
return errutil.Wrap("Failed to create provisioner", err)
|
||||
return fmt.Errorf("%v: %w", "Failed to create provisioner", err)
|
||||
}
|
||||
|
||||
ps.mutex.Lock()
|
||||
@@ -205,7 +205,7 @@ func (ps *ProvisioningServiceImpl) ProvisionDashboards(ctx context.Context) erro
|
||||
if err != nil {
|
||||
// If we fail to provision with the new provisioner, the mutex will unlock and the polling will restart with the
|
||||
// old provisioner as we did not switch them yet.
|
||||
return errutil.Wrap("Failed to provision dashboards", err)
|
||||
return fmt.Errorf("%v: %w", "Failed to provision dashboards", err)
|
||||
}
|
||||
ps.dashboardProvisioner = dashProvisioner
|
||||
return nil
|
||||
|
||||
@@ -18,8 +18,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
|
||||
"github.com/grafana/grafana/pkg/util/errutil"
|
||||
)
|
||||
|
||||
// IntValue represents a string value in a YAML
|
||||
@@ -41,7 +39,10 @@ func (val *IntValue) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
}
|
||||
val.Raw = interpolated.raw
|
||||
val.value, err = strconv.Atoi(interpolated.value)
|
||||
return errutil.Wrap("cannot convert value int", err)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%v: %w", "cannot convert value int", err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// Value returns the wrapped int value
|
||||
|
||||
@@ -74,7 +74,7 @@ func (mg *Migrator) GetMigrationLog() (map[string]MigrationLog, error) {
|
||||
|
||||
exists, err := mg.DBEngine.IsTableExist(new(MigrationLog))
|
||||
if err != nil {
|
||||
return nil, errutil.Wrap("failed to check table existence", err)
|
||||
return nil, fmt.Errorf("%v: %w", "failed to check table existence", err)
|
||||
}
|
||||
if !exists {
|
||||
return logMap, nil
|
||||
@@ -169,7 +169,7 @@ func (mg *Migrator) run() (err error) {
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
return errutil.Wrap(fmt.Sprintf("migration failed (id = %s)", m.Id()), err)
|
||||
return fmt.Errorf("%v: %w", fmt.Sprintf("migration failed (id = %s)", m.Id()), err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -144,13 +144,13 @@ func (db *MySQLDialect) CleanDB() error {
|
||||
switch table.Name {
|
||||
default:
|
||||
if _, err := sess.Exec("set foreign_key_checks = 0"); err != nil {
|
||||
return errutil.Wrap("failed to disable foreign key checks", err)
|
||||
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)
|
||||
}
|
||||
if _, err := sess.Exec("set foreign_key_checks = 1"); err != nil {
|
||||
return errutil.Wrap("failed to disable foreign key checks", err)
|
||||
return fmt.Errorf("%v: %w", "failed to disable foreign key checks", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,11 +133,11 @@ func (db *PostgresDialect) CleanDB() error {
|
||||
defer sess.Close()
|
||||
|
||||
if _, err := sess.Exec("DROP SCHEMA public CASCADE;"); err != nil {
|
||||
return errutil.Wrap("failed to drop schema public", err)
|
||||
return fmt.Errorf("%v: %w", "failed to drop schema public", err)
|
||||
}
|
||||
|
||||
if _, err := sess.Exec("CREATE SCHEMA public;"); err != nil {
|
||||
return errutil.Wrap("failed to create schema public", err)
|
||||
return fmt.Errorf("%v: %w", "failed to create schema public", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -95,7 +95,7 @@ func newSQLStore(cfg *setting.Cfg, cacheService *localcache.CacheService, engine
|
||||
}
|
||||
|
||||
if err := ss.initEngine(engine); err != nil {
|
||||
return nil, errutil.Wrap("failed to connect to database", err)
|
||||
return nil, fmt.Errorf("%v: %w", "failed to connect to database", err)
|
||||
}
|
||||
|
||||
ss.Dialect = migrator.NewDialect(ss.engine)
|
||||
|
||||
Reference in New Issue
Block a user