mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-22 17:28:25 +01:00
Get stacktrace out of lager context
Calling erlang:get_stacktrace() inside lager functions produces stacktraces of the logging function itself, not the function which has failed.
This commit is contained in:
parent
b416527e4f
commit
88d0b71d58
@ -151,7 +151,8 @@ get_certificates(Domains) ->
|
||||
throw:Throw ->
|
||||
Throw;
|
||||
E:R ->
|
||||
?ERROR_MSG("Unknown ~p:~p, ~p", [E, R, erlang:get_stacktrace()]),
|
||||
St = erlang:get_stacktrace(),
|
||||
?ERROR_MSG("Unknown ~p:~p, ~p", [E, R, St]),
|
||||
{error, get_certificates}
|
||||
end;
|
||||
false ->
|
||||
@ -243,7 +244,8 @@ get_certificate(CAUrl, DomainName, PrivateKey) ->
|
||||
throw:Throw ->
|
||||
Throw;
|
||||
E:R ->
|
||||
?ERROR_MSG("Unknown ~p:~p, ~p", [E, R, erlang:get_stacktrace()]),
|
||||
St = erlang:get_stacktrace(),
|
||||
?ERROR_MSG("Unknown ~p:~p, ~p", [E, R, St]),
|
||||
{error, DomainName, get_certificate}
|
||||
end.
|
||||
|
||||
@ -382,7 +384,8 @@ renew_certificates() ->
|
||||
throw:Throw ->
|
||||
Throw;
|
||||
E:R ->
|
||||
?ERROR_MSG("Unknown ~p:~p, ~p", [E, R, erlang:get_stacktrace()]),
|
||||
St = erlang:get_stacktrace(),
|
||||
?ERROR_MSG("Unknown ~p:~p, ~p", [E, R, St]),
|
||||
{error, get_certificates}
|
||||
end.
|
||||
|
||||
@ -447,7 +450,8 @@ list_certificates(Verbose) ->
|
||||
throw:Throw ->
|
||||
Throw;
|
||||
E:R ->
|
||||
?ERROR_MSG("Unknown ~p:~p, ~p", [E, R, erlang:get_stacktrace()]),
|
||||
St = erlang:get_stacktrace(),
|
||||
?ERROR_MSG("Unknown ~p:~p, ~p", [E, R, St]),
|
||||
{error, list_certificates}
|
||||
end;
|
||||
false ->
|
||||
@ -489,7 +493,8 @@ format_certificate(DataCert, Verbose) ->
|
||||
end
|
||||
catch
|
||||
E:R ->
|
||||
?ERROR_MSG("Unknown ~p:~p, ~p", [E, R, erlang:get_stacktrace()]),
|
||||
St = erlang:get_stacktrace(),
|
||||
?ERROR_MSG("Unknown ~p:~p, ~p", [E, R, St]),
|
||||
fail_format_certificate(DomainName)
|
||||
end.
|
||||
|
||||
@ -614,7 +619,8 @@ revoke_certificates(DomainOrFile) ->
|
||||
throw:Throw ->
|
||||
Throw;
|
||||
E:R ->
|
||||
?ERROR_MSG("Unknown ~p:~p, ~p", [E, R, erlang:get_stacktrace()]),
|
||||
St = erlang:get_stacktrace(),
|
||||
?ERROR_MSG("Unknown ~p:~p, ~p", [E, R, St]),
|
||||
{error, revoke_certificate}
|
||||
end.
|
||||
|
||||
@ -1118,7 +1124,8 @@ save_certificate({ok, DomainName, Cert}) ->
|
||||
throw:Throw ->
|
||||
Throw;
|
||||
E:R ->
|
||||
?ERROR_MSG("Unknown ~p:~p, ~p", [E, R, erlang:get_stacktrace()]),
|
||||
St = erlang:get_stacktrace(),
|
||||
?ERROR_MSG("Unknown ~p:~p, ~p", [E, R, St]),
|
||||
{error, DomainName, saving}
|
||||
end.
|
||||
|
||||
|
@ -380,11 +380,12 @@ safe_apply(Hook, Module, Function, Args) ->
|
||||
apply(Module, Function, Args)
|
||||
end
|
||||
catch E:R when E /= exit; R /= normal ->
|
||||
St = get_stacktrace(),
|
||||
?ERROR_MSG("Hook ~p crashed when running ~p:~p/~p:~n"
|
||||
"** Reason = ~p~n"
|
||||
"** Arguments = ~p",
|
||||
[Hook, Module, Function, length(Args),
|
||||
{E, R, get_stacktrace()}, Args]),
|
||||
{E, R, St}, Args]),
|
||||
'EXIT'
|
||||
end.
|
||||
|
||||
|
@ -71,8 +71,9 @@ start_link() ->
|
||||
route(Packet) ->
|
||||
try do_route(Packet)
|
||||
catch E:R ->
|
||||
St = erlang:get_stacktrace(),
|
||||
?ERROR_MSG("failed to route packet:~n~s~nReason = ~p",
|
||||
[xmpp:pp(Packet), {E, {R, erlang:get_stacktrace()}}])
|
||||
[xmpp:pp(Packet), {E, {R, St}}])
|
||||
end.
|
||||
|
||||
-spec route_iq(iq(), function()) -> ok.
|
||||
|
@ -91,8 +91,9 @@ start_link() ->
|
||||
route(Packet) ->
|
||||
try do_route(Packet)
|
||||
catch E:R ->
|
||||
St = erlang:get_stacktrace(),
|
||||
?ERROR_MSG("failed to route packet:~n~s~nReason = ~p",
|
||||
[xmpp:pp(Packet), {E, {R, erlang:get_stacktrace()}}])
|
||||
[xmpp:pp(Packet), {E, {R, St}}])
|
||||
end.
|
||||
|
||||
-spec route(jid(), jid(), xmlel() | stanza()) -> ok.
|
||||
|
@ -122,10 +122,11 @@ row_to_route(Domain, {ServerHost, NodeS, PidS, LocalHintS} = Row) ->
|
||||
catch _:{bad_node, _} ->
|
||||
[];
|
||||
E:R ->
|
||||
St = erlang:get_stacktrace(),
|
||||
?ERROR_MSG("failed to decode row from 'route' table:~n"
|
||||
"Row = ~p~n"
|
||||
"Domain = ~s~n"
|
||||
"Reason = ~p",
|
||||
[Row, Domain, {E, {R, erlang:get_stacktrace()}}]),
|
||||
[Row, Domain, {E, {R, St}}]),
|
||||
[]
|
||||
end.
|
||||
|
@ -95,8 +95,9 @@ start_link() ->
|
||||
route(Packet) ->
|
||||
try do_route(Packet)
|
||||
catch E:R ->
|
||||
St = erlang:get_stacktrace(),
|
||||
?ERROR_MSG("failed to route packet:~n~s~nReason = ~p",
|
||||
[xmpp:pp(Packet), {E, {R, erlang:get_stacktrace()}}])
|
||||
[xmpp:pp(Packet), {E, {R, St}}])
|
||||
end.
|
||||
|
||||
clean_temporarily_blocked_table() ->
|
||||
|
@ -142,9 +142,10 @@ route(Packet) ->
|
||||
Packet1 ->
|
||||
try do_route(Packet1), ok
|
||||
catch E:R ->
|
||||
St = erlang:get_stacktrace(),
|
||||
?ERROR_MSG("failed to route packet:~n~s~nReason = ~p",
|
||||
[xmpp:pp(Packet1),
|
||||
{E, {R, erlang:get_stacktrace()}}])
|
||||
{E, {R, St}}])
|
||||
end
|
||||
end.
|
||||
|
||||
|
@ -114,8 +114,9 @@ process_iq(_Host, Module, Function, IQ) ->
|
||||
ignore ->
|
||||
ok
|
||||
catch E:R ->
|
||||
St = erlang:get_stacktrace(),
|
||||
?ERROR_MSG("failed to process iq:~n~s~nReason = ~p",
|
||||
[xmpp:pp(IQ), {E, {R, erlang:get_stacktrace()}}]),
|
||||
[xmpp:pp(IQ), {E, {R, St}}]),
|
||||
Txt = <<"Module failed to handle the query">>,
|
||||
Err = xmpp:err_internal_server_error(Txt, IQ#iq.lang),
|
||||
ejabberd_router:route_error(IQ, Err)
|
||||
|
@ -193,7 +193,8 @@ process([Call], #request{method = 'POST', data = Data, ip = IPPort} = Req) ->
|
||||
?DEBUG("Bad Request: ~p", [_Err]),
|
||||
badrequest_response(<<"Invalid JSON input">>);
|
||||
_:_Error ->
|
||||
?DEBUG("Bad Request: ~p ~p", [_Error, erlang:get_stacktrace()]),
|
||||
St = erlang:get_stacktrace(),
|
||||
?DEBUG("Bad Request: ~p ~p", [_Error, St]),
|
||||
badrequest_response()
|
||||
end;
|
||||
process([Call], #request{method = 'GET', q = Data, ip = {IP, _}} = Req) ->
|
||||
@ -210,9 +211,9 @@ process([Call], #request{method = 'GET', q = Data, ip = {IP, _}} = Req) ->
|
||||
throw:{error, unknown_command} ->
|
||||
json_format({404, 44, <<"Command not found.">>});
|
||||
_:_Error ->
|
||||
|
||||
?DEBUG("Bad Request: ~p ~p", [_Error, erlang:get_stacktrace()]),
|
||||
badrequest_response()
|
||||
St = erlang:get_stacktrace(),
|
||||
?DEBUG("Bad Request: ~p ~p", [_Error, St]),
|
||||
badrequest_response()
|
||||
end;
|
||||
process([_Call], #request{method = 'OPTIONS', data = <<>>}) ->
|
||||
{200, ?OPTIONS_HEADER, []};
|
||||
@ -314,7 +315,8 @@ 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)};
|
||||
_Error ->
|
||||
?ERROR_MSG("REST API Error: ~p ~p", [_Error, erlang:get_stacktrace()]),
|
||||
St = erlang:get_stacktrace(),
|
||||
?ERROR_MSG("REST API Error: ~p ~p", [_Error, St]),
|
||||
{500, <<"internal_error">>}
|
||||
end;
|
||||
{error, Msg} ->
|
||||
|
@ -2815,9 +2815,9 @@ process_item_change(Item, SD, UJID) ->
|
||||
undefined ->
|
||||
<<"">>
|
||||
end,
|
||||
St = erlang:get_stacktrace(),
|
||||
?ERROR_MSG("failed to set item ~p~s: ~p",
|
||||
[Item, FromSuffix,
|
||||
{E, {R, erlang:get_stacktrace()}}]),
|
||||
[Item, FromSuffix, {E, {R, St}}]),
|
||||
{error, xmpp:err_internal_server_error()}
|
||||
end.
|
||||
|
||||
|
@ -321,8 +321,9 @@ process_iq_get(#iq{to = To, lang = Lang,
|
||||
ver = Version}
|
||||
end)
|
||||
catch E:R ->
|
||||
St = erlang:get_stacktrace(),
|
||||
?ERROR_MSG("failed to process roster get for ~s: ~p",
|
||||
[jid:encode(To), {E, {R, erlang:get_stacktrace()}}]),
|
||||
[jid:encode(To), {E, {R, St}}]),
|
||||
Txt = <<"Roster module has failed">>,
|
||||
xmpp:make_error(IQ, xmpp:err_internal_server_error(Txt, Lang))
|
||||
end.
|
||||
|
Loading…
Reference in New Issue
Block a user