26
1
mirror of https://github.com/processone/ejabberd.git synced 2025-01-03 18:02:28 +01:00

Get rid of catch-all in mod_pubsub

This commit is contained in:
Evgeniy Khramtsov 2018-03-13 22:10:58 +03:00
parent 6b079c0ab3
commit 99b41146b1

View File

@ -373,13 +373,9 @@ init_plugins(Host, ServerHost, Opts) ->
PluginsOK = lists:foldl( PluginsOK = lists:foldl(
fun (Name, Acc) -> fun (Name, Acc) ->
Plugin = plugin(Host, Name), Plugin = plugin(Host, Name),
case catch apply(Plugin, init, [Host, ServerHost, Opts]) of apply(Plugin, init, [Host, ServerHost, Opts]),
{'EXIT', _Error} -> ?DEBUG("** init ~s plugin", [Name]),
Acc; [Name | Acc]
_ ->
?DEBUG("** init ~s plugin", [Name]),
[Name | Acc]
end
end, end,
[], Plugins), [], Plugins),
{lists:reverse(PluginsOK), TreePlugin, PepMapping}. {lists:reverse(PluginsOK), TreePlugin, PepMapping}.
@ -3527,7 +3523,7 @@ tree_call({_User, Server, _Resource}, Function, Args) ->
tree_call(Host, Function, Args) -> tree_call(Host, Function, Args) ->
Tree = tree(Host), Tree = tree(Host),
?DEBUG("tree_call apply(~s, ~s, ~p) @ ~s", [Tree, Function, Args, Host]), ?DEBUG("tree_call apply(~s, ~s, ~p) @ ~s", [Tree, Function, Args, Host]),
catch apply(Tree, Function, Args). apply(Tree, Function, Args).
tree_action(Host, Function, Args) -> tree_action(Host, Function, Args) ->
?DEBUG("tree_action ~p ~p ~p", [Host, Function, Args]), ?DEBUG("tree_action ~p ~p ~p", [Host, Function, Args]),
@ -3535,9 +3531,9 @@ tree_action(Host, Function, Args) ->
Fun = fun () -> tree_call(Host, Function, Args) end, Fun = fun () -> tree_call(Host, Function, Args) end,
case gen_mod:get_module_opt(ServerHost, ?MODULE, db_type) of case gen_mod:get_module_opt(ServerHost, ?MODULE, db_type) of
mnesia -> mnesia ->
catch mnesia:sync_dirty(Fun); mnesia:sync_dirty(Fun);
sql -> sql ->
case catch ejabberd_sql:sql_bloc(ServerHost, Fun) of case ejabberd_sql:sql_bloc(ServerHost, Fun) of
{atomic, Result} -> {atomic, Result} ->
Result; Result;
{aborted, Reason} -> {aborted, Reason} ->
@ -3545,15 +3541,8 @@ tree_action(Host, Function, Args) ->
ErrTxt = <<"Database failure">>, ErrTxt = <<"Database failure">>,
{error, xmpp:err_internal_server_error(ErrTxt, ?MYLANG)} {error, xmpp:err_internal_server_error(ErrTxt, ?MYLANG)}
end; end;
Other -> _ ->
case catch Fun() of Fun()
{'EXIT', _} ->
?ERROR_MSG("unsupported backend: ~p~n", [Other]),
ErrTxt = <<"Database failure">>,
{error, xmpp:err_internal_server_error(ErrTxt, ?MYLANG)};
Result ->
Result
end
end. end.
%% @doc <p>node plugin call.</p> %% @doc <p>node plugin call.</p>
@ -3602,26 +3591,20 @@ transaction(Host, Node, Action, Trans) ->
transaction(Host, Fun, Trans) -> transaction(Host, Fun, Trans) ->
ServerHost = serverhost(Host), ServerHost = serverhost(Host),
DBType = gen_mod:get_module_opt(ServerHost, ?MODULE, db_type), DBType = gen_mod:get_module_opt(ServerHost, ?MODULE, db_type),
Retry = case DBType of do_transaction(ServerHost, Fun, Trans, DBType).
sql -> 2;
_ -> 1
end,
transaction_retry(Host, ServerHost, Fun, Trans, DBType, Retry).
transaction_retry(_Host, _ServerHost, _Fun, _Trans, _DBType, 0) -> do_transaction(ServerHost, Fun, Trans, DBType) ->
{error, xmpp:err_internal_server_error(<<"Database failure">>, ?MYLANG)};
transaction_retry(Host, ServerHost, Fun, Trans, DBType, Count) ->
Res = case DBType of Res = case DBType of
mnesia -> mnesia ->
catch mnesia:Trans(Fun); mnesia:Trans(Fun);
sql -> sql ->
SqlFun = case Trans of SqlFun = case Trans of
transaction -> sql_transaction; transaction -> sql_transaction;
_ -> sql_bloc _ -> sql_bloc
end, end,
catch ejabberd_sql:SqlFun(ServerHost, Fun); ejabberd_sql:SqlFun(ServerHost, Fun);
_ -> _ ->
catch Fun() Fun()
end, end,
case Res of case Res of
{result, Result} -> {result, Result} ->
@ -3635,12 +3618,6 @@ transaction_retry(Host, ServerHost, Fun, Trans, DBType, Count) ->
{aborted, Reason} -> {aborted, Reason} ->
?ERROR_MSG("transaction return internal error: ~p~n", [{aborted, Reason}]), ?ERROR_MSG("transaction return internal error: ~p~n", [{aborted, Reason}]),
{error, xmpp:err_internal_server_error(<<"Database failure">>, ?MYLANG)}; {error, xmpp:err_internal_server_error(<<"Database failure">>, ?MYLANG)};
{'EXIT', {timeout, _} = Reason} ->
?ERROR_MSG("transaction return internal error: ~p~n", [Reason]),
transaction_retry(Host, ServerHost, Fun, Trans, DBType, Count - 1);
{'EXIT', Reason} ->
?ERROR_MSG("transaction return internal error: ~p~n", [{'EXIT', Reason}]),
{error, xmpp:err_internal_server_error(<<"Database failure">>, ?MYLANG)};
Other -> Other ->
?ERROR_MSG("transaction return internal error: ~p~n", [Other]), ?ERROR_MSG("transaction return internal error: ~p~n", [Other]),
{error, xmpp:err_internal_server_error(<<"Database failure">>, ?MYLANG)} {error, xmpp:err_internal_server_error(<<"Database failure">>, ?MYLANG)}