basho / clique

CLI Framework for Erlang
Apache License 2.0
147 stars 49 forks source link

Typecasting errors can't be customized #44

Closed seancribbs closed 9 years ago

seancribbs commented 9 years ago

clique_error defines how to format all errors, but if I want to validate a flag is properly formed, I can't customize the output (actually I'll probably get function_clause). Example typecasting function:

ip(String) ->
    try
        [Ip, PortStr] = string:tokens(String, ":"),
        {ok, _} = inet_parse:address(Ip),
        Port = list_to_integer(PortStr),
        {Ip, Port}
    catch
        error:badarg ->
            {error, port_is_not_integer};
        error:badmatch ->
            {error, invalid_address}
    end.

I should be able to use symbolic errors in this case or handle them explicitly by running the command with flagged inputs. Currently I can do neither because clique_error is called immediately upon encountering an error.

seancribbs commented 9 years ago

Closing this. Our internal discussion suggests it would be better to reuse cuttlefish_datatypes, which I'm working on a PR for now.