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

support exit code for custom commands #30

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

Comments

@garethr
Copy link
Contributor

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 mpvl added the enhancement label Apr 16, 2019

@mpvl

This comment has been minimized.

Copy link
Contributor

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.

@garethr

This comment has been minimized.

Copy link
Contributor Author

commented Apr 16, 2019

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

@mpvl mpvl closed this in ffbc27e Apr 18, 2019

@garethr

This comment has been minimized.

Copy link
Contributor Author

commented Apr 19, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.