diff --git a/internal/executer/executer.go b/internal/executer/executer.go index 4ee47c9..4e9ee42 100644 --- a/internal/executer/executer.go +++ b/internal/executer/executer.go @@ -26,6 +26,10 @@ import ( "os/exec" ) +// dockerDesktopHelperName is the name of the docker credentials helper +// execuatable. +const dockerDesktopHelperName = "docker-credential-desktop.exe" + // Executer is an interface that simulates an executable binary. type Executer interface { 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 cmd.Stderr = os.Stderr output, err := cmd.Output() if err != nil { - if _, ok := err.(*exec.ExitError); ok { + switch execErr := err.(type) { + case *exec.ExitError: if errMessage := string(bytes.TrimSpace(output)); errMessage != "" { - err = errors.New(errMessage) + return nil, errors.New(errMessage) + } + case *exec.Error: + // check if the error is caused by Docker Desktop not running + if execErr.Err == exec.ErrNotFound && c.name == dockerDesktopHelperName { + return nil, errors.New("credentials store is configured to `desktop.exe` but Docker Desktop seems not running") } } return nil, err diff --git a/registry.go b/registry.go index b5e0210..3d46049 100644 --- a/registry.go +++ b/registry.go @@ -50,11 +50,11 @@ func Login(ctx context.Context, store Store, reg *remote.Registry, cred auth.Cre authClient.Credential = auth.StaticCredential(reg.Reference.Registry, cred) // validate and store the credential if err := regClone.Ping(ctx); err != nil { - return fmt.Errorf("failed to validate the credential for %s: %w", regClone.Reference.Registry, err) + return fmt.Errorf("failed to validate the credentials for %s: %w", regClone.Reference.Registry, err) } hostname := mapStoreRegistryName(regClone.Reference.Registry) if err := store.Put(ctx, hostname, cred); err != nil { - return fmt.Errorf("failed to store the credential for %s: %w", hostname, err) + return fmt.Errorf("failed to store the credentials for %s: %w", hostname, err) } return nil }