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
1 changed files with 81 additions and 105 deletions

View File

@ -648,121 +648,97 @@ 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} -> []; SURs = lists:sort([{S, U, R} || {U, S, R} <- USRs]),
USRs -> lists:map(
SURs = lists:sort([{S, U, R} || {U, S, R} <- USRs]), fun({S, U, R}) ->
lists:map( #disco_item{jid = jid:make(U, S, R),
fun({S, U, R}) -> name = <<U/binary, "@", S/binary>>}
#disco_item{jid = jid:make(U, S, R), end, SURs).
name = <<U/binary, "@", S/binary>>}
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 SUsers = lists:sort([{S, U} || {U, S} <- Users]),
{'EXIT', _Reason} -> []; case length(SUsers) of
Users -> N when N =< 100 ->
SUsers = lists:sort([{S, U} || {U, S} <- Users]), lists:map(fun({S, U}) ->
case length(SUsers) of #disco_item{jid = jid:make(U, S),
N when N =< 100 -> name = <<U/binary, $@, S/binary>>}
lists:map(fun({S, U}) -> end, SUsers);
#disco_item{jid = jid:make(U, S), N ->
name = <<U/binary, $@, S/binary>>} NParts = trunc(math:sqrt(N * 6.17999999999999993783e-1)) + 1,
end, SUsers); M = trunc(N / NParts) + 1,
N -> lists:map(
NParts = trunc(math:sqrt(N * 6.17999999999999993783e-1)) fun (K) ->
+ 1, L = K + M - 1,
M = trunc(N / NParts) + 1, Node = <<"@",
lists:map(fun (K) -> (integer_to_binary(K))/binary,
L = K + M - 1, "-",
Node = <<"@", (integer_to_binary(L))/binary>>,
(integer_to_binary(K))/binary, {FS, FU} = lists:nth(K, SUsers),
"-", {LS, LU} = if L < N -> lists:nth(L, SUsers);
(integer_to_binary(L))/binary>>, true -> lists:last(SUsers)
{FS, FU} = lists:nth(K, SUsers), end,
{LS, LU} = if L < N -> lists:nth(L, SUsers); Name = <<FU/binary, "@", FS/binary, " -- ",
true -> lists:last(SUsers) LU/binary, "@", LS/binary>>,
end, #disco_item{jid = jid:make(Host),
Name = <<FU/binary, "@", FS/binary, " -- ", node = <<"all users/", Node/binary>>,
LU/binary, "@", LS/binary>>, name = Name}
#disco_item{jid = jid:make(Host), end, lists:seq(1, N, M))
node = <<"all users/", Node/binary>>,
name = Name}
end,
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} -> []; DotHost = <<".", Host/binary>>,
Connections -> TConns = [TH || {FH, TH} <- Connections,
DotHost = <<".", Host/binary>>, Host == FH orelse str:suffix(DotHost, FH)],
TConns = [TH lists:map(
|| {FH, TH} <- Connections, fun (T) ->
Host == FH orelse str:suffix(DotHost, FH)], Name = str:format(tr(Lang, ?T("To ~s")),[T]),
lists:map( #disco_item{jid = jid:make(Host),
fun (T) -> node = <<"outgoing s2s/", T/binary>>,
Name = str:format(tr(Lang, ?T("To ~s")),[T]), name = Name}
#disco_item{jid = jid:make(Host), end, lists:usort(TConns)).
node = <<"outgoing s2s/", T/binary>>,
name = Name}
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} -> []; lists:map(
Connections -> fun ({F, _T}) ->
lists:map( Node = <<"outgoing s2s/", To/binary, "/", F/binary>>,
fun ({F, _T}) -> Name = str:format(tr(Lang, ?T("From ~s")), [F]),
Node = <<"outgoing s2s/", To/binary, "/", F/binary>>, #disco_item{jid = jid:make(Host), node = Node, name = Name}
Name = str:format(tr(Lang, ?T("From ~s")), [F]), end,
#disco_item{jid = jid:make(Host), node = Node, name = Name} lists:keysort(
end, 1,
lists:keysort(1, lists:filter(fun (E) -> element(2, E) == To end,
lists:filter(fun (E) -> element(2, E) == To Connections))).
end,
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} -> []; lists:map(
DBNodes -> fun (N) ->
lists:map( S = iolist_to_binary(atom_to_list(N)),
fun (N) -> #disco_item{jid = jid:make(Server),
S = iolist_to_binary(atom_to_list(N)), node = <<"running nodes/", S/binary>>,
#disco_item{jid = jid:make(Server), name = S}
node = <<"running nodes/", S/binary>>, end, lists:sort(DBNodes)).
name = S}
end,
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 lists:map(
{'EXIT', _Reason} -> []; fun (N) ->
DBNodes -> S = iolist_to_binary(atom_to_list(N)),
lists:map( #disco_item{jid = jid:make(ejabberd_config:get_myname()),
fun (N) -> node = <<"stopped nodes/", S/binary>>,
S = iolist_to_binary(atom_to_list(N)), name = S}
#disco_item{jid = jid:make(ejabberd_config:get_myname()), end, lists:sort(DBNodes)).
node = <<"stopped nodes/", S/binary>>,
name = S}
end,
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"),