airlift / airline

Java annotation-based framework for parsing Git like command line structures
Apache License 2.0
846 stars 138 forks source link

ParseOptionConversionException is not transporting the cause #67

Closed rtib closed 5 years ago

rtib commented 5 years ago

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.

findepi commented 5 years ago

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

rtib commented 5 years ago

I‘ll invest some time looking into it.