aboutsummaryrefslogtreecommitdiffstats
path: root/src/cowboy_stream.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2017-09-21 12:53:21 +0200
committerLoïc Hoguin <[email protected]>2017-09-21 12:53:21 +0200
commita6126306a2b9e956c38b10e8cf1e60acdb4e63fe (patch)
treea36c2cea7a85fdc035f7e8bd1b33f43cb968e141 /src/cowboy_stream.erl
parent17400f73b4f84c997abe4e03837d1642d3a188ce (diff)
downloadcowboy-a6126306a2b9e956c38b10e8cf1e60acdb4e63fe.tar.gz
cowboy-a6126306a2b9e956c38b10e8cf1e60acdb4e63fe.tar.bz2
cowboy-a6126306a2b9e956c38b10e8cf1e60acdb4e63fe.zip
Centralize stream handler error reporting in cowboy_stream
Diffstat (limited to 'src/cowboy_stream.erl')
-rw-r--r--src/cowboy_stream.erl46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/cowboy_stream.erl b/src/cowboy_stream.erl
index fbad569..b0a55f8 100644
--- a/src/cowboy_stream.erl
+++ b/src/cowboy_stream.erl
@@ -76,6 +76,7 @@
-export([info/3]).
-export([terminate/3]).
-export([early_error/5]).
+-export([report_error/5]).
%% Note that this and other functions in this module do NOT catch
%% exceptions. We want the exception to go all the way down to the
@@ -144,3 +145,48 @@ early_error(StreamID, Reason, PartialReq, Resp, Opts) ->
Handler:early_error(StreamID, Reason,
PartialReq, Resp, Opts#{stream_handlers => Tail})
end.
+
+-spec report_error(atom(), list(), error | exit | throw, any(), list()) -> ok.
+report_error(init, [StreamID, Req, Opts], Class, Exception, Stacktrace) ->
+ error_logger:error_msg(
+ "Unhandled exception ~p:~p in cowboy_stream:init(~p, Req, Opts)~n"
+ "Stacktrace: ~p~n"
+ "Req: ~p~n"
+ "Opts: ~p~n",
+ [Class, Exception, StreamID, Stacktrace, Req, Opts]);
+report_error(data, [StreamID, IsFin, Data, State], Class, Exception, Stacktrace) ->
+ error_logger:error_msg(
+ "Unhandled exception ~p:~p in cowboy_stream:data(~p, ~p, Data, State)~n"
+ "Stacktrace: ~p~n"
+ "Data: ~p~n"
+ "State: ~p~n",
+ [Class, Exception, StreamID, IsFin, Stacktrace, Data, State]);
+report_error(info, [StreamID, Msg, State], Class, Exception, Stacktrace) ->
+ error_logger:error_msg(
+ "Unhandled exception ~p:~p in cowboy_stream:info(~p, Msg, State)~n"
+ "Stacktrace: ~p~n"
+ "Msg: ~p~n"
+ "State: ~p~n",
+ [Class, Exception, StreamID, Stacktrace, Msg, State]);
+report_error(terminate, [StreamID, Reason, State], Class, Exception, Stacktrace) ->
+ error_logger:error_msg(
+ "Unhandled exception ~p:~p in cowboy_stream:terminate(~p, Reason, State)~n"
+ "Stacktrace: ~p~n"
+ "Reason: ~p~n"
+ "State: ~p~n",
+ [Class, Exception, StreamID, Stacktrace, Reason, State]);
+report_error(early_error, [StreamID, Reason, PartialReq, Resp, Opts], Class, Exception, Stacktrace) ->
+ error_logger:error_msg(
+ "Unhandled exception ~p:~p in cowboy_stream:early_error(~p, Reason, PartialReq, Resp, Opts)~n"
+ "Stacktrace: ~p~n"
+ "Reason: ~p~n"
+ "PartialReq: ~p~n"
+ "Resp: ~p~n"
+ "Opts: ~p~n",
+ [Class, Exception, StreamID, Stacktrace, Reason, PartialReq, Resp, Opts]);
+report_error(Callback, _, Class, Reason, Stacktrace) ->
+ error_logger:error_msg(
+ "Exception occurred in unknown callback ~p~n"
+ "Reason: ~p:~p~n"
+ "Stacktrace: ~p~n",
+ [Callback, Class, Reason, Stacktrace]).