From 9491d8589a265be33a5d6fac92c1213fd5b719d4 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Thu, 20 Oct 2016 11:29:53 +1300 Subject: Improve exception hierarchy ProxyException -> MitmproxyException NetlibException inherits from MitmproxyException --- mitmproxy/exceptions.py | 30 +++++++++++++++--------------- mitmproxy/proxy/protocol/rawtcp.py | 1 + 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/mitmproxy/exceptions.py b/mitmproxy/exceptions.py index 82022d31..a7ecf17f 100644 --- a/mitmproxy/exceptions.py +++ b/mitmproxy/exceptions.py @@ -2,7 +2,7 @@ We try to be very hygienic regarding the exceptions we throw: - Every exception that might be externally visible to users shall be a subclass - of ProxyException.p + of MitmproxyException.p - Every exception in the base net module shall be a subclass of NetlibException, and will not be propagated directly to users. @@ -10,7 +10,7 @@ See also: http://lucumr.pocoo.org/2014/10/16/on-error-handling/ """ -class ProxyException(Exception): +class MitmproxyException(Exception): """ Base class for all exceptions thrown by mitmproxy. @@ -20,7 +20,7 @@ class ProxyException(Exception): super().__init__(message) -class Kill(ProxyException): +class Kill(MitmproxyException): """ Signal that both client and server connection(s) should be killed immediately. @@ -28,7 +28,7 @@ class Kill(ProxyException): pass -class ProtocolException(ProxyException): +class ProtocolException(MitmproxyException): """ ProtocolExceptions are caused by invalid user input, unavailable network resources, or other events that are outside of our influence. @@ -69,48 +69,48 @@ class Http2ZombieException(ProtocolException): pass -class ServerException(ProxyException): +class ServerException(MitmproxyException): pass -class ContentViewException(ProxyException): +class ContentViewException(MitmproxyException): pass -class ReplayException(ProxyException): +class ReplayException(MitmproxyException): pass -class FlowReadException(ProxyException): +class FlowReadException(MitmproxyException): pass -class ControlException(ProxyException): +class ControlException(MitmproxyException): pass -class SetServerNotAllowedException(ProxyException): +class SetServerNotAllowedException(MitmproxyException): pass -class OptionsError(Exception): +class OptionsError(MitmproxyException): pass -class AddonError(Exception): +class AddonError(MitmproxyException): pass -class AddonHalt(Exception): +class AddonHalt(MitmproxyException): pass """ - Every net Exception raised shall be a subclass of NetlibException. + Net-layer exceptions """ -class NetlibException(Exception): +class NetlibException(MitmproxyException): """ Base class for all exceptions thrown by netlib. """ diff --git a/mitmproxy/proxy/protocol/rawtcp.py b/mitmproxy/proxy/protocol/rawtcp.py index d117fb41..8230c50b 100644 --- a/mitmproxy/proxy/protocol/rawtcp.py +++ b/mitmproxy/proxy/protocol/rawtcp.py @@ -5,6 +5,7 @@ from OpenSSL import SSL import netlib.tcp from mitmproxy import tcp from mitmproxy import flow +from mitmproxy import exceptions from mitmproxy.proxy.protocol import base -- cgit v1.2.3