Repository navigation
Description
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
gerhard commentedon Jul 18, 2023
This sounds good, let's do it & remove part of:
helderco commentedon Jul 18, 2023
@gerhard I think we should add this now and remove later since we're doing another release before v0.8.
gerhard commentedon Jul 25, 2023
That's a good idea!
Is there a PR / issue that we can track for the
v0.8.0milestone?helderco commentedon Jul 25, 2023
Yes, it's in #5479.