cli/config: use stdlib errors

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-08-11 15:14:05 +02:00
parent 3b677449d8
commit 9b7ee0e201
2 changed files with 9 additions and 10 deletions

View File

@ -13,7 +13,6 @@ import (
"github.com/docker/cli/cli/config/configfile"
"github.com/docker/cli/cli/config/credentials"
"github.com/docker/cli/cli/config/types"
"github.com/pkg/errors"
)
const (
@ -101,7 +100,7 @@ func SetDir(dir string) {
func Path(p ...string) (string, error) {
path := filepath.Join(append([]string{Dir()}, p...)...)
if !strings.HasPrefix(path, Dir()+string(filepath.Separator)) {
return "", errors.Errorf("path %q is outside of root config directory %q", path, Dir())
return "", fmt.Errorf("path %q is outside of root config directory %q", path, Dir())
}
return path, nil
}
@ -143,12 +142,12 @@ func load(configDir string) (*configfile.ConfigFile, error) {
return configFile, nil
}
// Any other error happening when failing to read the file must be returned.
return configFile, errors.Wrap(err, "loading config file")
return configFile, fmt.Errorf("loading config file: %w", err)
}
defer file.Close()
defer func() { _ = file.Close() }()
err = configFile.LoadFromReader(file)
if err != nil {
err = errors.Wrapf(err, "parsing config file (%s)", filename)
err = fmt.Errorf("parsing config file (%s): %w", filename, err)
}
return configFile, err
}

View File

@ -3,6 +3,7 @@ package configfile
import (
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"io"
"os"
@ -12,7 +13,6 @@ import (
"github.com/docker/cli/cli/config/credentials"
"github.com/docker/cli/cli/config/memorystore"
"github.com/docker/cli/cli/config/types"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
@ -167,7 +167,7 @@ func (configFile *ConfigFile) SaveToWriter(writer io.Writer) error {
// Save encodes and writes out all the authorization information
func (configFile *ConfigFile) Save() (retErr error) {
if configFile.Filename == "" {
return errors.Errorf("Can't save config with empty filename")
return errors.New("can't save config with empty filename")
}
dir := filepath.Dir(configFile.Filename)
@ -194,7 +194,7 @@ func (configFile *ConfigFile) Save() (retErr error) {
}
if err := temp.Close(); err != nil {
return errors.Wrap(err, "error closing temp file")
return fmt.Errorf("error closing temp file: %w", err)
}
// Handle situation where the configfile is a symlink, and allow for dangling symlinks
@ -278,11 +278,11 @@ func decodeAuth(authStr string) (string, string, error) {
return "", "", err
}
if n > decLen {
return "", "", errors.Errorf("Something went wrong decoding auth config")
return "", "", errors.New("something went wrong decoding auth config")
}
userName, password, ok := strings.Cut(string(decoded), ":")
if !ok || userName == "" {
return "", "", errors.Errorf("Invalid auth configuration file")
return "", "", errors.New("invalid auth configuration file")
}
return userName, strings.Trim(password, "\x00"), nil
}