[erlang-questions] http_uri_parse/1 inconsistent return value + dialyser headache
Zabrane Mickael
zabrane3@REDACTED
Tue Aug 14 14:38:19 CEST 2012
Following Magnus & Motiejus great suggestions, here it is:
%-------- put this marco somewhere (.hrl, top of your .erl)
-ifdef(DIALYZER_CATCH).
-define(CATCH_FOR_DIALYZER(X), catch X).
-else.
-define(CATCH_FOR_DIALYZER(X), X).
-endif.
%------- the new code
-spec http_uri_parse([byte()]) -> {ok, tuple()} | {error, atom()}.
http_uri_parse(URL) ->
case ?CATCH_FOR_DIALYZER(http_uri:parse(URL)) of
{ok,{_, _, _, _, _, _}} = Ret15 -> %% >=R15B
Ret15;
{_, _, _, _, _, _} = Ret14 -> %% =< R14B
{ok, Ret14};
Error ->
Error
end.
Add this flag "-DDIALYZER_CATCH=1" to your Dialyzer command line:
$ dialyzer --src src --plt /path ... -DDIALYZER_CATCH=1
Everything's perfect now.
Thanks for sharing these guys.
You saved my day.
Regards,
Zabrane
On Aug 14, 2012, at 2:06 PM, Magnus Henoch wrote:
> Motiejus Jakštys <desired.mta@REDACTED> writes:
>
>> On Tue, Aug 14, 2012 at 2:04 PM, Magnus Henoch
>> <magnus.henoch@REDACTED> wrote:
>>> Zabrane Mickael <zabrane3@REDACTED> writes:
>>>
>>> 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.
>>
>> Interesting. How do you know when you are running in dialyzer (i.e.
>> how would you define that macro)?
>
> The only way I know is to have your build system pass different -D flags
> for normal compilation and dialyzer.
>
> Regards,
> Magnus
More information about the erlang-questions
mailing list