1
0
Fork 0
mirror of https://github.com/processone/ejabberd synced 2025-10-03 17:59:31 +02:00

Remove EX_RULE and EX_STACK macros

As we no longer targer R19, we no longer need to carry those.
This commit is contained in:
Pawel Chmielowski 2025-09-22 17:49:33 +02:00
parent 4dea2f1eb6
commit 19b7106124
27 changed files with 252 additions and 264 deletions

View file

@ -1,27 +0,0 @@
%%%----------------------------------------------------------------------
%%%
%%% ejabberd, Copyright (C) 2002-2025 ProcessOne
%%%
%%% This program is free software; you can redistribute it and/or
%%% modify it under the terms of the GNU General Public License as
%%% published by the Free Software Foundation; either version 2 of the
%%% License, or (at your option) any later version.
%%%
%%% This program is distributed in the hope that it will be useful,
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
%%% General Public License for more details.
%%%
%%% You should have received a copy of the GNU General Public License along
%%% with this program; if not, write to the Free Software Foundation, Inc.,
%%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
%%%
%%%----------------------------------------------------------------------
-ifdef(DEPRECATED_GET_STACKTRACE).
-define(EX_RULE(Class, Reason, Stack), Class:Reason:Stack).
-define(EX_STACK(Stack), Stack).
-else.
-define(EX_RULE(Class, Reason, _), Class:Reason).
-define(EX_STACK(_), erlang:get_stacktrace()).
-endif.

View file

@ -85,7 +85,6 @@ defmodule Ejabberd.MixProject do
result = [{:d, :ELIXIR_ENABLED}] ++ result = [{:d, :ELIXIR_ENABLED}] ++
cond_options() ++ cond_options() ++
Enum.map(includes, fn (path) -> {:i, path} end) ++ Enum.map(includes, fn (path) -> {:i, path} end) ++
if_version_above(~c"20", [{:d, :DEPRECATED_GET_STACKTRACE}]) ++
if_version_above(~c"20", [{:d, :HAVE_URI_STRING}]) ++ if_version_above(~c"20", [{:d, :HAVE_URI_STRING}]) ++
if_version_above(~c"20", [{:d, :HAVE_ERL_ERROR}]) ++ if_version_above(~c"20", [{:d, :HAVE_ERL_ERROR}]) ++
if_version_below(~c"21", [{:d, :USE_OLD_HTTP_URI}]) ++ if_version_below(~c"21", [{:d, :USE_OLD_HTTP_URI}]) ++

View file

@ -126,7 +126,6 @@
{erl_opts, [nowarn_deprecated_function, {erl_opts, [nowarn_deprecated_function,
{i, "include"}, {i, "include"},
{if_version_above, "20", {d, 'DEPRECATED_GET_STACKTRACE'}},
{if_version_above, "20", {d, 'HAVE_ERL_ERROR'}}, {if_version_above, "20", {d, 'HAVE_ERL_ERROR'}},
{if_version_above, "20", {d, 'HAVE_URI_STRING'}}, {if_version_above, "20", {d, 'HAVE_URI_STRING'}},
{if_version_below, "21", {d, 'USE_OLD_HTTP_URI'}}, {if_version_below, "21", {d, 'USE_OLD_HTTP_URI'}},

View file

@ -32,7 +32,7 @@
-export([start/2, prep_stop/1, stop/1]). -export([start/2, prep_stop/1, stop/1]).
-include("logger.hrl"). -include("logger.hrl").
-include("ejabberd_stacktrace.hrl").
%%% %%%
%%% Application API %%% Application API

View file

@ -52,7 +52,7 @@
{get_lang, 1}]). {get_lang, 1}]).
-include("logger.hrl"). -include("logger.hrl").
-include("ejabberd_stacktrace.hrl").
-type option() :: atom() | {atom(), global | binary()}. -type option() :: atom() | {atom(), global | binary()}.
-type error_reason() :: {merge_conflict, atom(), binary()} | -type error_reason() :: {merge_conflict, atom(), binary()} |
@ -169,8 +169,8 @@ get_option({O, Host} = Opt) ->
T -> T T -> T
end, end,
try ets:lookup_element(Tab, Opt, 2) try ets:lookup_element(Tab, Opt, 2)
catch ?EX_RULE(error, badarg, St) when Host /= global -> catch
StackTrace = ?EX_STACK(St), error:badarg:StackTrace when Host /= global ->
Val = get_option({O, global}), Val = get_option({O, global}),
?DEBUG("Option '~ts' is not defined for virtual host '~ts'. " ?DEBUG("Option '~ts' is not defined for virtual host '~ts'. "
"This is a bug, please report it with the following " "This is a bug, please report it with the following "
@ -802,8 +802,9 @@ load_file(File) ->
Err -> Err ->
abort(Err) abort(Err)
end end
catch ?EX_RULE(Class, Reason, St) -> catch
{error, {exception, Class, Reason, ?EX_STACK(St)}} Class:Reason:Stack ->
{error, {exception, Class, Reason, Stack}}
end. end.
-spec commit() -> ok. -spec commit() -> ok.

View file

@ -39,7 +39,7 @@
-include("ejabberd_commands.hrl"). -include("ejabberd_commands.hrl").
-include("ejabberd_http.hrl"). -include("ejabberd_http.hrl").
-include("logger.hrl"). -include("logger.hrl").
-include("ejabberd_stacktrace.hrl").
-define(DEFAULT_VERSION, 1000000). -define(DEFAULT_VERSION, 1000000).
@ -331,8 +331,7 @@ try_call_command(Args, Auth, AccessCommands, Version) ->
?STATUS_ERROR}; ?STATUS_ERROR};
throw:Error -> throw:Error ->
{io_lib:format("~p", [Error]), ?STATUS_ERROR}; {io_lib:format("~p", [Error]), ?STATUS_ERROR};
?EX_RULE(A, Why, Stack) -> A:Why:StackTrace ->
StackTrace = ?EX_STACK(Stack),
{io_lib:format("Unhandled exception occurred executing the command:~n** ~ts", {io_lib:format("Unhandled exception occurred executing the command:~n** ~ts",
[misc:format_exception(2, A, Why, StackTrace)]), [misc:format_exception(2, A, Why, StackTrace)]),
?STATUS_ERROR} ?STATUS_ERROR}

View file

@ -60,7 +60,7 @@
). ).
-include("logger.hrl"). -include("logger.hrl").
-include("ejabberd_stacktrace.hrl").
-record(state, {}). -record(state, {}).
-type subscriber() :: {Module :: atom(), Function :: atom(), InitArg :: any()}. -type subscriber() :: {Module :: atom(), Function :: atom(), InitArg :: any()}.
@ -455,15 +455,17 @@ safe_apply(Hook, Module, Function, Args) ->
true -> true ->
apply(Module, Function, Args) apply(Module, Function, Args)
end end
catch ?EX_RULE(E, R, St) when E /= exit; R /= normal -> catch
Stack = ?EX_STACK(St), E:R:Stack when E /= exit; R /= normal ->
?ERROR_MSG("Hook ~p crashed when running ~p:~p/~p:~n" ++ ?ERROR_MSG("Hook ~p crashed when running ~p:~p/~p:~n" ++
string:join( string:join(
["** ~ts"| ["** ~ts" | [ "** Arg " ++ integer_to_list(I) ++ " = ~p"
["** Arg " ++ integer_to_list(I) ++ " = ~p"
|| I <- lists:seq(1, length(Args)) ]], || I <- lists:seq(1, length(Args)) ]],
"~n"), "~n"),
[Hook, Module, Function, length(Args), [Hook,
Module,
Function,
length(Args),
misc:format_exception(2, E, R, Stack) | Args]), misc:format_exception(2, E, R, Stack) | Args]),
'EXIT' 'EXIT'
end. end.
@ -480,15 +482,17 @@ call_subscriber_list([{Mod, Func, InitArg} | SubscriberList], Host, Hook, Callba
try apply(Mod, Func, SubscriberArgs) of try apply(Mod, Func, SubscriberArgs) of
State -> State ->
call_subscriber_list(SubscriberList, Host, Hook, CallbackOrArgs, Event, [{Mod, Func, State} | Result]) call_subscriber_list(SubscriberList, Host, Hook, CallbackOrArgs, Event, [{Mod, Func, State} | Result])
catch ?EX_RULE(E, R, St) when E /= exit; R /= normal -> catch
Stack = ?EX_STACK(St), E:R:Stack when E /= exit; R /= normal ->
?ERROR_MSG("Hook subscriber ~p crashed when running ~p:~p/~p:~n" ++ ?ERROR_MSG("Hook subscriber ~p crashed when running ~p:~p/~p:~n" ++
string:join( string:join(
["** ~ts"| ["** ~ts" | [ "** Arg " ++ integer_to_list(I) ++ " = ~p"
["** Arg " ++ integer_to_list(I) ++ " = ~p"
|| I <- lists:seq(1, length(SubscriberArgs)) ]], || I <- lists:seq(1, length(SubscriberArgs)) ]],
"~n"), "~n"),
[Hook, Mod, Func, length(SubscriberArgs), [Hook,
Mod,
Func,
length(SubscriberArgs),
misc:format_exception(2, E, R, Stack) | SubscriberArgs]), misc:format_exception(2, E, R, Stack) | SubscriberArgs]),
%% Do not append subscriber for next calls: %% Do not append subscriber for next calls:
call_subscriber_list(SubscriberList, Host, Hook, CallbackOrArgs, Event, Result) call_subscriber_list(SubscriberList, Host, Hook, CallbackOrArgs, Event, Result)
@ -709,12 +713,10 @@ run_event_handlers(TracingOpts, Hook, Host, Event, EventArgs, RunType) ->
_ -> _ ->
ok ok
catch catch
?EX_RULE(E, R, St) -> E:R:Stack ->
Stack = ?EX_STACK(St),
?ERROR_MSG( ?ERROR_MSG(
"(~0p|~ts|~0p) Tracing event '~0p' handler exception(~0p): ~0p: ~0p", "(~0p|~ts|~0p) Tracing event '~0p' handler exception(~0p): ~0p: ~0p",
[Hook, Host, erlang:self(), EventHandler, E, R, Stack] [Hook, Host, erlang:self(), EventHandler, E, R, Stack]),
),
ok ok
end end
end, end,
@ -885,8 +887,7 @@ tracing_output(#{output_function := OutputF}, Text, Args) ->
_ -> _ ->
ok ok
catch catch
?EX_RULE(E, R, St) -> E:R:Stack ->
Stack = ?EX_STACK(St),
?ERROR_MSG("Tracing output function exception(~0p): ~0p: ~0p", [E, R, Stack]), ?ERROR_MSG("Tracing output function exception(~0p): ~0p: ~0p", [E, R, Stack]),
ok ok
end; end;

View file

@ -39,7 +39,7 @@
-include("logger.hrl"). -include("logger.hrl").
-include_lib("xmpp/include/xmpp.hrl"). -include_lib("xmpp/include/xmpp.hrl").
-include("ejabberd_http.hrl"). -include("ejabberd_http.hrl").
-include("ejabberd_stacktrace.hrl").
-include_lib("kernel/include/file.hrl"). -include_lib("kernel/include/file.hrl").
-record(state, {sockmod, -record(state, {sockmod,
@ -372,11 +372,11 @@ process(Handlers, Request) ->
try try
HandlerModule:process(LocalPath, Request) HandlerModule:process(LocalPath, Request)
catch catch
?EX_RULE(Class, Reason, Stack) -> Class:Reason:Stack ->
?ERROR_MSG( ?ERROR_MSG(
"HTTP handler crashed: ~s", "HTTP handler crashed: ~s",
[misc:format_exception(2, Class, Reason, ?EX_STACK(Stack))]), [misc:format_exception(2, Class, Reason, Stack)]),
erlang:raise(Class, Reason, ?EX_STACK(Stack)) erlang:raise(Class, Reason, Stack)
end end
end, end,
ejabberd_hooks:run(http_request_debug, [{LocalPath, Request}]), ejabberd_hooks:run(http_request_debug, [{LocalPath, Request}]),

View file

@ -36,7 +36,7 @@
-include_lib("xmpp/include/xmpp.hrl"). -include_lib("xmpp/include/xmpp.hrl").
-include("logger.hrl"). -include("logger.hrl").
-include("ejabberd_stacktrace.hrl").
-record(state, {expire = infinity :: timeout()}). -record(state, {expire = infinity :: timeout()}).
-type state() :: #state{}. -type state() :: #state{}.
@ -174,8 +174,8 @@ calc_checksum(Data) ->
-spec callback(atom() | pid(), #iq{} | timeout, term()) -> any(). -spec callback(atom() | pid(), #iq{} | timeout, term()) -> any().
callback(undefined, IQRes, Fun) -> callback(undefined, IQRes, Fun) ->
try Fun(IQRes) try Fun(IQRes)
catch ?EX_RULE(Class, Reason, St) -> catch
StackTrace = ?EX_STACK(St), Class:Reason:StackTrace ->
?ERROR_MSG("Failed to process iq response:~n~ts~n** ~ts", ?ERROR_MSG("Failed to process iq response:~n~ts~n** ~ts",
[xmpp:pp(IQRes), [xmpp:pp(IQRes),
misc:format_exception(2, Class, Reason, StackTrace)]) misc:format_exception(2, Class, Reason, StackTrace)])

View file

@ -48,7 +48,7 @@
-include("logger.hrl"). -include("logger.hrl").
-include_lib("stdlib/include/ms_transform.hrl"). -include_lib("stdlib/include/ms_transform.hrl").
-include_lib("xmpp/include/xmpp.hrl"). -include_lib("xmpp/include/xmpp.hrl").
-include("ejabberd_stacktrace.hrl").
-include("translate.hrl"). -include("translate.hrl").
-record(state, {}). -record(state, {}).

View file

@ -42,7 +42,7 @@
-define(NEED_RESET, [local_content, type]). -define(NEED_RESET, [local_content, type]).
-include("logger.hrl"). -include("logger.hrl").
-include("ejabberd_stacktrace.hrl").
-record(state, {tables = #{} :: tables(), -record(state, {tables = #{} :: tables(),
schema = [] :: [{atom(), custom_schema()}]}). schema = [] :: [{atom(), custom_schema()}]}).
@ -377,12 +377,13 @@ do_transform(OldAttrs, Attrs, Old) ->
transform_fun(Module, Name) -> transform_fun(Module, Name) ->
fun(Obj) -> fun(Obj) ->
try Module:transform(Obj) try Module:transform(Obj)
catch ?EX_RULE(Class, Reason, St) -> catch
StackTrace = ?EX_STACK(St), Class:Reason:StackTrace ->
?ERROR_MSG("Failed to transform Mnesia table ~ts:~n" ?ERROR_MSG("Failed to transform Mnesia table ~ts:~n"
"** Record: ~p~n" "** Record: ~p~n"
"** ~ts", "** ~ts",
[Name, Obj, [Name,
Obj,
misc:format_exception(2, Class, Reason, StackTrace)]), misc:format_exception(2, Class, Reason, StackTrace)]),
erlang:raise(Class, Reason, StackTrace) erlang:raise(Class, Reason, StackTrace)
end end

View file

@ -48,7 +48,7 @@
-define(CALL_TIMEOUT, 60*1000). %% 60 seconds -define(CALL_TIMEOUT, 60*1000). %% 60 seconds
-include("logger.hrl"). -include("logger.hrl").
-include("ejabberd_stacktrace.hrl").
-record(state, {connection :: pid() | undefined, -record(state, {connection :: pid() | undefined,
num :: pos_integer(), num :: pos_integer(),
@ -114,9 +114,10 @@ multi(F) ->
{error, _} = Err -> Err; {error, _} = Err -> Err;
Result -> get_result(Result) Result -> get_result(Result)
end end
catch ?EX_RULE(E, R, St) -> catch
E:R:St ->
erlang:erase(?TR_STACK), erlang:erase(?TR_STACK),
erlang:raise(E, R, ?EX_STACK(St)) erlang:raise(E, R, St)
end; end;
_ -> _ ->
erlang:error(nested_transaction) erlang:error(nested_transaction)

View file

@ -70,7 +70,8 @@
-include("logger.hrl"). -include("logger.hrl").
-include("ejabberd_router.hrl"). -include("ejabberd_router.hrl").
-include_lib("xmpp/include/xmpp.hrl"). -include_lib("xmpp/include/xmpp.hrl").
-include("ejabberd_stacktrace.hrl").
-callback init() -> any(). -callback init() -> any().
-callback register_route(binary(), binary(), local_hint(), -callback register_route(binary(), binary(), local_hint(),
@ -90,8 +91,8 @@ start_link() ->
-spec route(stanza()) -> ok. -spec route(stanza()) -> ok.
route(Packet) -> route(Packet) ->
try do_route(Packet) try do_route(Packet)
catch ?EX_RULE(Class, Reason, St) -> catch
StackTrace = ?EX_STACK(St), Class:Reason:StackTrace ->
?ERROR_MSG("Failed to route packet:~n~ts~n** ~ts", ?ERROR_MSG("Failed to route packet:~n~ts~n** ~ts",
[xmpp:pp(Packet), [xmpp:pp(Packet),
misc:format_exception(2, Class, Reason, StackTrace)]) misc:format_exception(2, Class, Reason, StackTrace)])

View file

@ -32,7 +32,8 @@
-include("logger.hrl"). -include("logger.hrl").
-include("ejabberd_sql_pt.hrl"). -include("ejabberd_sql_pt.hrl").
-include("ejabberd_router.hrl"). -include("ejabberd_router.hrl").
-include("ejabberd_stacktrace.hrl").
%%%=================================================================== %%%===================================================================
%%% API %%% API
@ -141,13 +142,13 @@ row_to_route(Domain, {ServerHost, NodeS, PidS, LocalHintS} = Row) ->
local_hint = dec_local_hint(LocalHintS)}] local_hint = dec_local_hint(LocalHintS)}]
catch _:{bad_node, _} -> catch _:{bad_node, _} ->
[]; [];
?EX_RULE(Class, Reason, St) -> Class:Reason:StackTrace ->
StackTrace = ?EX_STACK(St),
?ERROR_MSG("Failed to decode row from 'route' table:~n" ?ERROR_MSG("Failed to decode row from 'route' table:~n"
"** Row = ~p~n" "** Row = ~p~n"
"** Domain = ~ts~n" "** Domain = ~ts~n"
"** ~ts", "** ~ts",
[Row, Domain, [Row,
Domain,
misc:format_exception(2, Class, Reason, StackTrace)]), misc:format_exception(2, Class, Reason, StackTrace)]),
[] []
end. end.

View file

@ -53,7 +53,7 @@
-include_lib("xmpp/include/xmpp.hrl"). -include_lib("xmpp/include/xmpp.hrl").
-include("ejabberd_commands.hrl"). -include("ejabberd_commands.hrl").
-include_lib("stdlib/include/ms_transform.hrl"). -include_lib("stdlib/include/ms_transform.hrl").
-include("ejabberd_stacktrace.hrl").
-include("translate.hrl"). -include("translate.hrl").
-define(DEFAULT_MAX_S2S_CONNECTIONS_NUMBER, 1). -define(DEFAULT_MAX_S2S_CONNECTIONS_NUMBER, 1).
@ -249,8 +249,8 @@ handle_info({mnesia_system_event, {mnesia_up, Node}}, State) ->
{noreply, State}; {noreply, State};
handle_info({route, Packet}, State) -> handle_info({route, Packet}, State) ->
try route(Packet) try route(Packet)
catch ?EX_RULE(Class, Reason, St) -> catch
StackTrace = ?EX_STACK(St), Class:Reason:StackTrace ->
?ERROR_MSG("Failed to route packet:~n~ts~n** ~ts", ?ERROR_MSG("Failed to route packet:~n~ts~n** ~ts",
[xmpp:pp(Packet), [xmpp:pp(Packet),
misc:format_exception(2, Class, Reason, StackTrace)]) misc:format_exception(2, Class, Reason, StackTrace)])

View file

@ -92,7 +92,7 @@
-include_lib("xmpp/include/xmpp.hrl"). -include_lib("xmpp/include/xmpp.hrl").
-include("ejabberd_commands.hrl"). -include("ejabberd_commands.hrl").
-include("ejabberd_sm.hrl"). -include("ejabberd_sm.hrl").
-include("ejabberd_stacktrace.hrl").
-include("translate.hrl"). -include("translate.hrl").
-callback init() -> ok | {error, any()}. -callback init() -> ok | {error, any()}.
@ -131,12 +131,13 @@ stop() ->
%% @doc route arbitrary term to c2s process(es) %% @doc route arbitrary term to c2s process(es)
route(To, Term) -> route(To, Term) ->
try do_route(To, Term), ok try do_route(To, Term), ok
catch ?EX_RULE(E, R, St) -> catch
StackTrace = ?EX_STACK(St), E:R:StackTrace ->
?ERROR_MSG("Failed to route term to ~ts:~n" ?ERROR_MSG("Failed to route term to ~ts:~n"
"** Term = ~p~n" "** Term = ~p~n"
"** ~ts", "** ~ts",
[jid:encode(To), Term, [jid:encode(To),
Term,
misc:format_exception(2, E, R, StackTrace)]) misc:format_exception(2, E, R, StackTrace)])
end. end.

View file

@ -89,7 +89,7 @@
-include("logger.hrl"). -include("logger.hrl").
-include("ejabberd_sql_pt.hrl"). -include("ejabberd_sql_pt.hrl").
-include("ejabberd_stacktrace.hrl").
-record(state, -record(state,
{db_ref :: undefined | db_ref_pid() | odbc_connection_reference(), {db_ref :: undefined | db_ref_pid() | odbc_connection_reference(),
@ -616,18 +616,19 @@ outer_transaction(F, NRestarts, _Reason) ->
{atomic, Res} {atomic, Res}
end end
catch catch
?EX_RULE(throw, {aborted, Reason}, _) when NRestarts > 0 -> throw:{aborted, Reason}:_ when NRestarts > 0 ->
maybe_restart_transaction(F, NRestarts, Reason, true); maybe_restart_transaction(F, NRestarts, Reason, true);
?EX_RULE(throw, {aborted, Reason}, Stack) when NRestarts =:= 0 -> throw:{aborted, Reason}:StackTrace when NRestarts =:= 0 ->
StackTrace = ?EX_STACK(Stack),
?ERROR_MSG("SQL transaction restarts exceeded~n** " ?ERROR_MSG("SQL transaction restarts exceeded~n** "
"Restarts: ~p~n** Last abort reason: " "Restarts: ~p~n** Last abort reason: "
"~p~n** Stacktrace: ~p~n** When State " "~p~n** Stacktrace: ~p~n** When State "
"== ~p", "== ~p",
[?MAX_TRANSACTION_RESTARTS, Reason, [?MAX_TRANSACTION_RESTARTS,
StackTrace, get(?STATE_KEY)]), Reason,
StackTrace,
get(?STATE_KEY)]),
maybe_restart_transaction(F, NRestarts, Reason, true); maybe_restart_transaction(F, NRestarts, Reason, true);
?EX_RULE(_, Reason, _) -> _:Reason:_ ->
maybe_restart_transaction(F, 0, Reason, true) maybe_restart_transaction(F, 0, Reason, true)
end end
end. end.
@ -742,8 +743,7 @@ sql_query_internal(#sql_query{} = Query) ->
{error, <<"terminated unexpectedly">>}; {error, <<"terminated unexpectedly">>};
exit:{shutdown, _} -> exit:{shutdown, _} ->
{error, <<"shutdown">>}; {error, <<"shutdown">>};
?EX_RULE(Class, Reason, Stack) -> Class:Reason:StackTrace ->
StackTrace = ?EX_STACK(Stack),
?ERROR_MSG("Internal error while processing SQL query:~n** ~ts", ?ERROR_MSG("Internal error while processing SQL query:~n** ~ts",
[misc:format_exception(2, Class, Reason, StackTrace)]), [misc:format_exception(2, Class, Reason, StackTrace)]),
{error, <<"internal error">>} {error, <<"internal error">>}
@ -935,8 +935,7 @@ sql_query_format_res({selected, _, Rows}, SQLQuery) ->
try try
[(SQLQuery#sql_query.format_res)(Row)] [(SQLQuery#sql_query.format_res)(Row)]
catch catch
?EX_RULE(Class, Reason, Stack) -> Class:Reason:StackTrace ->
StackTrace = ?EX_STACK(Stack),
?ERROR_MSG("Error while processing SQL query result:~n" ?ERROR_MSG("Error while processing SQL query result:~n"
"** Row: ~p~n** ~ts", "** Row: ~p~n** ~ts",
[Row, [Row,

View file

@ -37,7 +37,7 @@
-include("logger.hrl"). -include("logger.hrl").
-include_lib("xmpp/include/xmpp.hrl"). -include_lib("xmpp/include/xmpp.hrl").
-include("translate.hrl"). -include("translate.hrl").
-include("ejabberd_stacktrace.hrl").
-type component() :: ejabberd_sm | ejabberd_local. -type component() :: ejabberd_sm | ejabberd_local.
@ -111,8 +111,8 @@ process_iq(_Host, Module, Function, IQ) ->
ejabberd_router:route(ResIQ); ejabberd_router:route(ResIQ);
ignore -> ignore ->
ok ok
catch ?EX_RULE(Class, Reason, St) -> catch
StackTrace = ?EX_STACK(St), Class:Reason:StackTrace ->
?ERROR_MSG("Failed to process iq:~n~ts~n** ~ts", ?ERROR_MSG("Failed to process iq:~n~ts~n** ~ts",
[xmpp:pp(IQ), [xmpp:pp(IQ),
misc:format_exception(2, Class, Reason, StackTrace)]), misc:format_exception(2, Class, Reason, StackTrace)]),

View file

@ -44,7 +44,7 @@
-include("logger.hrl"). -include("logger.hrl").
-include_lib("stdlib/include/ms_transform.hrl"). -include_lib("stdlib/include/ms_transform.hrl").
-include("ejabberd_stacktrace.hrl").
-include("ejabberd_commands.hrl"). -include("ejabberd_commands.hrl").
-record(ejabberd_module, -record(ejabberd_module,
@ -187,12 +187,16 @@ start_module(Host, Module, Opts, Order) ->
ets:delete(ejabberd_modules, {Module, Host}), ets:delete(ejabberd_modules, {Module, Host}),
erlang:error({bad_return, Module, Err}) erlang:error({bad_return, Module, Err})
end end
catch ?EX_RULE(Class, Reason, Stack) -> catch
StackTrace = ?EX_STACK(Stack), Class:Reason:StackTrace ->
ets:delete(ejabberd_modules, {Module, Host}), ets:delete(ejabberd_modules, {Module, Host}),
ErrorText = format_module_error( ErrorText = format_module_error(
Module, start, 2, Module,
Opts, Class, Reason, start,
2,
Opts,
Class,
Reason,
StackTrace), StackTrace),
?CRITICAL_MSG(ErrorText, []), ?CRITICAL_MSG(ErrorText, []),
maybe_halt_ejabberd(), maybe_halt_ejabberd(),
@ -246,11 +250,15 @@ reload_module(Host, Module, NewOpts, OldOpts, Order) ->
{ok, Pid} when is_pid(Pid) -> {ok, Pid}; {ok, Pid} when is_pid(Pid) -> {ok, Pid};
Err -> erlang:error({bad_return, Module, Err}) Err -> erlang:error({bad_return, Module, Err})
end end
catch ?EX_RULE(Class, Reason, Stack) -> catch
StackTrace = ?EX_STACK(Stack), Class:Reason:StackTrace ->
ErrorText = format_module_error( ErrorText = format_module_error(
Module, reload, 3, Module,
NewOpts, Class, Reason, reload,
3,
NewOpts,
Class,
Reason,
StackTrace), StackTrace),
?CRITICAL_MSG(ErrorText, []), ?CRITICAL_MSG(ErrorText, []),
erlang:raise(Class, Reason, StackTrace) erlang:raise(Class, Reason, StackTrace)
@ -346,12 +354,13 @@ prep_stop_module_keep_config(Host, Module) ->
try Module:prep_stop(Host) of try Module:prep_stop(Host) of
_ -> _ ->
ok ok
catch ?EX_RULE(error, undef, _St) -> catch
error:undef:_St ->
ok; ok;
?EX_RULE(Class, Reason, St) -> Class:Reason:StackTrace ->
StackTrace = ?EX_STACK(St),
?ERROR_MSG("Failed to prepare stop module ~ts at ~ts:~n** ~ts", ?ERROR_MSG("Failed to prepare stop module ~ts at ~ts:~n** ~ts",
[Module, Host, [Module,
Host,
misc:format_exception(2, Class, Reason, StackTrace)]), misc:format_exception(2, Class, Reason, StackTrace)]),
error error
end. end.
@ -371,10 +380,11 @@ stop_module_keep_config(Host, Module) ->
_ -> _ ->
ets:delete(ejabberd_modules, {Module, Host}), ets:delete(ejabberd_modules, {Module, Host}),
ok ok
catch ?EX_RULE(Class, Reason, St) -> catch
StackTrace = ?EX_STACK(St), Class:Reason:StackTrace ->
?ERROR_MSG("Failed to stop module ~ts at ~ts:~n** ~ts", ?ERROR_MSG("Failed to stop module ~ts at ~ts:~n** ~ts",
[Module, Host, [Module,
Host,
misc:format_exception(2, Class, Reason, StackTrace)]), misc:format_exception(2, Class, Reason, StackTrace)]),
error error
end. end.

View file

@ -36,7 +36,7 @@
-include_lib("xmpp/include/xmpp.hrl"). -include_lib("xmpp/include/xmpp.hrl").
-include("logger.hrl"). -include("logger.hrl").
-include("ejabberd_http.hrl"). -include("ejabberd_http.hrl").
-include("ejabberd_stacktrace.hrl").
-include("translate.hrl"). -include("translate.hrl").
-define(DEFAULT_API_VERSION, 1000000). -define(DEFAULT_API_VERSION, 1000000).
@ -148,8 +148,7 @@ process([Call | _], #request{method = 'POST', data = Data, ip = IPPort} = Req) -
_:{error,{_,invalid_json}} = Err -> _:{error,{_,invalid_json}} = Err ->
?DEBUG("Bad Request: ~p", [Err]), ?DEBUG("Bad Request: ~p", [Err]),
badrequest_response(<<"Invalid JSON input">>); badrequest_response(<<"Invalid JSON input">>);
?EX_RULE(_Class, Error, Stack) -> _Class:Error:StackTrace ->
StackTrace = ?EX_STACK(Stack),
?DEBUG("Bad Request: ~p ~p", [Error, StackTrace]), ?DEBUG("Bad Request: ~p ~p", [Error, StackTrace]),
badrequest_response() badrequest_response()
end; end;
@ -166,8 +165,7 @@ process([Call | _], #request{method = 'GET', q = Data, ip = {IP, _}} = Req) ->
%% TODO We need to refactor to remove redundant error return formatting %% TODO We need to refactor to remove redundant error return formatting
throw:{error, unknown_command} -> throw:{error, unknown_command} ->
json_format({404, 44, <<"Command not found.">>}); json_format({404, 44, <<"Command not found.">>});
?EX_RULE(_, Error, Stack) -> _:Error:StackTrace ->
StackTrace = ?EX_STACK(Stack),
?DEBUG("Bad Request: ~p ~p", [Error, StackTrace]), ?DEBUG("Bad Request: ~p ~p", [Error, StackTrace]),
badrequest_response() badrequest_response()
end; end;
@ -257,12 +255,14 @@ handle(Call, Auth, Args, Version) when is_atom(Call), is_list(Args) ->
{400, misc:atom_to_binary(Error)}; {400, misc:atom_to_binary(Error)};
throw:Msg when is_list(Msg); is_binary(Msg) -> throw:Msg when is_list(Msg); is_binary(Msg) ->
{400, iolist_to_binary(Msg)}; {400, iolist_to_binary(Msg)};
?EX_RULE(Class, Error, Stack) -> Class:Error:StackTrace ->
StackTrace = ?EX_STACK(Stack),
?ERROR_MSG("REST API Error: " ?ERROR_MSG("REST API Error: "
"~ts(~p) -> ~p:~p ~p", "~ts(~p) -> ~p:~p ~p",
[Call, hide_sensitive_args(Args), [Call,
Class, Error, StackTrace]), hide_sensitive_args(Args),
Class,
Error,
StackTrace]),
{500, <<"internal_error">>} {500, <<"internal_error">>}
end. end.

View file

@ -44,7 +44,8 @@
-include_lib("xmpp/include/xmpp.hrl"). -include_lib("xmpp/include/xmpp.hrl").
-include("logger.hrl"). -include("logger.hrl").
-include("translate.hrl"). -include("translate.hrl").
-include("ejabberd_stacktrace.hrl").
-callback init(binary(), gen_mod:opts()) -> ok | {error, db_failure}. -callback init(binary(), gen_mod:opts()) -> ok | {error, db_failure}.
-callback set_channel(binary(), binary(), binary(), -callback set_channel(binary(), binary(), binary(),
@ -319,8 +320,8 @@ handle_cast(Request, State) ->
handle_info({route, Packet}, State) -> handle_info({route, Packet}, State) ->
try route(Packet) try route(Packet)
catch ?EX_RULE(Class, Reason, St) -> catch
StackTrace = ?EX_STACK(St), Class:Reason:StackTrace ->
?ERROR_MSG("Failed to route packet:~n~ts~n** ~ts", ?ERROR_MSG("Failed to route packet:~n~ts~n** ~ts",
[xmpp:pp(Packet), [xmpp:pp(Packet),
misc:format_exception(2, Class, Reason, StackTrace)]) misc:format_exception(2, Class, Reason, StackTrace)])

View file

@ -85,7 +85,7 @@
-include("mod_muc.hrl"). -include("mod_muc.hrl").
-include("mod_muc_room.hrl"). -include("mod_muc_room.hrl").
-include("translate.hrl"). -include("translate.hrl").
-include("ejabberd_stacktrace.hrl").
-type state() :: #{hosts := [binary()], -type state() :: #{hosts := [binary()],
server_host := binary(), server_host := binary(),
@ -454,8 +454,8 @@ handle_call({create, Room, Host, From, Nick, Opts}, _From,
-spec handle_cast(term(), state()) -> {noreply, state()}. -spec handle_cast(term(), state()) -> {noreply, state()}.
handle_cast({route_to_room, Packet}, #{server_host := ServerHost} = State) -> handle_cast({route_to_room, Packet}, #{server_host := ServerHost} = State) ->
try route_to_room(Packet, ServerHost) try route_to_room(Packet, ServerHost)
catch ?EX_RULE(Class, Reason, St) -> catch
StackTrace = ?EX_STACK(St), Class:Reason:StackTrace ->
?ERROR_MSG("Failed to route packet:~n~ts~n** ~ts", ?ERROR_MSG("Failed to route packet:~n~ts~n** ~ts",
[xmpp:pp(Packet), [xmpp:pp(Packet),
misc:format_exception(2, Class, Reason, StackTrace)]) misc:format_exception(2, Class, Reason, StackTrace)])
@ -483,8 +483,8 @@ handle_info({route, Packet}, #{server_host := ServerHost} = State) ->
%% where mod_muc is not loaded. Such configuration %% where mod_muc is not loaded. Such configuration
%% is *highly* discouraged %% is *highly* discouraged
try route(Packet, ServerHost) try route(Packet, ServerHost)
catch ?EX_RULE(Class, Reason, St) -> catch
StackTrace = ?EX_STACK(St), Class:Reason:StackTrace ->
?ERROR_MSG("Failed to route packet:~n~ts~n** ~ts", ?ERROR_MSG("Failed to route packet:~n~ts~n** ~ts",
[xmpp:pp(Packet), [xmpp:pp(Packet),
misc:format_exception(2, Class, Reason, StackTrace)]) misc:format_exception(2, Class, Reason, StackTrace)])

View file

@ -74,7 +74,7 @@
-include_lib("xmpp/include/xmpp.hrl"). -include_lib("xmpp/include/xmpp.hrl").
-include("translate.hrl"). -include("translate.hrl").
-include("mod_muc_room.hrl"). -include("mod_muc_room.hrl").
-include("ejabberd_stacktrace.hrl").
-define(MAX_USERS_DEFAULT_LIST, -define(MAX_USERS_DEFAULT_LIST,
[5, 10, 20, 30, 50, 100, 200, 500, 1000, 2000, 5000]). [5, 10, 20, 30, 50, 100, 200, 500, 1000, 2000, 5000]).
@ -1027,8 +1027,8 @@ terminate(Reason, _StateName,
ok ok
end end
end end
catch ?EX_RULE(E, R, St) -> catch
StackTrace = ?EX_STACK(St), E:R:StackTrace ->
?ERROR_MSG("Got exception on room termination:~n** ~ts", ?ERROR_MSG("Got exception on room termination:~n** ~ts",
[misc:format_exception(2, E, R, StackTrace)]) [misc:format_exception(2, E, R, StackTrace)])
end. end.
@ -3266,8 +3266,8 @@ process_item_change(Item, SD, UJID) ->
maybe_send_affiliation(JID, A, SD1), maybe_send_affiliation(JID, A, SD1),
SD1 SD1
end end
catch ?EX_RULE(E, R, St) -> catch
StackTrace = ?EX_STACK(St), E:R:StackTrace ->
FromSuffix = case UJID of FromSuffix = case UJID of
#jid{} -> #jid{} ->
JidString = jid:encode(UJID), JidString = jid:encode(UJID),
@ -3276,7 +3276,8 @@ process_item_change(Item, SD, UJID) ->
<<"">> <<"">>
end, end,
?ERROR_MSG("Failed to set item ~p~ts:~n** ~ts", ?ERROR_MSG("Failed to set item ~p~ts:~n** ~ts",
[Item, FromSuffix, [Item,
FromSuffix,
misc:format_exception(2, E, R, StackTrace)]), misc:format_exception(2, E, R, StackTrace)]),
{error, xmpp:err_internal_server_error()} {error, xmpp:err_internal_server_error()}
end. end.

View file

@ -40,7 +40,7 @@
-include("logger.hrl"). -include("logger.hrl").
-include_lib("xmpp/include/xmpp.hrl"). -include_lib("xmpp/include/xmpp.hrl").
-include("translate.hrl"). -include("translate.hrl").
-include("ejabberd_stacktrace.hrl").
-define(PROCNAME, ejabberd_mod_proxy65_service). -define(PROCNAME, ejabberd_mod_proxy65_service).
@ -86,8 +86,8 @@ terminate(_Reason, #state{myhosts = MyHosts}) ->
handle_info({route, Packet}, State) -> handle_info({route, Packet}, State) ->
try route(Packet) try route(Packet)
catch ?EX_RULE(Class, Reason, St) -> catch
StackTrace = ?EX_STACK(St), Class:Reason:StackTrace ->
?ERROR_MSG("Failed to route packet:~n~ts~n** ~ts", ?ERROR_MSG("Failed to route packet:~n~ts~n** ~ts",
[xmpp:pp(Packet), [xmpp:pp(Packet),
misc:format_exception(2, Class, Reason, StackTrace)]) misc:format_exception(2, Class, Reason, StackTrace)])

View file

@ -46,7 +46,7 @@
-include("pubsub.hrl"). -include("pubsub.hrl").
-include("mod_roster.hrl"). -include("mod_roster.hrl").
-include("translate.hrl"). -include("translate.hrl").
-include("ejabberd_stacktrace.hrl").
-include("ejabberd_commands.hrl"). -include("ejabberd_commands.hrl").
-define(STDTREE, <<"tree">>). -define(STDTREE, <<"tree">>).
@ -748,8 +748,8 @@ handle_cast(Msg, State) ->
handle_info({route, Packet}, State) -> handle_info({route, Packet}, State) ->
try route(Packet) try route(Packet)
catch ?EX_RULE(Class, Reason, St) -> catch
StackTrace = ?EX_STACK(St), Class:Reason:StackTrace ->
?ERROR_MSG("Failed to route packet:~n~ts~n** ~ts", ?ERROR_MSG("Failed to route packet:~n~ts~n** ~ts",
[xmpp:pp(Packet), [xmpp:pp(Packet),
misc:format_exception(2, Class, Reason, StackTrace)]) misc:format_exception(2, Class, Reason, StackTrace)])
@ -3819,8 +3819,8 @@ tree_action(Host, Function, Args) ->
DBType = mod_pubsub_opt:db_type(ServerHost), DBType = mod_pubsub_opt:db_type(ServerHost),
Fun = fun () -> Fun = fun () ->
try tree_call(Host, Function, Args) try tree_call(Host, Function, Args)
catch ?EX_RULE(Class, Reason, St) when DBType == sql -> catch
StackTrace = ?EX_STACK(St), Class:Reason:StackTrace when DBType == sql ->
ejabberd_sql:abort({exception, Class, Reason, StackTrace}) ejabberd_sql:abort({exception, Class, Reason, StackTrace})
end end
end, end,
@ -3919,10 +3919,10 @@ transaction(Host, Fun, Trans) ->
do_transaction(ServerHost, Fun, Trans, DBType) -> do_transaction(ServerHost, Fun, Trans, DBType) ->
F = fun() -> F = fun() ->
try Fun() try Fun()
catch ?EX_RULE(Class, Reason, St) when (DBType == mnesia andalso catch
Class:Reason:StackTrace when (DBType == mnesia andalso
Trans == transaction) orelse Trans == transaction) orelse
DBType == sql -> DBType == sql ->
StackTrace = ?EX_STACK(St),
Ex = {exception, Class, Reason, StackTrace}, Ex = {exception, Class, Reason, StackTrace},
case DBType of case DBType of
mnesia -> mnesia:abort(Ex); mnesia -> mnesia:abort(Ex);

View file

@ -61,7 +61,7 @@
-include("mod_roster.hrl"). -include("mod_roster.hrl").
-include("ejabberd_http.hrl"). -include("ejabberd_http.hrl").
-include("ejabberd_web_admin.hrl"). -include("ejabberd_web_admin.hrl").
-include("ejabberd_stacktrace.hrl").
-include("translate.hrl"). -include("translate.hrl").
-define(ROSTER_CACHE, roster_cache). -define(ROSTER_CACHE, roster_cache).

View file

@ -51,7 +51,7 @@
-include_lib("xmpp/include/xmpp.hrl"). -include_lib("xmpp/include/xmpp.hrl").
-include("mod_vcard.hrl"). -include("mod_vcard.hrl").
-include("translate.hrl"). -include("translate.hrl").
-include("ejabberd_stacktrace.hrl").
-include("ejabberd_http.hrl"). -include("ejabberd_http.hrl").
-include("ejabberd_web_admin.hrl"). -include("ejabberd_web_admin.hrl").
@ -151,8 +151,8 @@ handle_cast(Cast, State) ->
handle_info({route, Packet}, State) -> handle_info({route, Packet}, State) ->
try route(Packet) try route(Packet)
catch ?EX_RULE(Class, Reason, St) -> catch
StackTrace = ?EX_STACK(St), Class:Reason:StackTrace ->
?ERROR_MSG("Failed to route packet:~n~ts~n** ~ts", ?ERROR_MSG("Failed to route packet:~n~ts~n** ~ts",
[xmpp:pp(Packet), [xmpp:pp(Packet),
misc:format_exception(2, Class, Reason, StackTrace)]) misc:format_exception(2, Class, Reason, StackTrace)])