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
Make action functions explicitly require the ExitCoder interface instead of an error #608
Comments
Should probably include something like this in the library as well func WrapExitCoder(f func(*cli.Context) error) func(*cli.Context) cli.ExitCoder {
return func(cliCtx *cli.Context) cli.ExitCoder {
err := f(cliCtx)
if err != nil {
return cli.NewExitError(err, 1)
}
return nil
}
} |
Hi @kklipsch, Thank you far raising this up! As I mention in #594 (comment); the error isn't silently ignored, but rather it is propagated up to the I'll mark this as something to reconsider as part of the |
👋 v2 just hit master, so we'll need to check if this is still a valid issue 🔍 |
This is still a valid issue. |
It is only tangentially related. Because v2 has already been released doing this should be part of a v3 since it is a breaking change. It is related because it is part of the work required in moving more of |
(I think this has been said by others in other contexts, but for the record:) I'm generally against requiring a library-specific error type given the interface-checking behavior that's already available. Please holler if you feel strongly about the intention to move towards a v3 type ActionFunc func(context.Context, *Command) error 💖 🤘🏼 |
The current release handles errors returned by the actions/subcommands, the current master branch ignores them. This behavior has flipped back and forth, but the current practice seems like the cli library will ignore errors that are returned by functions passed into it unless they match the ExitCoder interface.
If this is the way forward, make the functions check this at compile time instead of run time.
It seems completely unidiomatic for users of the api to expect errors they return from those functions to be silently ignored, so don't let them assume that they can pass errors back.
(As an aside, I think the whole ExitCoder thing should definitely be opt in and you should leave the behavior of returning errors and them being handled by the library as it is in the current release. But if you are going to go away from that behavior you should enforce it at compile time)
The text was updated successfully, but these errors were encountered: