question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@Parameters validation and error messages if arity > 0 is buggy

See original GitHub issue

PicoCLI version: 1.0.1

I have a class annotated with @Parameters(arity = "1..*", description = "The input files") and discovered somethings about the validation of arity >= 1:

  1. Fails to validate in some cases
  2. Validates in some other cases but throws different messages based on whether an empty String ("") or zero-length String[] (new String[0]) is supplied to the parse(xx) method
         class Example {
            @Option(names = {"-h", "--help"}, help = true,
                    description = "Displays this help message and quits.")
            private boolean helpRequested;

            @Option(names = {"-o",
                    "--out-dir"}, required = true, usageHelp = true, description = "The output directory")
            private File outputDir;

            @Parameters(arity = "1..*", description = "The input files")
            private File[] inputFiles;
        }

        //Should've failed as inputFiles were not provided
        new CommandLine(new Example()).parse("-o /tmp");

        //Should've failed as inputFiles were not provided
        new CommandLine(new Example()).parse("-o", " /tmp");

        try {
            new CommandLine(new Example()).parse("");
        } catch (MissingParameterException e) {
            //Type 1 error message.
            e.printStackTrace();
        }

        try {
            new CommandLine(new Example()).parse();
        } catch (MissingParameterException e) {
            //Type 2 error message but the parameters are "essentially" the same as type 1.
            e.printStackTrace();
        }

Type 1 exception:

picocli.CommandLine$MissingParameterException: Missing required parameters at positions 0..*: inputFiles
	at picocli.CommandLine$Interpreter.assertNoMissingParameters(CommandLine.java:2159)
	at picocli.CommandLine$Interpreter.applyOption(CommandLine.java:1745)
	at picocli.CommandLine$Interpreter.processPositionalParameters0(CommandLine.java:1645)
	at picocli.CommandLine$Interpreter.processPositionalParameters(CommandLine.java:1601)
	at picocli.CommandLine$Interpreter.processArguments(CommandLine.java:1594)
	at picocli.CommandLine$Interpreter.parse(CommandLine.java:1501)
	at picocli.CommandLine$Interpreter.parse(CommandLine.java:1484)
	at picocli.CommandLine.parse(CommandLine.java:334)
	at Main.main(Main.java:32)

Type 2 exception:

picocli.CommandLine$MissingParameterException: Missing required options [outputDir, inputFiles]
	at picocli.CommandLine$MissingParameterException.create(CommandLine.java:4086)
	at picocli.CommandLine$MissingParameterException.access$1600(CommandLine.java:4071)
	at picocli.CommandLine$Interpreter.parse(CommandLine.java:1511)
	at picocli.CommandLine$Interpreter.parse(CommandLine.java:1484)
	at picocli.CommandLine.parse(CommandLine.java:334)
	at Main.main(Main.java:39)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
remkopcommented, Oct 13, 2017

After removing the usageHelp=true from the -o option, things worked mostly as expected.

Mostly, but not completely.

I agree that the difference between the Type1 and the Type2 exceptions is strange.

The second case seems okay: both the required -o option and the required positional parameter are reported as missing. This is as expected.

In the first case, an empty string parameter is passed. I would expect this to be parsed as a positional parameter (an <inputFiles> value), resulting in a Missing required option '-o=<outputDir>' exception. Instead what we are getting is a Missing required parameters at positions 0..*: <inputFiles>. I’ve tracked down and fixed the bug that causes this.

The fix has been pushed to master and I added your example as a new set of test cases (testIssue203() at the bottom).

Thanks for raising this! Please verify that master behaves as expected now.

0reactions
AshwinJaycommented, Oct 17, 2017

Thanks @remkop !

Read more comments on GitHub >

github_iconTop Results From Across the Web

https://dev.w3.org/xmlschema/XSV/driver.py
validateElement import validate from XSV.compile. ... dontWarn=dw f.errors=0 if baseURI is None: base = urlunsplit(('file','',os.getcwd().replace('\\' ...
Read more >
jest-validate | Yarn - Package Manager
Generic configuration validation tool that helps you with warnings, errors and deprecation messages as well as showing users examples of correct configuration.
Read more >
Advanced - 1.68.0 - Boost C++ Libraries
This library will never actually execute the pure virtual function body while it is calling the pure virtual function default implementation to check...
Read more >
Clojure `+` behaviour with nil values - Stack Overflow
1 Answer 1 · I think generally speaking Clojure adopts a 'garbage in, garbage out' attitude to argument validation, so I think it...
Read more >
Type Specifications and Erlang
We'll see why when we get to discuss how its type inference algorithm works, later in the chapter. Some Windows users will see...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found