Skip to content
This repository was archived by the owner on Apr 7, 2024. It is now read-only.

Commit 26b25ce

Browse files
fix: use a better error message on WSL (#77)
Resolves #26 Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
1 parent 6d14c42 commit 26b25ce

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

internal/executer/executer.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ import (
2626
"os/exec"
2727
)
2828

29+
// dockerDesktopHelperName is the name of the docker credentials helper
30+
// execuatable.
31+
const dockerDesktopHelperName = "docker-credential-desktop.exe"
32+
2933
// Executer is an interface that simulates an executable binary.
3034
type Executer interface {
3135
Execute(ctx context.Context, input io.Reader, action string) ([]byte, error)
@@ -50,9 +54,15 @@ func (c *executable) Execute(ctx context.Context, input io.Reader, action string
5054
cmd.Stderr = os.Stderr
5155
output, err := cmd.Output()
5256
if err != nil {
53-
if _, ok := err.(*exec.ExitError); ok {
57+
switch execErr := err.(type) {
58+
case *exec.ExitError:
5459
if errMessage := string(bytes.TrimSpace(output)); errMessage != "" {
55-
err = errors.New(errMessage)
60+
return nil, errors.New(errMessage)
61+
}
62+
case *exec.Error:
63+
// check if the error is caused by Docker Desktop not running
64+
if execErr.Err == exec.ErrNotFound && c.name == dockerDesktopHelperName {
65+
return nil, errors.New("credentials store is configured to `desktop.exe` but Docker Desktop seems not running")
5666
}
5767
}
5868
return nil, err

registry.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ func Login(ctx context.Context, store Store, reg *remote.Registry, cred auth.Cre
5050
authClient.Credential = auth.StaticCredential(reg.Reference.Registry, cred)
5151
// validate and store the credential
5252
if err := regClone.Ping(ctx); err != nil {
53-
return fmt.Errorf("failed to validate the credential for %s: %w", regClone.Reference.Registry, err)
53+
return fmt.Errorf("failed to validate the credentials for %s: %w", regClone.Reference.Registry, err)
5454
}
5555
hostname := ServerAddressFromRegistry(regClone.Reference.Registry)
5656
if err := store.Put(ctx, hostname, cred); err != nil {
57-
return fmt.Errorf("failed to store the credential for %s: %w", hostname, err)
57+
return fmt.Errorf("failed to store the credentials for %s: %w", hostname, err)
5858
}
5959
return nil
6060
}

0 commit comments

Comments
 (0)