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

fix: use a better error message on WSL#77

Merged
shizhMSFT merged 1 commit into
oras-project:mainfrom
wangxiaoxuan273:err-msg
Jun 19, 2023
Merged

fix: use a better error message on WSL#77
shizhMSFT merged 1 commit into
oras-project:mainfrom
wangxiaoxuan273:err-msg

Conversation

@wangxiaoxuan273

Copy link
Copy Markdown
Collaborator

Resolves #26

@codecov-commenter

codecov-commenter commented Jun 15, 2023

Copy link
Copy Markdown

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
Copy Markdown
Collaborator Author

Changed the displayed error message of the current scenario.
image

Comment thread native_store.go Outdated
}
_, 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread native_store.go Outdated
Comment thread native_store.go Outdated
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread native_store.go Outdated
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
Copy Markdown
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")
}

@wangxiaoxuan273 wangxiaoxuan273 Jun 19, 2023

Copy link
Copy Markdown
Collaborator Author

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.

Comment thread native_store.go Outdated
}
_, 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
Copy Markdown
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
Copy Markdown
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 thread internal/executer/executer.go Outdated
Comment on lines +55 to +56
err = errors.New(errMessage)
return nil, err

Copy link
Copy Markdown
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)

@wangxiaoxuan273 wangxiaoxuan273 Jun 19, 2023

Copy link
Copy Markdown
Collaborator Author

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 thread internal/executer/executer.go Outdated
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Collaborator Author

Current output:
Screenshot 2023-06-19 163117

@FeynmanZhou

Copy link
Copy Markdown
Member

Current output: Screenshot 2023-06-19 163117

This version looks good to me. Thanks @wangxiaoxuan273

Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>

@shizhMSFT shizhMSFT left a comment

Copy link
Copy Markdown
Contributor

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