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

Flag errors are not ExitCoder #1088

Open
5 of 7 tasks
Nokel81 opened this issue Mar 23, 2020 · 15 comments
Open
5 of 7 tasks

Flag errors are not ExitCoder #1088

Nokel81 opened this issue Mar 23, 2020 · 15 comments
Labels
area/v3 relates to / is being considered for v3 help wanted please help if you can! kind/bug describes or fixes a bug status/confirmed confirmed to be valid, but work has yet to start
Milestone

Comments

@Nokel81
Copy link

Nokel81 commented Mar 23, 2020

my urfave/cli version is

v2.2.0

Checklist

  • Are you running the latest v2 release? The list of releases is here.
  • Did you check the manual for your release? The v2 manual is here
  • Did you perform a search about this problem? Here's the Github guide about searching.

Dependency Management

  • My project is using go modules.
  • My project is using vendoring.
  • My project is automatically downloading the latest version.
  • I am unsure of what my dependency management setup is.

Describe the bug

If you mark a flag as "required" for instance and it is missing, then the error that is bubbled up to the root cli.App.Run(..) call does not satisfy the required interfaces for HandleExitCoder.

To reproduce

  1. Have a required flag
  2. Have a panic after the call to HandleExitCoder
  3. Call the CLI without it

Observed behavior

The panic is called

Expected behavior

HandleExitCoder calls os.Exit(..)

Additional context

It should be possible to define the exit code for a specific flag (or for the application in general) if there are flag errors. Be them required, or not defined as a flag.

@Nokel81 Nokel81 added area/v2 relates to / is being considered for v2 kind/bug describes or fixes a bug status/triage maintainers still need to look into this labels Mar 23, 2020
@coilysiren
Copy link
Member

Makes sense! I would be happy to review a PR from anyone that fixes this 🙏

@coilysiren coilysiren added help wanted please help if you can! status/confirmed confirmed to be valid, but work has yet to start and removed status/triage maintainers still need to look into this labels Mar 23, 2020
@Nokel81
Copy link
Author

Nokel81 commented Mar 23, 2020

Would you prefer it to be a global setting for the whole App or Command or one specific to a flag?

@coilysiren
Copy link
Member

I'm not quite sure I'm understanding where a setting is coming into play here? I think my expectation is that the existing required flags error satisfies that HandleExitCoder interface.

@Nokel81
Copy link
Author

Nokel81 commented Mar 23, 2020

Yes but what should that exit code be? Should it be static and unchanging? I think that it should be able to be set by users of this library.

@coilysiren
Copy link
Member

Ah, gotcha! I'm of the opinion that we should either:

  • exit 0 with a global setting for configuring that
  • return when hitting required flags errors, in which a way that an explicit os.Exit isn't required

I'd be interested in more opinions from @urfave/cli though!

@Nokel81
Copy link
Author

Nokel81 commented Mar 24, 2020

I think returning an ExitCoder should be part of it.

Another option (I like this one because it is the most customization while still having a fast path for global setting):

  • Have a hierarchy of exit codes: use app setting or, if set, command setting or, if set, flag setting

@Nokel81
Copy link
Author

Nokel81 commented Mar 24, 2020

Though, now that I have looked more deeply at the code, there is a slight problem with having the flags define their own exit codes. What happens if multiple flags produce errors (currently only required).

  • Should the first win?
  • Should the last win?
  • Should the highest value win?
  • Should the lowest non-zero win? (What about negative values?)

I have looked at some what other programs do (such as posix exit). It seems to be undefined if you try and use a negative number, or if you try and use a number outside of [0, 255] since that is all that wait_pid will return. All this is to say that the last option (lowest wins) should probably be never considered.

@coilysiren
Copy link
Member

Nice investigative work ✨

@stale
Copy link

stale bot commented Jun 28, 2020

This issue or PR has been automatically marked as stale because it has not had recent activity. Please add a comment bumping this if you're still interested in it's resolution! Thanks for your help, please let us know if you need anything else.

@stale stale bot added the status/stale stale due to the age of it's last update label Jun 28, 2020
@Nokel81
Copy link
Author

Nokel81 commented Jun 29, 2020

bump

@stale
Copy link

stale bot commented Jun 29, 2020

This issue or PR has been bumped and is no longer marked as stale! Feel free to bump it again in the future, if it's still relevant.

@stale stale bot removed the status/stale stale due to the age of it's last update label Jun 29, 2020
@stale
Copy link

stale bot commented Sep 27, 2020

This issue or PR has been automatically marked as stale because it has not had recent activity. Please add a comment bumping this if you're still interested in it's resolution! Thanks for your help, please let us know if you need anything else.

@stale stale bot added the status/stale stale due to the age of it's last update label Sep 27, 2020
@stale
Copy link

stale bot commented Oct 27, 2020

Closing this as it has become stale.

@stale stale bot closed this as completed Oct 27, 2020
@coilysiren coilysiren reopened this Jan 27, 2021
@stale
Copy link

stale bot commented Jan 27, 2021

This issue or PR has been bumped and is no longer marked as stale! Feel free to bump it again in the future, if it's still relevant.

@stale stale bot removed the status/stale stale due to the age of it's last update label Jan 27, 2021
@meatballhat meatballhat changed the title v2 bug: Flag errors are not ExitCoder Flag errors are not ExitCoder Apr 21, 2022
@meatballhat meatballhat modified the milestone: Release 2.5.0 Apr 21, 2022
@dearchap
Copy link
Contributor

@urfave/admins Any thoughts on this ?

@dearchap dearchap added area/v3 relates to / is being considered for v3 and removed area/v2 relates to / is being considered for v2 labels Dec 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/v3 relates to / is being considered for v3 help wanted please help if you can! kind/bug describes or fixes a bug status/confirmed confirmed to be valid, but work has yet to start
Projects
None yet
Development

No branches or pull requests

4 participants