Skip to content

Comments

Improve readability of Windows connect error#39588

Merged
thaJeztah merged 1 commit intomoby:masterfrom
zappy-shu:DESKTOP-1286-win-admin-error-readability
Aug 30, 2019
Merged

Improve readability of Windows connect error#39588
thaJeztah merged 1 commit intomoby:masterfrom
zappy-shu:DESKTOP-1286-win-admin-error-readability

Conversation

@zappy-shu
Copy link
Contributor

@zappy-shu zappy-shu commented Jul 22, 2019

- What I did

Improve the readability of the connection error displayed to the user on Windows when running docker commands when either the user is not running in admin mode or the daemon is not running.

- How I did it
This is done putting the help message first and putting the error details, which are difficult to
diagnose, after.

- How to verify it
On Windows, run a docker command (e.g. ps) without the daemon running and again with the daemon running but without elevated permissions. The displayed error message should start with In the default daemon configuration on Windows, the docker client must be run with elevated privileges to connect.
Run again without the daemon running but with elevated permissions. The displayed error message should start with This error may indicate that the docker daemon is not running.

- Description for the changelog

Improve error message shown on Windows when daemon is not running or client does not have elevated permissions

- A picture of a cute animal (not mandatory but encouraged)

@thaJeztah
Copy link
Member

CI is failing because this branch doesn't have the latest fixes from master (it should pass once rebased)

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

left one comment, but if possible, we should try to find what the reason was for the failure; can we somehow detect a "permission denied" and only print the extra information about "need to run privileged" in that case

@vikramhh do you know (or could you check) if that's possible? e.g. would os.IsPermission(err) https://golang.org/pkg/os/#IsPermission work?

Copy link
Member

Choose a reason for hiding this comment

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

Not new (original code already did so), but this should use errors.Wrap so that we preserve the original error;

Suggested change
err = errors.New("In the default daemon configuration on Windows, the docker client must be run elevated to connect. This error may also indicate that the docker daemon is not running. " + err.Error())
err = errors.Wrap(err, "in the default daemon configuration on Windows, the docker client must be run elevated to connect. This error may also indicate that the docker daemon is not running. ")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've done the change to wrap the error and used @vikramhh's sample below to check for if the user is privileged so as to direct the error message

@zappy-shu zappy-shu force-pushed the DESKTOP-1286-win-admin-error-readability branch from c2bc58c to ea64a16 Compare July 25, 2019 10:20
@vikramhh
Copy link

Here is how one might do it: https://play.golang.org/p/bBtRZrk4_p

I tried both the above and the alternative suggested at golang/go#28804. I suggest using this because it is more simple and robust.

@zappy-shu : I noticed the "How to verify it" section above is incomplete.[Please ignore my comment if it is meant to be completed later on]. Also I suggest consistent use of the term "elevated privileges" throughout [or admin mode or elevated permissions, whichever you prefer] instead of mixing these.

@vikramhh
Copy link

Instead of throwing away the opened file handle, I suggest capturing it and calling Close on it (only in case of success). This is the pattern shown in documentation of Open at https://golang.org/src/os/file.go?s=8458:8524#L272

@zappy-shu zappy-shu force-pushed the DESKTOP-1286-win-admin-error-readability branch from 92c759a to db1c623 Compare July 31, 2019 08:10
@zappy-shu
Copy link
Contributor Author

@vikramhh apologies for the delay in updating the description. Hopefully that is better. I'm happy to squash the commits as well if that helps

@vikramhh
Copy link

LGTM

Thanks you, Nick, for accepting my suggestions.

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

left one comment 😅 but otherwise looks good

@GordonTheTurtle GordonTheTurtle added the dco/no Automatically set by a bot when one of the commits lacks proper signature label Aug 20, 2019
@GordonTheTurtle
Copy link

Please sign your commits following these rules:
https://github.com/moby/moby/blob/master/CONTRIBUTING.md#sign-your-work
The easiest way to do this is to amend the last commit:

$ git clone -b "DESKTOP-1286-win-admin-error-readability" [email protected]:zappy-shu/moby.git somewhere
$ cd somewhere
$ git rebase -i HEAD~842359069840
editor opens
change each 'pick' to 'edit'
save the file and quit
$ git commit --amend -s --no-edit
$ git rebase --continue # and repeat the amend for each commit
$ git push -f

Amending updates the existing PR. You DO NOT need to open a new one.

@zappy-shu zappy-shu force-pushed the DESKTOP-1286-win-admin-error-readability branch from 385810b to 0784fa8 Compare August 20, 2019 08:10
@GordonTheTurtle GordonTheTurtle removed the dco/no Automatically set by a bot when one of the commits lacks proper signature label Aug 20, 2019
@zappy-shu zappy-shu force-pushed the DESKTOP-1286-win-admin-error-readability branch from 0784fa8 to 8a38ed5 Compare August 20, 2019 08:16
Improve the readability of the connection error displayed to the user on
Windows when running docker commands fails by checking if the client is
privileged. If so then display the actual error wrapped in a generic
error "This error may indicate that the docker daemon is not running."

If not that display the actual error wrapped in a more specific error:
"In the default daemon configuration on Windows, the docker client must
be run with elevated privileges to connect."

Signed-off-by: Nick Adcock <[email protected]>
@zappy-shu zappy-shu force-pushed the DESKTOP-1286-win-admin-error-readability branch from 8a38ed5 to 1a5dafb Compare August 20, 2019 11:10
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@thaJeztah
Copy link
Member

ping @tiborvass @kolyshkin PTAL

@thaJeztah
Copy link
Member

marking this for cherry-picking, because this should be low-risk, and there's often confusion about this on Docker Desktop users (but will need a re-vendor in the CLI after it's been backported)

Copy link
Member

@yongtang yongtang left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants