Skip to content

Commit

Permalink
Improve exception hierarchy
Browse files Browse the repository at this point in the history
ProxyException -> MitmproxyException
NetlibException inherits from MitmproxyException
  • Loading branch information
cortesi committed Oct 19, 2016
1 parent 01a449b commit 9491d85
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
30 changes: 15 additions & 15 deletions mitmproxy/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
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.
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.
Expand All @@ -20,15 +20,15 @@ def __init__(self, message=None):
super().__init__(message)


class Kill(ProxyException):
class Kill(MitmproxyException):

"""
Signal that both client and server connection(s) should be killed immediately.
"""
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.
Expand Down Expand Up @@ -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.
"""
Expand Down
1 change: 1 addition & 0 deletions mitmproxy/proxy/protocol/rawtcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import netlib.tcp
from mitmproxy import tcp
from mitmproxy import flow
from mitmproxy import exceptions
from mitmproxy.proxy.protocol import base


Expand Down

0 comments on commit 9491d85

Please sign in to comment.