From b1012c31f38810c6754dcd4cf03f8d2bfb010506 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20G=C3=B6m=C3=B6ri?= Date: Fri, 29 May 2015 19:00:33 +0200 Subject: cover: handle undefined module when analysing to file It is possible that not just the source but even the beam of a module is not available when calling analyse_to_file. For example when coverdata is imported from an old file and since then a module was removed. Before this fix cover:analyse_to_file/3 could possibly never return because of a helper process crashed with error:undef and never reply to the caller. At the same time link the helper process to cover_server so any further error won't let the caller waiting indefinitely. --- lib/tools/src/cover.erl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'lib/tools/src') diff --git a/lib/tools/src/cover.erl b/lib/tools/src/cover.erl index 71e17e0ba1..24881a0ab0 100644 --- a/lib/tools/src/cover.erl +++ b/lib/tools/src/cover.erl @@ -782,7 +782,7 @@ main_process_loop(State) -> {From, {{analyse_to_file, Opts},Module}} -> S = try Loaded = is_loaded(Module, State), - spawn(fun() -> + spawn_link(fun() -> ?SPAWN_DBG(analyse_to_file,{Module,Opts}), do_parallel_analysis_to_file( Module, Opts, Loaded, From, State) @@ -2143,7 +2143,13 @@ find_source(Module, File0) -> throw_file(filename:join([BeamDir, "..", "src", Base])), %% Not in ../src: look for source path in compile info, but %% first look relative the beam directory. - Info = lists:keyfind(source, 1, Module:module_info(compile)), + Info = + try lists:keyfind(source, 1, Module:module_info(compile)) + catch error:undef -> + %% The module might have been imported + %% and the beam not available + throw({beam, File0}) + end, false == Info andalso throw({beam, File0}), %% stripped {source, SrcFile} = Info, throw_file(splice(BeamDir, SrcFile)), %% below ../src -- cgit v1.2.3