Permalink
Browse files

Improved error handling of the situation, when refman XML file has un…

…expected structure.
  • Loading branch information...
1 parent 9aaa737 commit 5a82f03a87f06a194252fa67ccf831afd83ec012 @arcusfelis committed Dec 28, 2012
Showing with 23 additions and 3 deletions.
  1. +11 −1 src/inferno_refman_xml_reader.erl
  2. +12 −2 src/inferno_server.erl
@@ -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})
@@ -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}}.
View
@@ -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

0 comments on commit 5a82f03

Please sign in to comment.