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.

Unmatched argument returned when no equal sign used with option using a converter

See original GitHub issue

Issue noticed in app using PicoCLI Java 3.9.2 but also experienced with latest info.picocli:picocli:3.9.5.

Command line option code looks like this :

 @Option(
      names = {"--bootnodes"},
      split = ",",
      arity = "0..*",
      converter = EnodeToURIPropertyConverter.class)
  private final Collection<URI> bootNodes = null;

I’m skipping some useless details as not necessary for our story, but feel free to ask, the code is open source and can be seen at https://github.com/PegaSysEng/pantheon/blob/1966f485739ed75e4a8da8b95cd6a0afd2b365af/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java#L181

This option takes a list of enode strings separated by commas as input, or nothing if you want to override the default value. Default value is provided by an IDefaultValueProvider not visible here.

Our converter transforms a string to a URI using. This converter first check the string using a regex and com.google.common.base.Preconditions#checkArgument(boolean, java.lang.Object) if there’s any issue checkArgument throws an IllegalArgumentException(reason of the failure)

If you run pantheon --bootnodes enode://d2567893371ea5a6fa6371d483891ed0d129e79a8fc74d6df95a00a6545444cd4a6960bbffe0b4e2edcf35135271de57ee559c0909236bbc2074346ef2b5b47c@127.0.0.1:30304 this works as the input format is ok. But if you run for instance pantheon --bootnodes enode://invalidid@127.0.0.1:30304, the format being wrong it return :

Unmatched argument: enode://invalidid@127.0.0.1:30304
Did you mean: public-key?

It proposes public-key subcommand as a possible argument because it’s probably the closest thing it found but yet we don’t have any idea of the issue in the argument.

However, the strange thing, and that’s where it becomes interesting, is that when we call the program with same command pantheon --bootnodes=enode://invalidid@127.0.0.1:30304 but with an equal sign between the option and the value, it returns the full issue message Invalid value for option '--bootnodes' at index 0 (<enode://id@host:port>): cannot convert 'enode://invalidid@127.0.0.1:30304' to URI (java.lang.IllegalArgumentException: Enode URL contains an invalid node ID. Node ID must have 128 characters and shouldn't include the '0x' hex prefix.) which is what we want to enable users to understand why it fails.

So having the equal sign here changes how it handles the error. I guess it’s related to arity as we enable the option to have no value, but it seems to be related to the converter too as it work totally fine it you do this without a converter and an option of Collection<String> type.

Any idea where I can search ?

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
NicolasMassartcommented, Mar 13, 2019

I implemented your last proposal with just a change that I don’t use a converter but just a lambda and handle the error in the option method. I prefer to keep this that way for the moment as we are planning a refactoring soon. And it works like a charm. Thanks for your (as usual, always) very efficient help.

0reactions
remkopcommented, Mar 13, 2019

One could argue that even the error handling could (and perhaps should) be pushed into the converter. That would leave you with very simple code in the annotated option setter method:

private Collection<URI> bootNodes = null;

@Spec
CommandSpec spec;

@Option(names = {"--bootnodes"}, split = ",", arity = "0..*")
void replaceBootnodes(List<String> values) {
    bootNodes = EnodeToURIPropertyConverter.convertAll(values, "bootnode", spec);
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

picocli example showing the usage of multiple commands
1 Answer 1 · so i can run: java -jar target/jsontest2-0.0. · The example defines an --startDate and an --endDate option, and a...
Read more >
picocli - a mighty tiny command line interface
Argument files do have a limitation: parameter or option values enclosed in quotes must not be preceded by an equal sign. Something like...
Read more >
CommandLine.Help.Ansi - Apache Logging Services
275 * @return {@code true} if the end use may specify unmatched arguments on the command line, {@code false} otherwise 276 * @see...
Read more >
TPT10672 Error: Data contains a separator character which is ...
16.10 - TPT10672 Error: Data contains a separator character which is unmatched by the formatting string. - Teradata Tools and Utilities.
Read more >
NET - Parse the Command Line with System.CommandLine
The constructs supported include commands, options, arguments, ... for custom converters) that allow you, for example, to use System.IO.
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