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)