Skip to content

Deprecate exitCode #5124

Closed
Closed

Description

@helderco

Summary

I’m proposing we deprecate exitCode in favor of sync and ExecError as an alternative solution to #3192.

Motivation

The Container.exitCode field doesn’t make sense because you always get zero on success and you can’t get the non-zero value when the command fails due to a bug:

So since the result on success is useless, just replace with sync:

But if you do need the non-zero exit code value, you can get it from ExecError:

Examples

Don't care about the result

- _, err := ctr.ExitCode(ctx)
+ _, err := ctr.Sync(ctx)
  if err != nil {
      return err
  }

Need the exit code

func GetExitCode(ctr *dagger.Container) (int, error) {
    _, err := ctr.Sync(ctx)
    if e, ok := err.(*dagger.ExecError); ok {
        return e.ExitCode, nil
    }
    return 0, err
}

Specification

Just add the deprecation in the API:

type Container {
  """
  Exit code of the last executed command. Zero means success.

  Will execute default command if none is set, or error if there's no default.
  """
- exitCode: Int!
+ exitCode: Int! @deprecated(reason: "Use `sync` instead.")
}

Caveat

There is one big difference between ExitCode(ctx) and Sync(ctx). While the former triggers command execution, defaulting to the entrypoint and default args if no WithExec is defined in the pipeline, the latter does not.

Just “renaming” to a new .Run(ctx) that behaves the same doesn’t seem worth it. And some users don’t actually want to run the command (e.g., just do a Dockerfile build), so it pays to understand what’s going on.

We’ll just have to make this clear in documentation and examples:

Activity

  1. added
    area/engine
    on May 10, 2023
  2. gerhard commented on Jul 18, 2023

    @gerhard
    Contributor
  3. helderco commented on Jul 18, 2023

    @helderco
    ContributorAuthor

    @gerhard I think we should add this now and remove later since we're doing another release before v0.8.

  4. gerhard commented on Jul 25, 2023

    @gerhard
    Contributor

    That's a good idea!

    Is there a PR / issue that we can track for the v0.8.0 milestone?

  5. helderco commented on Jul 25, 2023

    @helderco
    ContributorAuthor

    Yes, it's in #5479.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/engine

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions