Skip to content
This repository has been archived by the owner. It is now read-only.

support exit code for custom commands #30

Closed
garethr opened this issue Apr 11, 2019 · 4 comments
Closed

support exit code for custom commands #30

garethr opened this issue Apr 11, 2019 · 4 comments

Comments

@garethr
Copy link
Contributor

@garethr garethr commented Apr 11, 2019

I was experimenting with adding a set of validation commands to my cue configuration, in _tools.cue files. The commands they exec out to will return non-zero exit codes when those commands fail, but running them via the cue <cmd> runner eats those exit codes and always returns 0. Checking the code this doesn't appear to be something I can add to the print task.

cue/cmd/cue/cmd/custom.go

Lines 299 to 310 in 2b0e7cd

func (c *printCmd) Run(ctx context.Context, v cue.Value) (res interface{}, err error) {
str, err := v.Lookup("text").String()
if err != nil {
return nil, err
}
if testOut != nil {
fmt.Fprintln(testOut, str)
} else {
fmt.Println(str)
}
return nil, nil
}

Is there a way of achieving this at present? Supporting passing through the exit codes would make integration of cue commands into pipelines easier.

@mpvl
Copy link
Contributor

@mpvl mpvl commented Apr 16, 2019

Yes, it makes sense to at least return a non-zero error code on failure. To what extent does it need to be the same code? As there may be multiple tasks executed concurrently, returning the code of the failed first task may result in indeterministic behavior, so simply returning 1, for instance, may be a better approach.

Loading

@garethr
Copy link
Contributor Author

@garethr garethr commented Apr 16, 2019

Agreed, returning 1 makes sense in all the cases I have in mind.

Loading

@mpvl mpvl closed this in ffbc27e Apr 18, 2019
@garethr
Copy link
Contributor Author

@garethr garethr commented Apr 19, 2019

Thanks, just tested this out and this works for me. Appreciated.

Loading

@cueckoo
Copy link

@cueckoo cueckoo commented Jul 3, 2021

This issue has been migrated to cue-lang/cue#30.

For more details about CUE's migration to a new home, please see cue-lang/cue#1078.

Loading

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants