Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/processone/ejabberd.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>2017-01-09 17:02:17 +0300
committerEvgeniy Khramtsov <ekhramtsov@process-one.net>2017-01-09 17:02:17 +0300
commit1e55e018e534aa82541c5f460063a237192b768c (patch)
tree9584ed46fe2b18770343399254b0ba15ff591e51 /src/ejabberd_hooks.erl
parent3dd2a614ace3c2fe4c82dac001c29d643bd57098 (diff)
Adopt remaining code to support new hooks
Diffstat (limited to 'src/ejabberd_hooks.erl')
-rw-r--r--src/ejabberd_hooks.erl22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/ejabberd_hooks.erl b/src/ejabberd_hooks.erl
index 612d5afe5..f63d1d75c 100644
--- a/src/ejabberd_hooks.erl
+++ b/src/ejabberd_hooks.erl
@@ -326,10 +326,9 @@ run1([{_Seq, Node, Module, Function} | Ls], Hook, Args) ->
run1(Ls, Hook, Args)
end;
run1([{_Seq, Module, Function} | Ls], Hook, Args) ->
- Res = safe_apply(Module, Function, Args),
+ Res = safe_apply(Hook, Module, Function, Args),
case Res of
- {'EXIT', Reason} ->
- ?ERROR_MSG("~p~nrunning hook: ~p", [Reason, {Hook, Args}]),
+ 'EXIT' ->
run1(Ls, Hook, Args);
stop ->
ok;
@@ -362,10 +361,9 @@ run_fold1([{_Seq, Node, Module, Function} | Ls], Hook, Val, Args) ->
run_fold1(Ls, Hook, NewVal, Args)
end;
run_fold1([{_Seq, Module, Function} | Ls], Hook, Val, Args) ->
- Res = safe_apply(Module, Function, [Val | Args]),
+ Res = safe_apply(Hook, Module, Function, [Val | Args]),
case Res of
- {'EXIT', Reason} ->
- ?ERROR_MSG("~p~nrunning hook: ~p", [Reason, {Hook, Args}]),
+ 'EXIT' ->
run_fold1(Ls, Hook, Val, Args);
stop ->
stopped;
@@ -375,12 +373,20 @@ run_fold1([{_Seq, Module, Function} | Ls], Hook, Val, Args) ->
run_fold1(Ls, Hook, NewVal, Args)
end.
-safe_apply(Module, Function, Args) ->
+safe_apply(Hook, Module, Function, Args) ->
try if is_function(Function) ->
apply(Function, Args);
true ->
apply(Module, Function, Args)
end
catch E:R when E /= exit, R /= normal ->
- {'EXIT', {E, {R, erlang:get_stacktrace()}}}
+ ?ERROR_MSG("Hook ~p crashed when running ~p:~p/~p:~n"
+ "** Reason = ~p~n"
+ "** Arguments = ~p",
+ [Hook, Module, Function, length(Args),
+ {E, R, get_stacktrace()}, Args]),
+ 'EXIT'
end.
+
+get_stacktrace() ->
+ [{Mod, Fun, Loc, Args} || {Mod, Fun, Args, Loc} <- erlang:get_stacktrace()].