Skip to content

Commit 1085852

Browse files
committed
remove error message from exec outpout by default
Add the error as a log for verbose mode Signed-off-by: Guillaume Lours <[email protected]>
1 parent 3553aa2 commit 1085852

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

cmd/compose/exec.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@ package compose
1818

1919
import (
2020
"context"
21+
"errors"
2122
"fmt"
23+
"os"
2224

2325
"github.com/compose-spec/compose-go/v2/types"
2426
"github.com/docker/cli/cli"
2527
"github.com/docker/cli/cli/command"
2628
"github.com/docker/compose/v2/pkg/api"
2729
"github.com/docker/compose/v2/pkg/compose"
30+
"github.com/sirupsen/logrus"
2831
"github.com/spf13/cobra"
2932
)
3033

@@ -60,7 +63,15 @@ func execCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service)
6063
return nil
6164
}),
6265
RunE: Adapt(func(ctx context.Context, args []string) error {
63-
return runExec(ctx, dockerCli, backend, opts)
66+
err := runExec(ctx, dockerCli, backend, opts)
67+
if err != nil {
68+
logrus.Debugf("%v", err)
69+
var cliError cli.StatusError
70+
if ok := errors.As(err, &cliError); ok {
71+
os.Exit(err.(cli.StatusError).StatusCode)
72+
}
73+
}
74+
return err
6475
}),
6576
ValidArgsFunction: completeServiceNames(dockerCli, p),
6677
}

pkg/e2e/fixtures/hooks/poststart/compose-error.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ services:
33
test:
44
image: alpine
55
post_start:
6-
- command: sh -c 'echo env'
6+
- command: sh -c 'unexpected command'

0 commit comments

Comments
 (0)