Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit cf7f0db

Browse files
authored
Merge pull request #1501 from gtardif/error_exit_code
Replace custom error type for exit code with existing one from docker/cli
2 parents 80c8241 + 86f5e31 commit cf7f0db

File tree

5 files changed

+17
-35
lines changed

5 files changed

+17
-35
lines changed

cli/cmd/compose/run.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ import (
2727
"github.com/mattn/go-shellwords"
2828
"github.com/spf13/cobra"
2929

30+
"github.com/docker/cli/cli"
3031
"github.com/docker/compose-cli/api/client"
3132
"github.com/docker/compose-cli/api/compose"
3233
"github.com/docker/compose-cli/api/progress"
33-
"github.com/docker/compose-cli/cli/cmd"
3434
)
3535

3636
type runOptions struct {
@@ -196,7 +196,11 @@ func runRun(ctx context.Context, opts runOptions) error {
196196
}
197197
exitCode, err := c.ComposeService().RunOneOffContainer(ctx, project, runOpts)
198198
if exitCode != 0 {
199-
return cmd.ExitCodeError{ExitCode: exitCode}
199+
errMsg := ""
200+
if err != nil {
201+
errMsg = err.Error()
202+
}
203+
return cli.StatusError{StatusCode: exitCode, Status: errMsg}
200204
}
201205
return err
202206
}

cli/cmd/compose/up.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"time"
2929

3030
"github.com/compose-spec/compose-go/types"
31+
"github.com/docker/cli/cli"
3132
"github.com/docker/compose-cli/utils"
3233
"github.com/sirupsen/logrus"
3334
"github.com/spf13/cobra"
@@ -37,7 +38,6 @@ import (
3738
"github.com/docker/compose-cli/api/compose"
3839
"github.com/docker/compose-cli/api/context/store"
3940
"github.com/docker/compose-cli/api/progress"
40-
"github.com/docker/compose-cli/cli/cmd"
4141
"github.com/docker/compose-cli/cli/formatter"
4242
)
4343

@@ -323,7 +323,11 @@ func runCreateStart(ctx context.Context, opts upOptions, services []string) erro
323323

324324
err = eg.Wait()
325325
if exitCode != 0 {
326-
return cmd.ExitCodeError{ExitCode: exitCode}
326+
errMsg := ""
327+
if err != nil {
328+
errMsg = err.Error()
329+
}
330+
return cli.StatusError{StatusCode: exitCode, Status: errMsg}
327331
}
328332
return err
329333
}

cli/cmd/exit.go

Lines changed: 0 additions & 28 deletions
This file was deleted.

cli/cmd/version.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323

2424
"github.com/spf13/cobra"
2525

26+
"github.com/docker/cli/cli"
2627
"github.com/docker/compose-cli/cli/formatter"
2728
"github.com/docker/compose-cli/cli/mobycli"
2829
"github.com/docker/compose-cli/internal"
@@ -39,7 +40,7 @@ func VersionCommand() *cobra.Command {
3940
RunE: func(cmd *cobra.Command, _ []string) error {
4041
err := runVersion(cmd)
4142
if err != nil {
42-
return ExitCodeError{ExitCode: 1}
43+
return cli.StatusError{StatusCode: 1, Status: err.Error()}
4344
}
4445
return nil
4546
},

cli/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"syscall"
2929
"time"
3030

31+
"github.com/docker/cli/cli"
3132
"github.com/docker/cli/cli/command"
3233
cliconfig "github.com/docker/cli/cli/config"
3334
cliflags "github.com/docker/cli/cli/flags"
@@ -286,9 +287,9 @@ $ docker context create %s <name>`, cc.Type(), store.EcsContextType), ctype)
286287
}
287288

288289
func exit(ctx string, err error, ctype string) {
289-
if exit, ok := err.(cmd.ExitCodeError); ok {
290+
if exit, ok := err.(cli.StatusError); ok {
290291
metrics.Track(ctype, os.Args[1:], metrics.SuccessStatus)
291-
os.Exit(exit.ExitCode)
292+
os.Exit(exit.StatusCode)
292293
}
293294

294295
metrics.Track(ctype, os.Args[1:], metrics.FailureStatus)

0 commit comments

Comments
 (0)