24
1
mirror of https://github.com/processone/ejabberd.git synced 2024-06-14 22:00:16 +02:00

Don't hide errors using catch

This commit is contained in:
Evgeny Khramtsov 2019-07-15 17:03:29 +03:00
parent a00496a38f
commit e1f3526466

View File

@ -648,23 +648,17 @@ get_local_items(_Host, _, _Server, _Lang) ->
-spec get_online_vh_users(binary()) -> [disco_item()]. -spec get_online_vh_users(binary()) -> [disco_item()].
get_online_vh_users(Host) -> get_online_vh_users(Host) ->
case catch ejabberd_sm:get_vh_session_list(Host) of USRs = ejabberd_sm:get_vh_session_list(Host),
{'EXIT', _Reason} -> [];
USRs ->
SURs = lists:sort([{S, U, R} || {U, S, R} <- USRs]), SURs = lists:sort([{S, U, R} || {U, S, R} <- USRs]),
lists:map( lists:map(
fun({S, U, R}) -> fun({S, U, R}) ->
#disco_item{jid = jid:make(U, S, R), #disco_item{jid = jid:make(U, S, R),
name = <<U/binary, "@", S/binary>>} name = <<U/binary, "@", S/binary>>}
end, SURs) end, SURs).
end.
-spec get_all_vh_users(binary()) -> [disco_item()]. -spec get_all_vh_users(binary()) -> [disco_item()].
get_all_vh_users(Host) -> get_all_vh_users(Host) ->
case catch ejabberd_auth:get_users(Host) Users = ejabberd_auth:get_users(Host),
of
{'EXIT', _Reason} -> [];
Users ->
SUsers = lists:sort([{S, U} || {U, S} <- Users]), SUsers = lists:sort([{S, U} || {U, S} <- Users]),
case length(SUsers) of case length(SUsers) of
N when N =< 100 -> N when N =< 100 ->
@ -673,10 +667,10 @@ get_all_vh_users(Host) ->
name = <<U/binary, $@, S/binary>>} name = <<U/binary, $@, S/binary>>}
end, SUsers); end, SUsers);
N -> N ->
NParts = trunc(math:sqrt(N * 6.17999999999999993783e-1)) NParts = trunc(math:sqrt(N * 6.17999999999999993783e-1)) + 1,
+ 1,
M = trunc(N / NParts) + 1, M = trunc(N / NParts) + 1,
lists:map(fun (K) -> lists:map(
fun (K) ->
L = K + M - 1, L = K + M - 1,
Node = <<"@", Node = <<"@",
(integer_to_binary(K))/binary, (integer_to_binary(K))/binary,
@ -691,19 +685,14 @@ get_all_vh_users(Host) ->
#disco_item{jid = jid:make(Host), #disco_item{jid = jid:make(Host),
node = <<"all users/", Node/binary>>, node = <<"all users/", Node/binary>>,
name = Name} name = Name}
end, end, lists:seq(1, N, M))
lists:seq(1, N, M))
end
end. end.
-spec get_outgoing_s2s(binary(), binary()) -> [disco_item()]. -spec get_outgoing_s2s(binary(), binary()) -> [disco_item()].
get_outgoing_s2s(Host, Lang) -> get_outgoing_s2s(Host, Lang) ->
case catch ejabberd_s2s:dirty_get_connections() of Connections = ejabberd_s2s:dirty_get_connections(),
{'EXIT', _Reason} -> [];
Connections ->
DotHost = <<".", Host/binary>>, DotHost = <<".", Host/binary>>,
TConns = [TH TConns = [TH || {FH, TH} <- Connections,
|| {FH, TH} <- Connections,
Host == FH orelse str:suffix(DotHost, FH)], Host == FH orelse str:suffix(DotHost, FH)],
lists:map( lists:map(
fun (T) -> fun (T) ->
@ -711,58 +700,45 @@ get_outgoing_s2s(Host, Lang) ->
#disco_item{jid = jid:make(Host), #disco_item{jid = jid:make(Host),
node = <<"outgoing s2s/", T/binary>>, node = <<"outgoing s2s/", T/binary>>,
name = Name} name = Name}
end, lists:usort(TConns)) end, lists:usort(TConns)).
end.
-spec get_outgoing_s2s(binary(), binary(), binary()) -> [disco_item()]. -spec get_outgoing_s2s(binary(), binary(), binary()) -> [disco_item()].
get_outgoing_s2s(Host, Lang, To) -> get_outgoing_s2s(Host, Lang, To) ->
case catch ejabberd_s2s:dirty_get_connections() of Connections = ejabberd_s2s:dirty_get_connections(),
{'EXIT', _Reason} -> [];
Connections ->
lists:map( lists:map(
fun ({F, _T}) -> fun ({F, _T}) ->
Node = <<"outgoing s2s/", To/binary, "/", F/binary>>, Node = <<"outgoing s2s/", To/binary, "/", F/binary>>,
Name = str:format(tr(Lang, ?T("From ~s")), [F]), Name = str:format(tr(Lang, ?T("From ~s")), [F]),
#disco_item{jid = jid:make(Host), node = Node, name = Name} #disco_item{jid = jid:make(Host), node = Node, name = Name}
end, end,
lists:keysort(1, lists:keysort(
lists:filter(fun (E) -> element(2, E) == To 1,
end, lists:filter(fun (E) -> element(2, E) == To end,
Connections))) Connections))).
end.
-spec get_running_nodes(binary(), binary()) -> [disco_item()]. -spec get_running_nodes(binary(), binary()) -> [disco_item()].
get_running_nodes(Server, _Lang) -> get_running_nodes(Server, _Lang) ->
case catch mnesia:system_info(running_db_nodes) of DBNodes = mnesia:system_info(running_db_nodes),
{'EXIT', _Reason} -> [];
DBNodes ->
lists:map( lists:map(
fun (N) -> fun (N) ->
S = iolist_to_binary(atom_to_list(N)), S = iolist_to_binary(atom_to_list(N)),
#disco_item{jid = jid:make(Server), #disco_item{jid = jid:make(Server),
node = <<"running nodes/", S/binary>>, node = <<"running nodes/", S/binary>>,
name = S} name = S}
end, end, lists:sort(DBNodes)).
lists:sort(DBNodes))
end.
-spec get_stopped_nodes(binary()) -> [disco_item()]. -spec get_stopped_nodes(binary()) -> [disco_item()].
get_stopped_nodes(_Lang) -> get_stopped_nodes(_Lang) ->
case catch lists:usort(mnesia:system_info(db_nodes) ++ DBNodes = lists:usort(mnesia:system_info(db_nodes) ++
mnesia:system_info(extra_db_nodes)) mnesia:system_info(extra_db_nodes))
-- mnesia:system_info(running_db_nodes) -- mnesia:system_info(running_db_nodes),
of
{'EXIT', _Reason} -> [];
DBNodes ->
lists:map( lists:map(
fun (N) -> fun (N) ->
S = iolist_to_binary(atom_to_list(N)), S = iolist_to_binary(atom_to_list(N)),
#disco_item{jid = jid:make(ejabberd_config:get_myname()), #disco_item{jid = jid:make(ejabberd_config:get_myname()),
node = <<"stopped nodes/", S/binary>>, node = <<"stopped nodes/", S/binary>>,
name = S} name = S}
end, end, lists:sort(DBNodes)).
lists:sort(DBNodes))
end.
%%------------------------------------------------------------------------- %%-------------------------------------------------------------------------
@ -823,12 +799,12 @@ adhoc_local_commands(From,
{error, Error} -> {error, Error} {error, Error} -> {error, Error}
end; end;
XData /= undefined, ActionIsExecute -> XData /= undefined, ActionIsExecute ->
case catch set_form(From, LServer, LNode, Lang, XData) of case set_form(From, LServer, LNode, Lang, XData) of
{result, Res} -> {result, Res} ->
xmpp_util:make_adhoc_response( xmpp_util:make_adhoc_response(
Request, Request,
#adhoc_command{xdata = Res, status = completed}); #adhoc_command{xdata = Res, status = completed});
{'EXIT', _} -> {error, xmpp:err_bad_request()}; %%{'EXIT', _} -> {error, xmpp:err_bad_request()};
{error, Error} -> {error, Error} {error, Error} -> {error, Error}
end; end;
true -> true ->
@ -1587,10 +1563,10 @@ search_running_node(SNode, [Node | Nodes]) ->
-spec stop_node(jid(), binary(), binary(), restart | stop, xdata()) -> {result, undefined}. -spec stop_node(jid(), binary(), binary(), restart | stop, xdata()) -> {result, undefined}.
stop_node(From, Host, ENode, Action, XData) -> stop_node(From, Host, ENode, Action, XData) ->
Delay = binary_to_integer(get_value(<<"delay">>, XData)), Delay = binary_to_integer(get_value(<<"delay">>, XData)),
Subject = case get_value(<<"subject">>, XData) of Subject = case get_values(<<"subject">>, XData) of
<<"">> -> [] ->
[]; [];
S -> [S|_] ->
[#xdata_field{var = <<"subject">>, values = [S]}] [#xdata_field{var = <<"subject">>, values = [S]}]
end, end,
Announcement = case get_values(<<"announcement">>, XData) of Announcement = case get_values(<<"announcement">>, XData) of
@ -1698,7 +1674,7 @@ set_sm_form(User, Server, <<"config">>,
{error, xmpp:err_not_acceptable(Txt, Lang)} {error, xmpp:err_not_acceptable(Txt, Lang)}
end; end;
[<<"remove">>] -> [<<"remove">>] ->
catch ejabberd_auth:remove_user(User, Server), ejabberd_auth:remove_user(User, Server),
xmpp_util:make_adhoc_response(Response); xmpp_util:make_adhoc_response(Response);
_ -> _ ->
Txt = ?T("Incorrect value of 'action' in data form"), Txt = ?T("Incorrect value of 'action' in data form"),