From 3a7232b019f975a594a696eace46abcbfeec5b2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Tue, 31 Dec 2019 15:10:38 +0100 Subject: No longer use erlang:get_stacktrace/0 It has been deprecated in OTP and the new way is available on all supported OTP versions. --- src/cowboy_stream_h.erl | 31 +++++-------------------------- 1 file changed, 5 insertions(+), 26 deletions(-) (limited to 'src/cowboy_stream_h.erl') diff --git a/src/cowboy_stream_h.erl b/src/cowboy_stream_h.erl index 71b2948..2a50d6a 100644 --- a/src/cowboy_stream_h.erl +++ b/src/cowboy_stream_h.erl @@ -15,10 +15,6 @@ -module(cowboy_stream_h). -behavior(cowboy_stream). --ifdef(OTP_RELEASE). --compile({nowarn_deprecated_function, [{erlang, get_stacktrace, 0}]}). --endif. - -export([init/3]). -export([data/4]). -export([info/3]). @@ -285,33 +281,16 @@ send_request_body(Pid, Ref, fin, BodyLen, Data) -> %% Request process. -%% We catch all exceptions in order to add the stacktrace to -%% the exit reason as it is not propagated by proc_lib otherwise -%% and therefore not present in the 'EXIT' message. We want -%% the stacktrace in order to simplify debugging of errors. -%% -%% This + the behavior in proc_lib means that we will get a -%% {Reason, Stacktrace} tuple for every exceptions, instead of -%% just for errors and throws. -%% -%% @todo Better spec. +%% We add the stacktrace to exit exceptions here in order +%% to simplify the debugging of errors. The proc_lib library +%% already adds the stacktrace to other types of exceptions. -spec request_process(cowboy_req:req(), cowboy_middleware:env(), [module()]) -> ok. request_process(Req, Env, Middlewares) -> - OTP = erlang:system_info(otp_release), try execute(Req, Env, Middlewares) catch - exit:Reason -> - Stacktrace = erlang:get_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); - %% @todo I don't think this clause is necessary. - Class:Reason -> - erlang:raise(Class, Reason, erlang:get_stacktrace()) + exit:Reason:Stacktrace -> + erlang:raise(exit, {Reason, Stacktrace}, Stacktrace) end. execute(_, _, []) -> -- cgit v1.2.3