From 8e623296f4fa735e430cedeb57d816dfcca7883b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Fri, 19 May 2017 16:46:28 +0200 Subject: Ensure the stacktrace is passed when crashing --- src/gun.erl | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/gun.erl b/src/gun.erl index 173bb2d..3eafe10 100644 --- a/src/gun.erl +++ b/src/gun.erl @@ -78,7 +78,7 @@ %% Internals. -export([start_link/4]). --export([init/5]). +-export([proc_lib_hack/5]). -export([system_continue/3]). -export([system_terminate/4]). -export([system_code_change/4]). @@ -527,9 +527,19 @@ dbg_send_raw(ServerPid, Data) -> %% Internals. start_link(Owner, Host, Port, Opts) -> - proc_lib:start_link(?MODULE, init, + proc_lib:start_link(?MODULE, proc_lib_hack, [self(), Owner, Host, Port, Opts]). +proc_lib_hack(Parent, Owner, Host, Port, Opts) -> + try + init(Parent, Owner, Host, Port, Opts) + catch + _:normal -> exit(normal); + _:shutdown -> exit(shutdown); + _:Reason = {shutdown, _} -> exit(Reason); + _:Reason -> exit({Reason, erlang:get_stacktrace()}) + end. + init(Parent, Owner, Host, Port, Opts) -> ok = proc_lib:init_ack(Parent, {ok, self()}), Retry = maps:get(retry, Opts, 5), -- cgit v1.2.3