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

Empty error message when launching script without mandatory argument #17

Open
CristianCantoro opened this issue Jun 25, 2018 · 2 comments
Labels
blocked by docopt parser docopts uses an upper docopt parser which has a limitation. Parser must be improved. discussion

Comments

@CristianCantoro
Copy link

With the latest docopts-go build:

#!/usr/bin/env bash
# file: atest.sh

arg=''

eval "$(./docopts -V - -h - : "$@" <<EOF
Usage: atest.sh <arg>
       atest.sh ( -h | --help )
       atest.sh ( -V | --version )

      arg				An argument.

Options:
      -h, --help        Show this help message and exits.
      -V, --version     Print version and copyright information.
----
atest 0.1.0
EOF
)"

echo "$arg"

If I launch the script without the mandatory argument no error message is shown:

$ ./atest.
error: 
Usage: atest.sh <arg>
       atest.sh ( -h | --help )
       atest.sh ( -V | --version )
@CristianCantoro CristianCantoro changed the title Empty error message Empty error message when launching script without mandatory argument Jun 25, 2018
@Sylvain303
Copy link
Collaborator

Yes, thanks reporting.

error: is empty. It seems to be an internal behavior of the go lib docopt-go (or may be even python's docopt lib). I've to investigate in this code. Globally the docopt libs are bad for error reporting. :(

You can have almost same behavior with python's version of docopts:

In your working copy, fetch the tagged previous version (you'll need python interpretor and python's docopt too)

git checkout v0.6.1+fix

And retry your example, it gives:

sylvain@lap40:~/code/go/src/github.com/docopt/docopts/issues/17-Empty-error-without-mandatory-argument$ ./atest.sh 
Usage: atest.sh <arg>
       atest.sh ( -h | --help )
       atest.sh ( -V | --version )

How to fix that? Well, it would be an enhancement, the most advanced docopt lib seems to be the Rust version I've to look at it if they addressed this issue.

I'm creating an issue in golang version of the docopt lib for that too, if the maintainer could help.

https://github.com/Sylvain303/docopts/tree/debug-issues/issues/17-Empty-error-without-mandatory-argument

docopt/docopt.go#61

By design for now, calling without mandatory argument produce an error, but the display is to print, partial usage + exit status non zero. I added an error: part in the docopts code, which is empty in that case, because the lib fail with an empty message.

What would you suggest for docopts HelpHandler?

@CristianCantoro
Copy link
Author

@Sylvain303 said:

In your working copy, fetch the tagged previous version (you'll need python interpretor and python's docopt too)

Yes, I have seen the difference with the Python-based implementation of docopts.

By design for now, calling without mandatory argument produce an error, but the display is to print, partial usage + exit status non zero. I added an error: part in the docopts code, which is empty in that case, because the lib fail with an empty message.

What would you suggest for docopts HelpHandler?

I would suggest a message like Error: required argument <arg> is missing, or something like that.

@Sylvain303 Sylvain303 added blocked by docopt parser docopts uses an upper docopt parser which has a limitation. Parser must be improved. discussion labels Dec 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked by docopt parser docopts uses an upper docopt parser which has a limitation. Parser must be improved. discussion
Projects
None yet
Development

No branches or pull requests

2 participants