0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 12:20:24 +00:00

Fix propagating the stacktrace on errors for OTP 19

This commit is contained in:
Loïc Hoguin 2017-09-14 18:23:55 +02:00
parent 5027d1335d
commit 1cc877b649
No known key found for this signature in database
GPG key ID: 71366FF21851DF03

View file

@ -161,12 +161,18 @@ report_crash(Ref, StreamID, Pid, Reason, Stacktrace) ->
%% @todo Better spec. %% @todo Better spec.
-spec request_process(_, _, _) -> _. -spec request_process(_, _, _) -> _.
request_process(Req, Env, Middlewares) -> request_process(Req, Env, Middlewares) ->
OTP = erlang:system_info(otp_release),
try try
execute(Req, Env, Middlewares) execute(Req, Env, Middlewares)
catch catch
exit:Reason -> exit:Reason ->
Stacktrace = erlang:get_stacktrace(), Stacktrace = erlang:get_stacktrace(),
erlang:raise(exit, {Reason, Stacktrace}, Stacktrace); erlang:raise(exit, {Reason, Stacktrace}, Stacktrace);
%% OTP 19 does not propagate any exception stacktraces,
%% we therefore add it for every class of exception.
_:Reason when OTP =:= "19" ->
Stacktrace = erlang:get_stacktrace(),
erlang:raise(exit, {Reason, Stacktrace}, Stacktrace);
Class:Reason -> Class:Reason ->
erlang:raise(Class, Reason, erlang:get_stacktrace()) erlang:raise(Class, Reason, erlang:get_stacktrace())
end. end.