Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove exit code per error type used by legacy metrics system #12502

Merged
merged 1 commit into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 4 additions & 4 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
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
Loading