Chore: Remove Wrap (#50048)
* Chore: Remove Wrap and Wrapf * Fix: Add error check
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/fatih/color"
|
||||
@@ -14,7 +15,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/migrations"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/util/errutil"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
@@ -24,12 +24,12 @@ func runRunnerCommand(command func(commandLine utils.CommandLine, runner runner.
|
||||
|
||||
cfg, err := initCfg(cmd)
|
||||
if err != nil {
|
||||
return errutil.Wrap("failed to load configuration", err)
|
||||
return fmt.Errorf("%v: %w", "failed to load configuration", err)
|
||||
}
|
||||
|
||||
r, err := runner.Initialize(cfg)
|
||||
if err != nil {
|
||||
return errutil.Wrap("failed to initialize runner", err)
|
||||
return fmt.Errorf("%v: %w", "failed to initialize runner", err)
|
||||
}
|
||||
|
||||
if err := command(cmd, r); err != nil {
|
||||
@@ -47,17 +47,17 @@ func runDbCommand(command func(commandLine utils.CommandLine, sqlStore *sqlstore
|
||||
|
||||
cfg, err := initCfg(cmd)
|
||||
if err != nil {
|
||||
return errutil.Wrap("failed to load configuration", err)
|
||||
return fmt.Errorf("%v: %w", "failed to load configuration", err)
|
||||
}
|
||||
|
||||
tracer, err := tracing.ProvideService(cfg)
|
||||
if err != nil {
|
||||
return errutil.Wrap("failed to initialize tracer service", err)
|
||||
return fmt.Errorf("%v: %w", "failed to initialize tracer service", err)
|
||||
}
|
||||
|
||||
sqlStore, err := sqlstore.ProvideService(cfg, nil, &migrations.OSSMigrations{}, tracer)
|
||||
if err != nil {
|
||||
return errutil.Wrap("failed to initialize SQL store", err)
|
||||
return fmt.Errorf("%v: %w", "failed to initialize SQL store", err)
|
||||
}
|
||||
|
||||
if err := command(cmd, sqlStore); err != nil {
|
||||
|
||||
@@ -3,6 +3,7 @@ package datamigrations
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
|
||||
@@ -89,7 +90,7 @@ func updateRows(session *sqlstore.DBSession, rows []map[string][]byte, passwordF
|
||||
|
||||
data, err := json.Marshal(newSecureJSONData)
|
||||
if err != nil {
|
||||
return 0, errutil.Wrap("marshaling newSecureJsonData failed", err)
|
||||
return 0, fmt.Errorf("%v: %w", "marshaling newSecureJsonData failed", err)
|
||||
}
|
||||
|
||||
newRow := map[string]interface{}{"secure_json_data": data, passwordFieldName: ""}
|
||||
|
||||
@@ -117,7 +117,7 @@ func InstallPlugin(pluginName, version string, c utils.CommandLine, client utils
|
||||
// Create temp file for downloading zip file
|
||||
tmpFile, err := ioutil.TempFile("", "*.zip")
|
||||
if err != nil {
|
||||
return errutil.Wrap("failed to create temporary file", err)
|
||||
return fmt.Errorf("%v: %w", "failed to create temporary file", err)
|
||||
}
|
||||
defer func() {
|
||||
if err := os.Remove(tmpFile.Name()); err != nil {
|
||||
@@ -130,16 +130,16 @@ func InstallPlugin(pluginName, version string, c utils.CommandLine, client utils
|
||||
if err := tmpFile.Close(); err != nil {
|
||||
logger.Warn("Failed to close file", "err", err)
|
||||
}
|
||||
return errutil.Wrap("failed to download plugin archive", err)
|
||||
return fmt.Errorf("%v: %w", "failed to download plugin archive", err)
|
||||
}
|
||||
err = tmpFile.Close()
|
||||
if err != nil {
|
||||
return errutil.Wrap("failed to close tmp file", err)
|
||||
return fmt.Errorf("%v: %w", "failed to close tmp file", err)
|
||||
}
|
||||
|
||||
err = extractFiles(tmpFile.Name(), pluginName, pluginFolder, isInternal)
|
||||
if err != nil {
|
||||
return errutil.Wrap("failed to extract plugin archive", err)
|
||||
return fmt.Errorf("%v: %w", "failed to extract plugin archive", err)
|
||||
}
|
||||
|
||||
logger.Infof("%s Installed %s successfully \n", color.GreenString("✔"), pluginName)
|
||||
@@ -275,7 +275,7 @@ func extractFiles(archiveFile string, pluginName string, dstDir string, allowSym
|
||||
// We can ignore gosec G304 here since it makes sense to give all users read access
|
||||
// nolint:gosec
|
||||
if err := os.MkdirAll(filepath.Dir(dstPath), 0755); err != nil {
|
||||
return errutil.Wrap("failed to create directory to extract plugin files", err)
|
||||
return fmt.Errorf("%v: %w", "failed to create directory to extract plugin files", err)
|
||||
}
|
||||
|
||||
if isSymlink(zf) {
|
||||
@@ -291,7 +291,7 @@ func extractFiles(archiveFile string, pluginName string, dstDir string, allowSym
|
||||
}
|
||||
|
||||
if err := extractFile(zf, dstPath); err != nil {
|
||||
return errutil.Wrap("failed to extract file", err)
|
||||
return fmt.Errorf("%v: %w", "failed to extract file", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -306,11 +306,11 @@ func extractSymlink(file *zip.File, filePath string) error {
|
||||
// symlink target is the contents of the file
|
||||
src, err := file.Open()
|
||||
if err != nil {
|
||||
return errutil.Wrap("failed to extract file", err)
|
||||
return fmt.Errorf("%v: %w", "failed to extract file", err)
|
||||
}
|
||||
buf := new(bytes.Buffer)
|
||||
if _, err := io.Copy(buf, src); err != nil {
|
||||
return errutil.Wrap("failed to copy symlink contents", err)
|
||||
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)
|
||||
@@ -340,7 +340,7 @@ func extractFile(file *zip.File, filePath string) (err error) {
|
||||
return fmt.Errorf("file %q is in use - please stop Grafana, install the plugin and restart Grafana", filePath)
|
||||
}
|
||||
|
||||
return errutil.Wrap("failed to open file", err)
|
||||
return fmt.Errorf("%v: %w", "failed to open file", err)
|
||||
}
|
||||
defer func() {
|
||||
err = dst.Close()
|
||||
@@ -348,7 +348,7 @@ func extractFile(file *zip.File, filePath string) (err error) {
|
||||
|
||||
src, err := file.Open()
|
||||
if err != nil {
|
||||
return errutil.Wrap("failed to extract file", err)
|
||||
return fmt.Errorf("%v: %w", "failed to extract file", err)
|
||||
}
|
||||
defer func() {
|
||||
err = src.Close()
|
||||
|
||||
Reference in New Issue
Block a user