cli: Wrong error message from "node ps" outside swarm mode
| ... | ... |
@@ -1,6 +1,9 @@ |
| 1 | 1 |
package node |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
+ "errors" |
|
| 5 |
+ |
|
| 6 |
+ "github.com/docker/docker/api/types" |
|
| 4 | 7 |
"github.com/docker/docker/cli" |
| 5 | 8 |
"github.com/docker/docker/cli/command" |
| 6 | 9 |
apiclient "github.com/docker/docker/client" |
| ... | ... |
@@ -38,6 +41,16 @@ func Reference(ctx context.Context, client apiclient.APIClient, ref string) (str |
| 38 | 38 |
if err != nil {
|
| 39 | 39 |
return "", err |
| 40 | 40 |
} |
| 41 |
+ if info.Swarm.NodeID == "" {
|
|
| 42 |
+ // If there's no node ID in /info, the node probably |
|
| 43 |
+ // isn't a manager. Call a swarm-specific endpoint to |
|
| 44 |
+ // get a more specific error message. |
|
| 45 |
+ _, err = client.NodeList(ctx, types.NodeListOptions{})
|
|
| 46 |
+ if err != nil {
|
|
| 47 |
+ return "", err |
|
| 48 |
+ } |
|
| 49 |
+ return "", errors.New("node ID not found in /info")
|
|
| 50 |
+ } |
|
| 41 | 51 |
return info.Swarm.NodeID, nil |
| 42 | 52 |
} |
| 43 | 53 |
return ref, nil |
| ... | ... |
@@ -50,7 +50,7 @@ func TestNodeInspectErrors(t *testing.T) {
|
| 50 | 50 |
return swarm.Node{}, []byte{}, errors.Errorf("error inspecting the node")
|
| 51 | 51 |
}, |
| 52 | 52 |
infoFunc: func() (types.Info, error) {
|
| 53 |
- return types.Info{}, nil
|
|
| 53 |
+ return types.Info{Swarm: swarm.Info{NodeID: "abc"}}, nil
|
|
| 54 | 54 |
}, |
| 55 | 55 |
expectedError: "error inspecting the node", |
| 56 | 56 |
}, |
| ... | ... |
@@ -95,8 +95,10 @@ func runPs(dockerCli command.Cli, opts psOptions) error {
|
| 95 | 95 |
} |
| 96 | 96 |
} |
| 97 | 97 |
|
| 98 |
- if err := task.Print(dockerCli, ctx, tasks, idresolver.New(client, opts.noResolve), !opts.noTrunc, opts.quiet, format); err != nil {
|
|
| 99 |
- errs = append(errs, err.Error()) |
|
| 98 |
+ if len(errs) == 0 || len(tasks) != 0 {
|
|
| 99 |
+ if err := task.Print(dockerCli, ctx, tasks, idresolver.New(client, opts.noResolve), !opts.noTrunc, opts.quiet, format); err != nil {
|
|
| 100 |
+ errs = append(errs, err.Error()) |
|
| 101 |
+ } |
|
| 100 | 102 |
} |
| 101 | 103 |
|
| 102 | 104 |
if len(errs) > 0 {
|