Generic error messages

10 views
Skip to first unread message

firefl...@gmail.com

unread,
Sep 29, 2016, 10:26:00 AM9/29/16
to jopt-simple
Hi,

Thanks for the excellent tool!

I'm running into a problem. I have an option defined as follows:

opSchemasConfigRoot = parser.acceptsAll(Arrays.asList(
    "s", "schemas-config-root"), "schemas config root dir")
    .withRequiredArg()
    .withValuesConvertedBy(new PathConverter(PathProperties.DIRECTORY_EXISTING))
    .required();

As you can see, I'm checking to make sure that the directory specified as an argument to the option exists on the filesystem. However, when I run the code and specify a directory that does not exist, I get a very generic error message: 
   "Cannot parse argument '/home/greg/dev/testfiles/TDCConfig/Schema' of option s/schemas-config-root" 

The moment I specify a directory that does exist, the argument is accepted with no problems.

From a look at the code it appears I should be getting the message, "Directory [{0}] does not exist" from the ExceptionMessages.properties file.

What am I missing?

Thanks,
Greg


Paul Holser

unread,
Sep 29, 2016, 11:47:21 AM9/29/16
to jopt-simple
Hi Greg,

Thanks for your interest in JOpt Simple!

I believe that PathConverter is raising ValueConversionException("Directory [/home/greg/dev/testfiles/TDCConfig/Schema] does not exist"), which becomes the cause of the OptionArgumentConversionException("Cannot parse argument '/home/greg/dev/testfiles/TDCConfig/Schema'...") raised when you're accessing the argument of the option. The right exception is present, but isn't the top-level exception in the chain.

Hope this helps.

--p

firefl...@gmail.com

unread,
Sep 29, 2016, 11:58:50 AM9/29/16
to jopt-simple
Thanks Paul! I see. That makes sense.

Do you have any suggestions for the best way, then, to get the most specific message to return to the user (without any non-user-friendly stacktrace info)? My code currently looks like this:

try {
   OptionSet options = parser.parse(args);
   executeOptions(options);
}
catch (OptionException e) {
   System.out.println(e.getMessage());
   System.exit(1);
}

Paul Holser

unread,
Sep 29, 2016, 12:12:13 PM9/29/16
to jopt-simple
Greg, here are a couple of options for accessing the exception chain:

-- Guava: https://github.com/google/guava/wiki/ThrowablesExplained -- see the "Causal Chain" section

Hope this helps!

--p

firefl...@gmail.com

unread,
Sep 29, 2016, 12:16:15 PM9/29/16
to jopt-simple
OK, thanks for the info.
Reply all
Reply to author
Forward
0 new messages