mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-24 16:23:40 +01:00
Use correct stacktrace in logging macros
By calling erlang:get_stacktrace() inside a lager function we obtain actually a stacktrace of the lager function, not the one we got during exception. This is not a problem for newest Erlang versions though.
This commit is contained in:
parent
6697a3e3f1
commit
b479fe5315
@ -151,7 +151,8 @@ get_certificates(Domains) ->
|
||||
throw:Throw ->
|
||||
Throw;
|
||||
?EX_RULE(E, R, St) ->
|
||||
?ERROR_MSG("Unknown ~p:~p, ~p", [E, R, ?EX_STACK(St)]),
|
||||
StackTrace = ?EX_STACK(St),
|
||||
?ERROR_MSG("Unknown ~p:~p, ~p", [E, R, StackTrace]),
|
||||
{error, get_certificates}
|
||||
end;
|
||||
false ->
|
||||
@ -243,7 +244,8 @@ get_certificate(CAUrl, DomainName, PrivateKey) ->
|
||||
throw:Throw ->
|
||||
Throw;
|
||||
?EX_RULE(E, R, St) ->
|
||||
?ERROR_MSG("Unknown ~p:~p, ~p", [E, R, ?EX_STACK(St)]),
|
||||
StackTrace = ?EX_STACK(St),
|
||||
?ERROR_MSG("Unknown ~p:~p, ~p", [E, R, StackTrace]),
|
||||
{error, DomainName, get_certificate}
|
||||
end.
|
||||
|
||||
@ -382,7 +384,8 @@ renew_certificates() ->
|
||||
throw:Throw ->
|
||||
Throw;
|
||||
?EX_RULE(E, R, St) ->
|
||||
?ERROR_MSG("Unknown ~p:~p, ~p", [E, R, ?EX_STACK(St)]),
|
||||
StackTrace = ?EX_STACK(St),
|
||||
?ERROR_MSG("Unknown ~p:~p, ~p", [E, R, StackTrace]),
|
||||
{error, get_certificates}
|
||||
end.
|
||||
|
||||
@ -447,7 +450,8 @@ list_certificates(Verbose) ->
|
||||
throw:Throw ->
|
||||
Throw;
|
||||
?EX_RULE(E, R, St) ->
|
||||
?ERROR_MSG("Unknown ~p:~p, ~p", [E, R, ?EX_STACK(St)]),
|
||||
StackTrace = ?EX_STACK(St),
|
||||
?ERROR_MSG("Unknown ~p:~p, ~p", [E, R, StackTrace]),
|
||||
{error, list_certificates}
|
||||
end;
|
||||
false ->
|
||||
@ -489,7 +493,8 @@ format_certificate(DataCert, Verbose) ->
|
||||
end
|
||||
catch
|
||||
?EX_RULE(E, R, St) ->
|
||||
?ERROR_MSG("Unknown ~p:~p, ~p", [E, R, ?EX_STACK(St)]),
|
||||
StackTrace = ?EX_STACK(St),
|
||||
?ERROR_MSG("Unknown ~p:~p, ~p", [E, R, StackTrace]),
|
||||
fail_format_certificate(DomainName)
|
||||
end.
|
||||
|
||||
@ -614,7 +619,8 @@ revoke_certificates(DomainOrFile) ->
|
||||
throw:Throw ->
|
||||
Throw;
|
||||
?EX_RULE(E, R, St) ->
|
||||
?ERROR_MSG("Unknown ~p:~p, ~p", [E, R, ?EX_STACK(St)]),
|
||||
StackTrace = ?EX_STACK(St),
|
||||
?ERROR_MSG("Unknown ~p:~p, ~p", [E, R, StackTrace]),
|
||||
{error, revoke_certificate}
|
||||
end.
|
||||
|
||||
@ -1085,7 +1091,8 @@ save_certificate({ok, DomainName, Cert}) ->
|
||||
throw:Throw ->
|
||||
Throw;
|
||||
?EX_RULE(E, R, St) ->
|
||||
?ERROR_MSG("Unknown ~p:~p, ~p", [E, R, ?EX_STACK(St)]),
|
||||
StackTrace = ?EX_STACK(St),
|
||||
?ERROR_MSG("Unknown ~p:~p, ~p", [E, R, StackTrace]),
|
||||
{error, DomainName, saving}
|
||||
end.
|
||||
|
||||
|
@ -73,8 +73,9 @@ start_link() ->
|
||||
route(Packet) ->
|
||||
try do_route(Packet)
|
||||
catch ?EX_RULE(E, R, St) ->
|
||||
StackTrace = ?EX_STACK(St),
|
||||
?ERROR_MSG("Failed to route packet:~n~s~nReason = ~p",
|
||||
[xmpp:pp(Packet), {E, {R, ?EX_STACK(St)}}])
|
||||
[xmpp:pp(Packet), {E, {R, StackTrace}}])
|
||||
end.
|
||||
|
||||
-spec route_iq(iq(), function()) -> ok.
|
||||
|
@ -90,8 +90,9 @@ start_link() ->
|
||||
route(Packet) ->
|
||||
try do_route(Packet)
|
||||
catch ?EX_RULE(E, R, St) ->
|
||||
StackTrace = ?EX_STACK(St),
|
||||
?ERROR_MSG("Failed to route packet:~n~s~nReason = ~p",
|
||||
[xmpp:pp(Packet), {E, {R, ?EX_STACK(St)}}])
|
||||
[xmpp:pp(Packet), {E, {R, StackTrace}}])
|
||||
end.
|
||||
|
||||
-spec route(jid(), jid(), xmlel() | stanza()) -> ok.
|
||||
|
@ -122,10 +122,11 @@ row_to_route(Domain, {ServerHost, NodeS, PidS, LocalHintS} = Row) ->
|
||||
catch _:{bad_node, _} ->
|
||||
[];
|
||||
?EX_RULE(E, R, St) ->
|
||||
StackTrace = ?EX_STACK(St),
|
||||
?ERROR_MSG("Failed to decode row from 'route' table:~n"
|
||||
"Row = ~p~n"
|
||||
"Domain = ~s~n"
|
||||
"Reason = ~p",
|
||||
[Row, Domain, {E, {R, ?EX_STACK(St)}}]),
|
||||
[Row, Domain, {E, {R, StackTrace}}]),
|
||||
[]
|
||||
end.
|
||||
|
@ -91,8 +91,9 @@ start_link() ->
|
||||
route(Packet) ->
|
||||
try do_route(Packet)
|
||||
catch ?EX_RULE(E, R, St) ->
|
||||
StackTrace = ?EX_STACK(St),
|
||||
?ERROR_MSG("Failed to route packet:~n~s~nReason = ~p",
|
||||
[xmpp:pp(Packet), {E, {R, ?EX_STACK(St)}}])
|
||||
[xmpp:pp(Packet), {E, {R, StackTrace}}])
|
||||
end.
|
||||
|
||||
clean_temporarily_blocked_table() ->
|
||||
|
@ -141,9 +141,10 @@ route(Packet) ->
|
||||
Packet1 ->
|
||||
try do_route(Packet1), ok
|
||||
catch ?EX_RULE(E, R, St) ->
|
||||
StackTrace = ?EX_STACK(St),
|
||||
?ERROR_MSG("Failed to route packet:~n~s~nReason = ~p",
|
||||
[xmpp:pp(Packet1),
|
||||
{E, {R, ?EX_STACK(St)}}])
|
||||
{E, {R, StackTrace}}])
|
||||
end
|
||||
end.
|
||||
|
||||
|
@ -535,12 +535,13 @@ outer_transaction(F, NRestarts, _Reason) ->
|
||||
put(?NESTING_KEY, ?TOP_LEVEL_TXN),
|
||||
outer_transaction(F, NRestarts - 1, Reason);
|
||||
?EX_RULE(throw, {aborted, Reason}, Stack) when NRestarts =:= 0 ->
|
||||
StackTrace = ?EX_STACK(Stack),
|
||||
?ERROR_MSG("SQL transaction restarts exceeded~n** "
|
||||
"Restarts: ~p~n** Last abort reason: "
|
||||
"~p~n** Stacktrace: ~p~n** When State "
|
||||
"== ~p",
|
||||
[?MAX_TRANSACTION_RESTARTS, Reason,
|
||||
?EX_STACK(Stack), get(?STATE_KEY)]),
|
||||
StackTrace, get(?STATE_KEY)]),
|
||||
sql_query_internal([<<"rollback;">>]),
|
||||
{aborted, Reason};
|
||||
?EX_RULE(exit, Reason, _) ->
|
||||
@ -612,8 +613,9 @@ sql_query_internal(#sql_query{} = Query) ->
|
||||
exit:{normal, _} ->
|
||||
{error, <<"terminated unexpectedly">>};
|
||||
?EX_RULE(Class, Reason, Stack) ->
|
||||
StackTrace = ?EX_STACK(Stack),
|
||||
?ERROR_MSG("Internal error while processing SQL query: ~p",
|
||||
[{Class, Reason, ?EX_STACK(Stack)}]),
|
||||
[{Class, Reason, StackTrace}]),
|
||||
{error, <<"internal error">>}
|
||||
end,
|
||||
check_error(Res, Query);
|
||||
@ -753,10 +755,11 @@ sql_query_format_res({selected, _, Rows}, SQLQuery) ->
|
||||
[(SQLQuery#sql_query.format_res)(Row)]
|
||||
catch
|
||||
?EX_RULE(Class, Reason, Stack) ->
|
||||
StackTrace = ?EX_STACK(Stack),
|
||||
?ERROR_MSG("Error while processing "
|
||||
"SQL query result: ~p~n"
|
||||
"row: ~p",
|
||||
[{Class, Reason, ?EX_STACK(Stack)}, Row]),
|
||||
[{Class, Reason, StackTrace}, Row]),
|
||||
[]
|
||||
end
|
||||
end, Rows),
|
||||
|
@ -112,8 +112,9 @@ process_iq(_Host, Module, Function, IQ) ->
|
||||
ignore ->
|
||||
ok
|
||||
catch ?EX_RULE(E, R, St) ->
|
||||
StackTrace = ?EX_STACK(St),
|
||||
?ERROR_MSG("Failed to process iq:~n~s~nReason = ~p",
|
||||
[xmpp:pp(IQ), {E, {R, ?EX_STACK(St)}}]),
|
||||
[xmpp:pp(IQ), {E, {R, StackTrace}}]),
|
||||
Txt = ?T("Module failed to handle the query"),
|
||||
Err = xmpp:err_internal_server_error(Txt, IQ#iq.lang),
|
||||
ejabberd_router:route_error(IQ, Err)
|
||||
|
@ -192,7 +192,8 @@ process([Call], #request{method = 'POST', data = Data, ip = IPPort} = Req) ->
|
||||
?DEBUG("Bad Request: ~p", [_Err]),
|
||||
badrequest_response(<<"Invalid JSON input">>);
|
||||
?EX_RULE(_Class, _Error, Stack) ->
|
||||
?DEBUG("Bad Request: ~p ~p", [_Error, ?EX_STACK(Stack)]),
|
||||
StackTrace = ?EX_STACK(Stack),
|
||||
?DEBUG("Bad Request: ~p ~p", [_Error, StackTrace]),
|
||||
badrequest_response()
|
||||
end;
|
||||
process([Call], #request{method = 'GET', q = Data, ip = {IP, _}} = Req) ->
|
||||
@ -209,7 +210,8 @@ process([Call], #request{method = 'GET', q = Data, ip = {IP, _}} = Req) ->
|
||||
throw:{error, unknown_command} ->
|
||||
json_format({404, 44, <<"Command not found.">>});
|
||||
?EX_RULE(_, _Error, Stack) ->
|
||||
?DEBUG("Bad Request: ~p ~p", [_Error, ?EX_STACK(Stack)]),
|
||||
StackTrace = ?EX_STACK(Stack),
|
||||
?DEBUG("Bad Request: ~p ~p", [_Error, StackTrace]),
|
||||
badrequest_response()
|
||||
end;
|
||||
process([_Call], #request{method = 'OPTIONS', data = <<>>}) ->
|
||||
@ -296,10 +298,11 @@ handle(Call, Auth, Args, Version) when is_atom(Call), is_list(Args) ->
|
||||
throw:Msg when is_list(Msg); is_binary(Msg) ->
|
||||
{400, iolist_to_binary(Msg)};
|
||||
?EX_RULE(Class, Error, Stack) ->
|
||||
StackTrace = ?EX_STACK(Stack),
|
||||
?ERROR_MSG("REST API Error: "
|
||||
"~s(~p) -> ~p:~p ~p",
|
||||
[Call, hide_sensitive_args(Args),
|
||||
Class, Error, ?EX_STACK(Stack)]),
|
||||
Class, Error, StackTrace]),
|
||||
{500, <<"internal_error">>}
|
||||
end.
|
||||
|
||||
|
@ -746,8 +746,9 @@ terminate(Reason, _StateName,
|
||||
end,
|
||||
mod_muc:room_destroyed(Host, Room, self(), LServer)
|
||||
catch ?EX_RULE(E, R, St) ->
|
||||
mod_muc:room_destroyed(Host, Room, self(), LServer),
|
||||
?ERROR_MSG("Got exception on room termination: ~p", [{E, {R, ?EX_STACK(St)}}])
|
||||
StackTrace = ?EX_STACK(St),
|
||||
mod_muc:room_destroyed(Host, Room, self(), LServer),
|
||||
?ERROR_MSG("Got exception on room termination: ~p", [{E, {R, StackTrace}}])
|
||||
end,
|
||||
ok.
|
||||
|
||||
@ -2782,15 +2783,16 @@ process_item_change(Item, SD, UJID) ->
|
||||
SD1
|
||||
end
|
||||
catch ?EX_RULE(E, R, St) ->
|
||||
FromSuffix = case UJID of
|
||||
#jid{} ->
|
||||
JidString = jid:encode(UJID),
|
||||
<<" from ", JidString/binary>>;
|
||||
undefined ->
|
||||
<<"">>
|
||||
end,
|
||||
?ERROR_MSG("Failed to set item ~p~s: ~p",
|
||||
[Item, FromSuffix, {E, {R, ?EX_STACK(St)}}]),
|
||||
StackTrace = ?EX_STACK(St),
|
||||
FromSuffix = case UJID of
|
||||
#jid{} ->
|
||||
JidString = jid:encode(UJID),
|
||||
<<" from ", JidString/binary>>;
|
||||
undefined ->
|
||||
<<"">>
|
||||
end,
|
||||
?ERROR_MSG("Failed to set item ~p~s: ~p",
|
||||
[Item, FromSuffix, {E, {R, StackTrace}}]),
|
||||
{error, xmpp:err_internal_server_error()}
|
||||
end.
|
||||
|
||||
|
@ -321,8 +321,9 @@ process_iq_get(#iq{to = To, lang = Lang,
|
||||
ver = Version}
|
||||
end)
|
||||
catch ?EX_RULE(E, R, St) ->
|
||||
StackTrace = ?EX_STACK(St),
|
||||
?ERROR_MSG("Failed to process roster get for ~s: ~p",
|
||||
[jid:encode(To), {E, {R, ?EX_STACK(St)}}]),
|
||||
[jid:encode(To), {E, {R, StackTrace}}]),
|
||||
Txt = ?T("Roster module has failed"),
|
||||
xmpp:make_error(IQ, xmpp:err_internal_server_error(Txt, Lang))
|
||||
end.
|
||||
|
Loading…
Reference in New Issue
Block a user