Skip to content

Commit

Permalink
remove exit code per error type used by legacy metrics system
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
  • Loading branch information
ndeloof committed Jan 27, 2025
1 parent 7c74076 commit 4230b2f
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 231 deletions.
15 changes: 3 additions & 12 deletions cmd/compose/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import (
"github.com/docker/compose/v2/internal/experimental"
"github.com/docker/compose/v2/internal/tracing"
"github.com/docker/compose/v2/pkg/api"
"github.com/docker/compose/v2/pkg/compose"
ui "github.com/docker/compose/v2/pkg/progress"
"github.com/docker/compose/v2/pkg/remote"
"github.com/docker/compose/v2/pkg/utils"
Expand Down Expand Up @@ -121,17 +120,9 @@ func AdaptCmd(fn CobraCommand) func(cmd *cobra.Command, args []string) error {
}()

err := fn(ctx, cmd, args)
var composeErr compose.Error
if api.IsErrCanceled(err) || errors.Is(ctx.Err(), context.Canceled) {
err = dockercli.StatusError{
StatusCode: 130,
Status: compose.CanceledStatus,
}
}
if errors.As(err, &composeErr) {
err = dockercli.StatusError{
StatusCode: composeErr.GetMetricsFailureCategory().ExitCode,
Status: err.Error(),
}
}
if ui.Mode == ui.ModeJSON {
Expand Down Expand Up @@ -307,7 +298,7 @@ func (o *ProjectOptions) ToProject(ctx context.Context, dockerCli command.Cli, s

options, err := o.toProjectOptions(po...)
if err != nil {
return nil, metrics, compose.WrapComposeError(err)
return nil, metrics, err
}

options.WithListeners(func(event string, metadata map[string]any) {
Expand Down Expand Up @@ -339,7 +330,7 @@ func (o *ProjectOptions) ToProject(ctx context.Context, dockerCli command.Cli, s

project, err := options.LoadProject(ctx)
if err != nil {
return nil, metrics, compose.WrapComposeError(err)
return nil, metrics, err
}

if project.Name == "" {
Expand Down Expand Up @@ -453,7 +444,7 @@ func RootCommand(dockerCli command.Cli, backend Backend) *cobra.Command { //noli
}
_ = cmd.Help()
return dockercli.StatusError{
StatusCode: compose.CommandSyntaxFailure.ExitCode,
StatusCode: 1,
Status: fmt.Sprintf("unknown docker command: %q", "compose "+args[0]),
}
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func pluginMain() {

cmd.SetFlagErrorFunc(func(c *cobra.Command, err error) error {
return dockercli.StatusError{
StatusCode: compose.CommandSyntaxFailure.ExitCode,
StatusCode: 1,
Status: err.Error(),
}
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/compose/build_buildkit.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (s *composeService) doBuildBuildkit(ctx context.Context, service string, op
confutil.NewConfig(s.dockerCli),
buildx.WithPrefix(p, service, true))
if err != nil {
return "", WrapCategorisedComposeError(err, BuildFailure)
return "", err
}
}

Expand Down
71 changes: 0 additions & 71 deletions pkg/compose/errors.go

This file was deleted.

79 changes: 0 additions & 79 deletions pkg/compose/metrics.go

This file was deleted.

8 changes: 4 additions & 4 deletions pkg/compose/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func (s *composeService) pullServiceImage(ctx context.Context, service types.Ser
Text: "Warning",
StatusText: getUnwrappedErrorMessage(err),
})
return "", WrapCategorisedComposeError(err, PullFailure)
return "", err
}

if err != nil {
Expand All @@ -221,7 +221,7 @@ func (s *composeService) pullServiceImage(ctx context.Context, service types.Ser
Text: "Error",
StatusText: getUnwrappedErrorMessage(err),
})
return "", WrapCategorisedComposeError(err, PullFailure)
return "", err
}

dec := json.NewDecoder(stream)
Expand All @@ -231,10 +231,10 @@ func (s *composeService) pullServiceImage(ctx context.Context, service types.Ser
if errors.Is(err, io.EOF) {
break
}
return "", WrapCategorisedComposeError(err, PullFailure)
return "", err
}
if jm.Error != nil {
return "", WrapCategorisedComposeError(errors.New(jm.Error.Message), PullFailure)
return "", errors.New(jm.Error.Message)
}
if !quietPull {
toPullProgressEvent(service.Name, jm, w)
Expand Down
11 changes: 5 additions & 6 deletions pkg/e2e/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func TestBuildSSH(t *testing.T) {
"--project-directory", "fixtures/build-test/ssh", "build", "--no-cache", "--ssh",
"wrong-ssh=./fixtures/build-test/ssh/fake_rsa")
res.Assert(t, icmd.Expected{
ExitCode: 17,
ExitCode: 1,
Err: "unset ssh forward key fake-ssh",
})
})
Expand Down Expand Up @@ -304,7 +304,7 @@ func TestBuildPlatformsWithCorrectBuildxConfig(t *testing.T) {
res := c.RunDockerComposeCmdNoCheck(t, "--project-directory", "fixtures/build-test/platforms",
"-f", "fixtures/build-test/platforms/compose-unsupported-platform.yml", "build")
res.Assert(t, icmd.Expected{
ExitCode: 17,
ExitCode: 1,
Err: "no match for platform in",
})
})
Expand Down Expand Up @@ -402,7 +402,7 @@ func TestBuildPlatformsStandardErrors(t *testing.T) {
t.Run("builder does not support multi-arch", func(t *testing.T) {
res := c.RunDockerComposeCmdNoCheck(t, "--project-directory", "fixtures/build-test/platforms", "build")
res.Assert(t, icmd.Expected{
ExitCode: 17,
ExitCode: 1,
Err: `Multi-platform build is not supported for the docker driver.
Switch to a different driver, or turn on the containerd image store, and try again.`,
})
Expand All @@ -412,7 +412,7 @@ Switch to a different driver, or turn on the containerd image store, and try aga
res := c.RunDockerComposeCmdNoCheck(t, "--project-directory", "fixtures/build-test/platforms",
"-f", "fixtures/build-test/platforms/compose-service-platform-not-in-build-platforms.yaml", "build")
res.Assert(t, icmd.Expected{
ExitCode: 15,
ExitCode: 1,
Err: `service.build.platforms MUST include service.platform "linux/riscv64"`,
})
})
Expand Down Expand Up @@ -461,8 +461,7 @@ func TestBuildBuilder(t *testing.T) {
t.Run("error when using specific builder to run build command", func(t *testing.T) {
res := c.RunDockerComposeCmdNoCheck(t, "--project-directory", "fixtures/build-test", "build", "--builder", "unknown-builder")
res.Assert(t, icmd.Expected{
ExitCode: 1,
Err: fmt.Sprintf(`no builder %q found`, "unknown-builder"),
Err: fmt.Sprintf(`no builder %q found`, "unknown-builder"),
})
})
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/e2e/compose_up_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestUpExitCodeFrom(t *testing.T) {
const projectName = "e2e-exit-code-from"

res := c.RunDockerComposeCmdNoCheck(t, "-f", "fixtures/start-fail/start-depends_on-long-lived.yaml", "--project-name", projectName, "up", "--menu=false", "--exit-code-from=failure", "failure")
res.Assert(t, icmd.Expected{ExitCode: 42})
res.Assert(t, icmd.Expected{ExitCode: 1})

c.RunDockerComposeCmd(t, "--project-name", projectName, "down", "--remove-orphans")
}
Expand Down
55 changes: 0 additions & 55 deletions pkg/e2e/metrics_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/e2e/pull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestComposePull(t *testing.T) {

t.Run("Verify pull failure", func(t *testing.T) {
res := c.RunDockerComposeCmdNoCheck(t, "--project-directory", "fixtures/compose-pull/unknown-image", "pull")
res.Assert(t, icmd.Expected{ExitCode: 18, Err: "pull access denied for does_not_exists"})
res.Assert(t, icmd.Expected{ExitCode: 1, Err: "pull access denied for does_not_exists"})
})

t.Run("Verify ignore pull failure", func(t *testing.T) {
Expand Down

0 comments on commit 4230b2f

Please sign in to comment.