diff options
author | Fred Hebert <mononcqc@ferd.ca> | 2017-06-13 07:17:07 -0400 |
---|---|---|
committer | Fred Hebert <mononcqc@ferd.ca> | 2017-06-13 07:17:07 -0400 |
commit | 7f1301f635b8c07fd22ffdf1c9dcf6f5cbba8655 (patch) | |
tree | 16908378472fc97530593b0e6b63bc4807b2a5ea /src | |
parent | 9b1aa9191027647eb370eb6b0d5fa9cbfacc21d4 (diff) |
Prevent xref crashes with undef behaviours
When a given behaviour module does not exist, rebar3 brutally crashes.
This patch makes it so instead, there is a warning output menitoning the
missing behaviour, and this one is omitted from the unused function
calls check. This means that unused calls will instead be shown for the
module implementing a non-existing behaviour, as if no behaviour were
declared in the first place.
Diffstat (limited to 'src')
-rw-r--r-- | src/rebar_prv_xref.erl | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/rebar_prv_xref.erl b/src/rebar_prv_xref.erl index 51154b5..e6a074f 100644 --- a/src/rebar_prv_xref.erl +++ b/src/rebar_prv_xref.erl @@ -168,8 +168,15 @@ keyall(Key, List) -> lists:flatmap(fun({K, L}) when Key =:= K -> L; (_) -> [] end, List). get_behaviour_callbacks(exports_not_used, Attributes) -> - [B:behaviour_info(callbacks) || B <- keyall(behaviour, Attributes) ++ - keyall(behavior, Attributes)]; + lists:map(fun(Mod) -> + try + Mod:behaviour_info(callbacks) + catch + error:undef -> + ?WARN("Behaviour ~p is used but cannot be found.", [Mod]), + [] + end + end, keyall(behaviour, Attributes) ++ keyall(behavior, Attributes)); get_behaviour_callbacks(_XrefCheck, _Attributes) -> []. |