airlift / airline

Java annotation-based framework for parsing Git like command line structures

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ParseOptionConversionException is not transporting the cause

rtib opened this issue · comments

I have the following problem: my CLI application has commands accepting an argument, which I provide a class, ClusterID having a constructor taking a String, for parsing and validating the argument.

    @Arguments(required = true, description = "Cluster ID ...")
    public ClusterID cluster;

While this is working fine for the happy case, ClusterID's constructor would raise an exception with a proper message if something has failed.

I'd like to report that message to the user, but I get an io.airlift.airline.ParseOptionConversionException only, without the cause.

io.airlift.airline.ParseOptionConversionException: cluster: can not convert "098" to a ClusterID
	at io.airlift.airline.TypeConverter.convert(TypeConverter.java:78)
	at io.airlift.airline.Parser.parseArg(Parser.java:265)
	at io.airlift.airline.Parser.parseArgs(Parser.java:255)
	at io.airlift.airline.Parser.parse(Parser.java:70)
	at io.airlift.airline.Cli.parse(Cli.java:121)
	at io.airlift.airline.Cli.parse(Cli.java:108)
	at io.airlift.airline.Cli.parse(Cli.java:103)
	at Main.main(Main.java:53)

I'd appreciate TypeConverter.java#L75 would not ignore the Throwable but pass in on io.airlift.airline.ParseOptionConversionException as cause.

This is reasonable. @rtib is it something you want to make a PR for?

I‘ll invest some time looking into it.