akamensky / argparse

Argparse for golang. Just because `flag` sucks
MIT License
604 stars 62 forks source link

Validation error messages should go to stderr not stdout #64

Closed josegonzalez closed 3 years ago

josegonzalez commented 4 years ago

I'm using argparse as part of go-procfile-util, and capturing output of that command. Unfortunately, if flags are passed in, the command will exit non-zero but will have some output, which can be a bit confusing if you expect no output on error (my project doesn't have stdout unless there are no errors).

Would be great if all errors went to stderr instead of stdout.

jhughes1153 commented 4 years ago

Yeah python does this so that makes sense

akamensky commented 4 years ago

Generally you are correct that errors should go to stderr and other output to stdout (that convention way predates python just fyi). I cannot recall what was the reasoning behind not doing that, but either way the errors are (or at least should be) returnable and the it is your code that decides where to output the error (stdout or stderr or elsewhere).

The way examples in this repo implement it is just an example. Your code can decide what to do with the error message.

The only cases I know which won't allow you to decide this is when the error is not in input, but in implementation (but I think most of those places cause panic and not just print error). This is the difficult part because with good flexibility there always will be edge cases of implementation that will never work, in C/C++ this is achievable with #error pre-processor macro that will prevent you from compiling, which is not possible in Go (unfortunately).

You can check GoDoc for more information.

akamensky commented 4 years ago

@josegonzalez Otherwise please provide example of code that does not allow you to handle errors and prints to stdout instead of stderr.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed soon if no further activity occurs. Thank you for your contributions. Feel free to comment or otherwise update to keep it alive.

stale[bot] commented 3 years ago

Closing due to old age. Feel free to re-open or ping maintainers.