fix: use a better error message on WSL#77
Conversation
Codecov Report
❗ 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
|
| } | ||
| _, 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") |
There was a problem hiding this comment.
Should we call it credentials store by following the consistent naming with Docker? See https://docs.docker.com/engine/reference/commandline/login/#credentials-store
There was a problem hiding this comment.
Will this error message Error: error storing credentials: be added by ORAS to the beginning in this output?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Should we call it
credentials storeby following the consistent naming with Docker? See https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Nice catch. Changed the name.
There was a problem hiding this comment.
@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.
| remoteCredentialsPrefix = "docker-credential-" | ||
| emptyUsername = "<token>" | ||
| errCredentialsNotFoundMessage = "credentials not found in native keychain" | ||
| errExeNotInPathMessage = "exec: \"docker-credential-desktop.exe\": executable file not found in $PATH" |
There was a problem hiding this comment.
Should there be a native_store_wsl.go to handle this that or can we count on a generic match?
There was a problem hiding this comment.
We don't think a separate wsl.go file is necessary. We have changed exact string matching to error matching to improve the code.
There was a problem hiding this comment.
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.
| remoteCredentialsPrefix = "docker-credential-" | ||
| emptyUsername = "<token>" | ||
| errCredentialsNotFoundMessage = "credentials not found in native keychain" | ||
| errExeNotInPathMessage = "exec: \"docker-credential-desktop.exe\": executable file not found in $PATH" |
There was a problem hiding this comment.
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")
}There was a problem hiding this comment.
Added this part. It's a very good suggestion.
| } | ||
| _, 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") |
There was a problem hiding this comment.
nit:
| 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
| err = errors.New(errMessage) | ||
| return nil, err |
There was a problem hiding this comment.
nit: clean code
| err = errors.New(errMessage) | |
| return nil, err | |
| return nil, errors.New(errMessage) |
There was a problem hiding this comment.
changed this part and used a switch statement.
| // 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") | ||
| } |
There was a problem hiding this comment.
What if the binary is not docker-credential-desktop.exe?
There was a problem hiding this comment.
added a third condition.
|
This version looks good to me. Thanks @wangxiaoxuan273 |
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>



Resolves #26