Chore: Drop xerrors dependency (#26718)

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
Arve Knudsen
2020-07-31 09:45:20 +02:00
committed by GitHub
parent 5a6afd9096
commit 16c185c3b9
20 changed files with 79 additions and 61 deletions
@@ -17,7 +17,6 @@ import (
"github.com/fatih/color"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/utils"
"github.com/grafana/grafana/pkg/util/errutil"
"golang.org/x/xerrors"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/models"
@@ -180,7 +179,7 @@ func SelectVersion(plugin *models.Plugin, version string) (*models.Version, erro
latestForArch := latestSupportedVersion(plugin)
if latestForArch == nil {
return nil, xerrors.New("plugin is not supported on your architecture and OS.")
return nil, fmt.Errorf("plugin is not supported on your architecture and OS")
}
if version == "" {
@@ -194,11 +193,13 @@ func SelectVersion(plugin *models.Plugin, version string) (*models.Version, erro
}
if len(ver.Version) == 0 {
return nil, xerrors.New("could not find the version you're looking for")
return nil, fmt.Errorf("could not find the version you're looking for")
}
if !supportsCurrentArch(&ver) {
return nil, xerrors.Errorf("the version you want is not supported on your architecture and OS. Latest suitable version is %s", latestForArch.Version)
return nil, fmt.Errorf(
"the version you want is not supported on your architecture and OS, latest suitable version is %s",
latestForArch.Version)
}
return &ver, nil
@@ -209,7 +210,7 @@ func RemoveGitBuildFromName(pluginName, filename string) string {
return r.ReplaceAllString(filename, pluginName+"/")
}
var permissionsDeniedMessage = "Could not create %s. Permission denied. Make sure you have write access to plugindir"
const permissionsDeniedMessage = "could not create %q, permission denied, make sure you have write access to plugin dir"
func extractFiles(archiveFile string, pluginName string, filePath string, allowSymlinks bool) error {
logger.Debugf("Extracting archive %v to %v...\n", archiveFile, filePath)
@@ -221,7 +222,8 @@ func extractFiles(archiveFile string, pluginName string, filePath string, allowS
for _, zf := range r.File {
newFileName := RemoveGitBuildFromName(pluginName, zf.Name)
if !isPathSafe(newFileName, filepath.Join(filePath, pluginName)) {
return xerrors.Errorf("filepath: %q tries to write outside of plugin directory: %q. This can be a security risk.", zf.Name, path.Join(filePath, pluginName))
return fmt.Errorf("filepath: %q tries to write outside of plugin directory: %q, this can be a security risk",
zf.Name, filepath.Join(filePath, pluginName))
}
newFile := path.Join(filePath, newFileName)
@@ -285,12 +287,12 @@ func extractFile(file *zip.File, filePath string) (err error) {
dst, err := os.OpenFile(filePath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, fileMode)
if err != nil {
if os.IsPermission(err) {
return xerrors.Errorf(permissionsDeniedMessage, filePath)
return fmt.Errorf(permissionsDeniedMessage, filePath)
}
unwrappedError := xerrors.Unwrap(err)
unwrappedError := errors.Unwrap(err)
if unwrappedError != nil && strings.EqualFold(unwrappedError.Error(), "text file busy") {
return fmt.Errorf("file %s is in use. Please stop Grafana, install the plugin and restart Grafana", filePath)
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)
+2 -3
View File
@@ -16,7 +16,6 @@ import (
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/models"
"github.com/grafana/grafana/pkg/util/errutil"
"golang.org/x/xerrors"
)
type GrafanaComClient struct {
@@ -78,7 +77,7 @@ func (client *GrafanaComClient) DownloadFile(pluginName string, tmpFile *os.File
client.retryCount = 0
failure := fmt.Sprintf("%v", r)
if failure == "runtime error: makeslice: len out of range" {
err = xerrors.New("Corrupt http response from source. Please try again")
err = fmt.Errorf("corrupt HTTP response from source, please try again")
} else {
panic(r)
}
@@ -101,7 +100,7 @@ func (client *GrafanaComClient) DownloadFile(pluginName string, tmpFile *os.File
}
w.Flush()
if len(checksum) > 0 && checksum != fmt.Sprintf("%x", h.Sum(nil)) {
return xerrors.New("Expected MD5 checksum does not match the downloaded archive. Please contact security@grafana.com.")
return fmt.Errorf("expected MD5 checksum does not match the downloaded archive - please contact security@grafana.com")
}
return nil
}
+2 -2
View File
@@ -6,7 +6,7 @@ import (
"path/filepath"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
"golang.org/x/xerrors"
"github.com/grafana/grafana/pkg/util/errutil"
)
func GetGrafanaPluginDir(currentOS string) string {
@@ -23,7 +23,7 @@ func GetGrafanaPluginDir(currentOS string) string {
func getGrafanaRoot() (string, error) {
ex, err := os.Executable()
if err != nil {
return "", xerrors.New("Failed to get executable path")
return "", errutil.Wrap("failed to get executable path", err)
}
exPath := filepath.Dir(ex)
_, last := path.Split(exPath)
+3 -3
View File
@@ -2,6 +2,7 @@ package main
import (
"context"
"errors"
"flag"
"fmt"
"io/ioutil"
@@ -40,7 +41,6 @@ import (
_ "github.com/grafana/grafana/pkg/services/sqlstore"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/util/errutil"
"golang.org/x/xerrors"
)
// NewServer returns a new instance of Server.
@@ -147,7 +147,7 @@ func (s *Server) Run() (err error) {
defer func() {
s.log.Debug("Waiting on services...")
if waitErr := s.childRoutines.Wait(); waitErr != nil && !xerrors.Is(waitErr, context.Canceled) {
if waitErr := s.childRoutines.Wait(); waitErr != nil && !errors.Is(waitErr, context.Canceled) {
s.log.Error("A service failed", "err", waitErr)
if err == nil {
err = waitErr
@@ -169,7 +169,7 @@ func (s *Server) Shutdown(reason string) {
s.shutdownFn()
// wait for child routines
if err := s.childRoutines.Wait(); err != nil && !xerrors.Is(err, context.Canceled) {
if err := s.childRoutines.Wait(); err != nil && !errors.Is(err, context.Canceled) {
s.log.Error("Failed waiting for services to shutdown", "err", err)
}
}