Skip to content

Container: add Run helper - #4723

Closed
vito wants to merge 2 commits into
dagger:mainfrom
vito:container-run
Closed

vito wants to merge 2 commits into
dagger:mainfrom
vito:container-run

Conversation

@vito

@vito vito commented Mar 7, 2023 •

Copy link
Copy Markdown
Contributor

Adds this API:

"Nothing. Used by SDK codegen to skip the return value."
scalar Void

extend type Container {
  """
  Evaluates the command and returns an error if it exits with a nonzero exit
  code.
  """
  run: Void!
}

This is a convenience to replace this pattern:

code, err := container.ExitCode(ctx)
if err != nil {
  return err
}
if code != 0 {
  return fmt.Errorf("exit code: %d", code)
}

with this:

err := container.Run(ctx)
if err != nil {
  return err
}

I expect this to be used in a lot of pipelines that people write, so I biased towards what I think is a pretty ergonomic name ("run") even if it's a bit of a lie due to caching.

Right now this API is redundant because ExitCode returns an error when it encounters a nonzero exit code, which is a bug (#3192). Anyone relying on that behavior and ignoring the exit code return value should switch to this new API instead to avoid silently dropping failures in the future. (edit: per #3192 (comment) it'll keep erroring by default, so don't fear breakage in the future, but this API is still nice for when you don't actually care about the exit code.)

implementation notes

I added a new Void scalar return type because the entire point of this API is to not have a return value and just raise an error if the container fails. I updated the Go SDK codegen to handle this but haven't updated the rest yet. Submitting PR early for API review.

@vito
vito requested review from marcosnils, shykes and sipsma March 7, 2023 20:07
@vito
vito force-pushed the container-run branch 3 times, most recently from fa346cf to dc894fb Compare March 7, 2023 20:27
vito added 2 commits March 7, 2023 17:12
This is a convenience API to replace this pattern:

```go
code, err := container.ExitCode(ctx)
if err != nil {
  return err
}
if code != 0 {
  return fmt.Errorf("exit code: %d", code)
}
```

Right now it's redundant because ExitCode returns an error when it
encounters a nonzero exit code, which is a bug (dagger#3192). Anyone relying
on that behavior and ignoring the code return value should switch to
this new API instead.

Signed-off-by: Alex Suraci <[email protected]>
@vito

vito commented Mar 8, 2023

Copy link
Copy Markdown
Contributor Author

@helderco @slumbering I'm going to context-switch away from this for a bit, so if you have some downtime I'd appreciate any pointers (or commits) for updating the Python/NodeJS SDKs to handle the new Void response type. I've updated the Go SDK, but I'm not sure what the most ergonomic equivalent would be in the other languages, or if they're fine as-is. (:pray:)

@helderco

helderco commented Mar 8, 2023

Copy link
Copy Markdown
Contributor

It's on my radar. I don't have bandwidth right now but I want to think about this a little more soon.

At a glance, I'd like to add not erroring on exit_code to the breaking changes pile. It's a big one, since many are depending on it, but are we at a point where we're stuck with that history?

@vito

vito commented Mar 8, 2023 •

Copy link
Copy Markdown
Contributor Author

@helderco Thanks! No rush. 🙏

At a glance, I'd like to add not erroring on exit_code to the breaking changes pile. It's a big one, since many are depending on it, but are we at a point where we're stuck with that history?

Chatted about this with @sipsma and this is where we landed: #3192 (comment)

tl;dr The safest thing to me is to leave exit_code, stdout, and stderr erroring by default - or at least stdout. I can see the argument for stderr/exit_code not erroring by default (if you're asking for the exit code you might care about values other than 0; if you're asking for stderr you might be doing it after a failure). But stdout seems safest to error by default, since you might be writing a hastily written script that parses output, and from there I can justify the other two by just thinking it's consistent.

@github-actions

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@helderco

Copy link
Copy Markdown
Contributor

I think we should focus on getting a standardized solution to resolving lazyness:

The synchronization convenience could raise an error on failure, either by default or by having a flag. Same as suggested in #3192 (comment) but I'd rather move away from using ExitCode as a way to force a pipeline to execute.

Not yet clear to me if a Container.Run() helper would still make sense with #4205. Maybe it does.

@helderco

helderco commented Apr 4, 2023

Copy link
Copy Markdown
Contributor

Just to update that I still have this on my mind, but I'm going to submit a different proposal soon.

@gerhard

gerhard commented Apr 6, 2023

Copy link
Copy Markdown
Contributor

This looked to merge to me, but waiting on your thoughts @helderco before we push it through.

@TomChv TomChv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM too, let me know when it's ready so I can also update the Typescript Client if necessary.

@helderco

helderco commented Apr 6, 2023

Copy link
Copy Markdown
Contributor

Please hold on as I have concerns. We do need to replace the exitCode pattern, but I have a different suggestion for that and it's better to standardize on just one solution.

@helderco

Copy link
Copy Markdown
Contributor

As I understand it, we shouldn't use the GraphQL error for non-zero exit code in exec. It should be reserved for the inability to even run the command (e.g., command not configured, network error, etc...):

In this situation, with GraphQL, people tend to return a custom "Error" type as the response value instead. Similarly to that, I've submitted a proposal that uses an object as value (ExecResult), no matter if the command succeeds or not:

@github-actions

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions

github-actions Bot commented May 3, 2023

Copy link
Copy Markdown
Contributor

This PR was closed because it has been stalled for 7 days with no activity.

@github-actions github-actions Bot closed this May 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants