[erlang-questions] http_uri_parse/1 inconsistent return value + dialyser headache
Magnus Henoch
magnus.henoch@REDACTED
Tue Aug 14 13:04:04 CEST 2012
Zabrane Mickael <zabrane3@REDACTED> writes:
> http_uri_parse/1 returns inconsistent value since 15RB.
> I'm trying to build a wrapper around it to make my code works on =<R14B04 too.
>
> Here's what i got so far:
>
> -spec http_uri_parse([byte()]) -> {ok, tuple()} | {error, atom()}.
> http_uri_parse(URL) when is_list(URL) ->
> case http_uri:parse(URL) of
> {ok,{Scheme, UserInfo, Host, Port, Path, Query}} -> %% >=R15B
> http_uri_parse_1(Scheme, UserInfo, Host, Port, Path, Query);
> {Scheme, UserInfo, Host, Port, Path, Query} -> %% =< R14B <------- LINE 1106
> http_uri_parse_1(Scheme, UserInfo, Host, Port, Path, Query);
> Error ->
> Error
> end.
>
> http_uri_parse_1(Scheme, UserInfo, Host, Port, Path, Query) ->
> {ok, {Scheme, UserInfo, Host, Port, Path, Query}}.
>
> But Dilayzer isn't happy:
>
> Checking whether the PLT /Users/younes/.otp_plt is up-to-date... yes
> Proceeding with analysis...
> pimco.erl:1106: The pattern {Scheme, UserInfo, Host, Port, Path, Query} can never match the type {'error','no_scheme' | {_,atom(),_}}
>
>
> Any hint/help to get rid of this warning?
You've already been given the nice way to do it, so let me show the
hackish way to get rid of the warning. Dialyzer can't infer anything
about what a 'catch' expression returns, so if you write this instead:
case catch http_uri:parse(URL) of
then Dialyzer won't complain.
An advanced variant of that is to define a ?catch_for_dialyzer macro
that expands to nothing for normal compilation, and to 'catch' when
running Dialyzer.
Regards,
Magnus
More information about the erlang-questions
mailing list