Skip to content

Commit 77a8a8c

Browse files
authored
Merge pull request #5854 from Benehiko/fix-exec-msg
cmd/docker: do not print error status on exec/run
2 parents eb48cad + 0cff340 commit 77a8a8c

File tree

6 files changed

+9
-13
lines changed

6 files changed

+9
-13
lines changed

cli/command/network/remove.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package network
33
import (
44
"context"
55
"fmt"
6+
"strconv"
67

78
"github.com/docker/cli/cli"
89
"github.com/docker/cli/cli/command"
@@ -68,7 +69,7 @@ func runRemove(ctx context.Context, dockerCLI command.Cli, networks []string, op
6869
}
6970

7071
if status != 0 {
71-
return cli.StatusError{StatusCode: status}
72+
return cli.StatusError{StatusCode: status, Status: "exit status " + strconv.Itoa(status)}
7273
}
7374
return nil
7475
}

cli/error.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package cli
22

3-
import (
4-
"strconv"
5-
)
6-
73
// StatusError reports an unsuccessful exit by a command.
84
type StatusError struct {
95
Cause error
@@ -21,7 +17,9 @@ func (e StatusError) Error() string {
2117
if e.Cause != nil {
2218
return e.Cause.Error()
2319
}
24-
return "exit status " + strconv.Itoa(e.StatusCode)
20+
// we don't want to set a default message here,
21+
// some commands might want to be explicit about the error message
22+
return ""
2523
}
2624

2725
func (e StatusError) Unwrap() error {

cmd/docker/docker.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ func main() {
4343
}
4444

4545
if err != nil && !errdefs.IsCancelled(err) {
46-
_, _ = fmt.Fprintln(os.Stderr, err)
46+
if err.Error() != "" {
47+
_, _ = fmt.Fprintln(os.Stderr, err)
48+
}
4749
os.Exit(getExitCode(err))
4850
}
4951
}

e2e/cli-plugins/socket_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ func TestPluginSocketBackwardsCompatible(t *testing.T) {
137137
assert.Assert(t, errors.As(err, &exitError))
138138
assert.Check(t, exitError.Exited())
139139
assert.Check(t, is.Equal(exitError.ExitCode(), 1))
140-
assert.Check(t, is.ErrorContains(err, "exit status 1"))
141140

142141
// the plugin process does not receive a SIGINT and does
143142
// the CLI cannot cancel it over the socket, so it kills
@@ -199,11 +198,10 @@ func TestPluginSocketCommunication(t *testing.T) {
199198
assert.Assert(t, errors.As(err, &exitError))
200199
assert.Check(t, exitError.Exited())
201200
assert.Check(t, is.Equal(exitError.ExitCode(), 2))
202-
assert.Check(t, is.ErrorContains(err, "exit status 2"))
203201

204202
// the plugin does not get signalled, but it does get its
205203
// context canceled by the CLI through the socket
206-
const expected = "test-socket: exiting after context was done\nexit status 2"
204+
const expected = "test-socket: exiting after context was done"
207205
actual := strings.TrimSpace(string(out))
208206
assert.Check(t, is.Equal(actual, expected))
209207
})
@@ -238,7 +236,6 @@ func TestPluginSocketCommunication(t *testing.T) {
238236
assert.Assert(t, errors.As(err, &exitError))
239237
assert.Check(t, exitError.Exited())
240238
assert.Check(t, is.Equal(exitError.ExitCode(), 1))
241-
assert.Check(t, is.ErrorContains(err, "exit status 1"))
242239

243240
// the plugin process does not receive a SIGINT and does
244241
// not exit after having it's context canceled, so the CLI

e2e/container/attach_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,4 @@ func TestAttachInterrupt(t *testing.T) {
5858
// the CLI should exit with 33 (the SIGINT was forwarded to the container), and the
5959
// CLI process waited for the container exit and properly captured/set the exit code
6060
assert.Equal(t, c.ProcessState.ExitCode(), 33)
61-
assert.Equal(t, d.String(), "exit status 33\n")
6261
}

e2e/container/run_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ func TestRunAttach(t *testing.T) {
6868
}
6969

7070
assert.Equal(t, c.ProcessState.ExitCode(), 7)
71-
assert.Check(t, is.Contains(d.String(), "exit status 7"))
7271
})
7372
}
7473
}

0 commit comments

Comments
 (0)