Skip to content

Commit

Permalink
Improved error handling of the situation, when refman XML file has un…
Browse files Browse the repository at this point in the history
…expected structure.
  • Loading branch information
arcusfelis committed Dec 28, 2012
1 parent 9aaa737 commit 5a82f03
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/inferno_refman_xml_reader.erl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ handle_erlref(#xmlElement{name = erlref, content = Con}) ->
X@ = #info_module{},
X@ = lists:foldl(fun handle_erlref_element/2, X@, Con),
X@ = set_function_module_names(X@),
sort_functions(X@).
X@ = sort_functions(X@),
validate_functions(X@).


set_function_module_names(M=#info_module{name = ModuleName, functions = Funs}) ->
NewFuns = [set_function_mfa(F#info_function{module_name = ModuleName})
Expand All @@ -51,6 +53,14 @@ set_function_module_names(M=#info_module{name = ModuleName, functions = Funs}) -
sort_functions(M) ->
M#info_module{functions = lists:keysort(#info_function.mfa, old())}.

validate_functions(M=#info_module{functions = Funs}) ->
{ValidFuns, InvalidFuns} = lists:partition(fun is_valid_function/1, Funs),
[error:error_msg("Invalid function: ~p~n", [X]) || X <- InvalidFuns],
M#info_module{functions = ValidFuns}.

is_valid_function(#info_function{module_name = M, name = F, arity = A}) ->
not lists:member(undefined, [M, F, A]).

set_function_mfa(X=#info_function{module_name = M, name = F, arity = A}) ->
X#info_function{mfa = {M, F, A}}.

Expand Down
14 changes: 12 additions & 2 deletions src/inferno_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -439,10 +439,20 @@ read_module_documentation(ModuleName, M2DF) ->
case dict:find(ModuleName, M2DF) of
{ok, FileName} ->
case inferno_refman_xml_reader:filename_to_xml(FileName) of
{ok, XML} -> inferno_refman_xml_reader:handle_module(XML);
{ok, XML} ->
try
inferno_refman_xml_reader:handle_module(XML)
catch error:Reason ->
error_logger:error_msg("Bad file format ~ts. "
"Ignore and continue.~nError ~p~n"
"Stacktrace:~n~p~n",
[FileName, Reason, erlang:get_stacktrace()]),
undefined
end;
{error, Reason} ->
%% File is not found?
error_logger:error_msg("inferno_refman_xml_reader "
"returns ~p. Ignore and continue.~n", [Reason]),
"returns ~p.~n Ignore and continue.~n", [Reason]),
undefined
end;
error -> undefined
Expand Down

0 comments on commit 5a82f03

Please sign in to comment.