From e4ae35dabb6fdeb3d9de08c6611f72062fdf0607 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Wed, 21 Sep 2016 21:49:32 -0700 Subject: fix mitmdump error logging, fix #1549 (#1565) This commit replaces the logging statement introduced in afe34e8b28988bdff91123862194606152c03c33 with the previous implementation where an exception is raised. ProtocolExceptions are normally logged as regular warnings, achieving the same effect for the end user. However, this retains the full stack trace for debug-level logging, which makes the analysis of client errors considerably easier. --- mitmproxy/exceptions.py | 4 ++++ mitmproxy/protocol/http.py | 11 ++++++----- mitmproxy/proxy/server.py | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/mitmproxy/exceptions.py b/mitmproxy/exceptions.py index c4797e21..6873215c 100644 --- a/mitmproxy/exceptions.py +++ b/mitmproxy/exceptions.py @@ -27,6 +27,10 @@ class Kill(ProxyException): class ProtocolException(ProxyException): + """ + ProtocolExceptions are caused by invalid user input, unavailable network resources, + or other events that are outside of our influence. + """ pass diff --git a/mitmproxy/protocol/http.py b/mitmproxy/protocol/http.py index 1418d6e9..1632e66f 100644 --- a/mitmproxy/protocol/http.py +++ b/mitmproxy/protocol/http.py @@ -153,12 +153,13 @@ class HttpLayer(base.Layer): # We optimistically guess there might be an HTTP client on the # other end self.send_error_response(400, repr(e)) - self.log( - "request", - "warn", - "HTTP protocol error in client request: %s" % e + six.reraise( + exceptions.ProtocolException, + exceptions.ProtocolException( + "HTTP protocol error in client request: {}".format(e) + ), + sys.exc_info()[2] ) - return self.log("request", "debug", [repr(request)]) diff --git a/mitmproxy/proxy/server.py b/mitmproxy/proxy/server.py index 4fd5755a..c5fd5f9e 100644 --- a/mitmproxy/proxy/server.py +++ b/mitmproxy/proxy/server.py @@ -132,7 +132,7 @@ class ConnectionHandler(object): self.log(str(e), "warn") self.log("Invalid certificate, closing connection. Pass --insecure to disable validation.", "warn") else: - self.log(repr(e), "warn") + self.log(str(e), "warn") self.log(traceback.format_exc(), "debug") # If an error propagates to the topmost level, -- cgit v1.2.3