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

fix: use a better error message on WSL #77

Merged
merged 1 commit into from
Jun 19, 2023
Merged

fix: use a better error message on WSL #77

merged 1 commit into from
Jun 19, 2023

Conversation

wangxiaoxuan273
Copy link
Collaborator

Resolves #26

@codecov-commenter
Copy link

codecov-commenter commented Jun 15, 2023

Codecov Report

Merging #77 (a8175a5) into main (bf5244c) will not change coverage.
The diff coverage is 50.00%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@           Coverage Diff           @@
##             main      #77   +/-   ##
=======================================
  Coverage   82.73%   82.73%           
=======================================
  Files           6        6           
  Lines         388      388           
=======================================
  Hits          321      321           
  Misses         45       45           
  Partials       22       22           
Impacted Files Coverage Δ
registry.go 83.33% <50.00%> (ø)

@wangxiaoxuan273 wangxiaoxuan273 changed the title fix: use a error message on WSL fix: use a better error message on WSL Jun 15, 2023
@wangxiaoxuan273
Copy link
Collaborator Author

Changed the displayed error message of the current scenario.
image

native_store.go Outdated
@@ -120,6 +122,9 @@ func (ns *nativeStore) Put(ctx context.Context, serverAddress string, cred auth.
return err
}
_, err = ns.exec.Execute(ctx, bytes.NewReader(credJSON), "store")
if err != nil && err.Error() == errExeNotInPathMessage {
return fmt.Errorf("credential store is configured to `desktop` but docker desktop seems not running")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we call it credentials store by following the consistent naming with Docker? See https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this error message Error: error storing credentials: be added by ORAS to the beginning in this output?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this error message Error: error storing credentials: be added by ORAS to the beginning in this output?

You can take a look at the screen shot above. It looks like the answer is no. We can change it if we need. @FeynmanZhou

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we call it credentials store by following the consistent naming with Docker? See https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Nice catch. Changed the name.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wangxiaoxuan273 You can check the log style in other ORAS error logs. If there is a consistent log style in ORAS, we may need to follow it and add it accordingly. If not, we can skip it.

native_store.go Outdated Show resolved Hide resolved
native_store.go Outdated
@@ -30,6 +31,7 @@ const (
remoteCredentialsPrefix = "docker-credential-"
emptyUsername = "<token>"
errCredentialsNotFoundMessage = "credentials not found in native keychain"
errExeNotInPathMessage = "exec: \"docker-credential-desktop.exe\": executable file not found in $PATH"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be a native_store_wsl.go to handle this that or can we count on a generic match?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't think a separate wsl.go file is necessary. We have changed exact string matching to error matching to improve the code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code was improved by the time this was merged, but this is exactly the kind of thing you'd want to put in a platform specific module.

native_store.go Outdated
@@ -30,6 +31,7 @@ const (
remoteCredentialsPrefix = "docker-credential-"
emptyUsername = "<token>"
errCredentialsNotFoundMessage = "credentials not found in native keychain"
errExeNotInPathMessage = "exec: \"docker-credential-desktop.exe\": executable file not found in $PATH"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding the following code to executer.go.

if execErr, ok := err.(*exec.Error); ok && execErr.Err == exec.ErrNotFound {
	return nil, errors.New("credentials store is configured to `desktop` but Docker Desktop seems not running")
}

Copy link
Collaborator Author

@wangxiaoxuan273 wangxiaoxuan273 Jun 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this part. It's a very good suggestion.

native_store.go Outdated
@@ -120,6 +122,9 @@ func (ns *nativeStore) Put(ctx context.Context, serverAddress string, cred auth.
return err
}
_, err = ns.exec.Execute(ctx, bytes.NewReader(credJSON), "store")
if err != nil && err.Error() == errExeNotInPathMessage {
return fmt.Errorf("credentials store is configured to `desktop` but Docker Desktop seems not running")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
return fmt.Errorf("credentials store is configured to `desktop` but Docker Desktop seems not running")
return fmt.Errorf("credentials store is configured to `desktop.exe` but Docker Desktop seems not running")

/cc @FeynmanZhou

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shizhMSFT Good catch.

Comment on lines 55 to 56
err = errors.New(errMessage)
return nil, err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: clean code

Suggested change
err = errors.New(errMessage)
return nil, err
return nil, errors.New(errMessage)

Copy link
Collaborator Author

@wangxiaoxuan273 wangxiaoxuan273 Jun 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed this part and used a switch statement.

Comment on lines 59 to 62
// check if the error is caused by Docker Desktop not running
if execErr, ok := err.(*exec.Error); ok && execErr.Err == exec.ErrNotFound {
return nil, errors.New("credentials store is configured to `desktop` but Docker Desktop seems not running")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the binary is not docker-credential-desktop.exe?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a third condition.

@wangxiaoxuan273
Copy link
Collaborator Author

Current output:
Screenshot 2023-06-19 163117

@FeynmanZhou
Copy link
Member

Current output: Screenshot 2023-06-19 163117

This version looks good to me. Thanks @wangxiaoxuan273

Signed-off-by: Xiaoxuan Wang <[email protected]>
Copy link
Contributor

@shizhMSFT shizhMSFT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@shizhMSFT shizhMSFT merged commit 26b25ce into oras-project:main Jun 19, 2023
@wangxiaoxuan273 wangxiaoxuan273 deleted the err-msg branch June 19, 2023 09:14
@wangxiaoxuan273 wangxiaoxuan273 mentioned this pull request Jun 19, 2023
3 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Better error prompt when Docker Desktop is installed
5 participants