diff options
author | Maximilian Hils <git@maximilianhils.com> | 2016-05-11 11:15:26 -0600 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2016-05-11 11:15:36 -0600 |
commit | 67a37e6d1f4fd5411e902ee5a59e2085d6c8a12d (patch) | |
tree | a0cb764e4284f585feb29eb52199ca3ff432e885 /mitmproxy/exceptions.py | |
parent | 4c8e334642d98a5ed005b7cf6fc7e9cc379e6deb (diff) | |
download | mitmproxy-67a37e6d1f4fd5411e902ee5a59e2085d6c8a12d.tar.gz mitmproxy-67a37e6d1f4fd5411e902ee5a59e2085d6c8a12d.tar.bz2 mitmproxy-67a37e6d1f4fd5411e902ee5a59e2085d6c8a12d.zip |
improve script loading
Diffstat (limited to 'mitmproxy/exceptions.py')
-rw-r--r-- | mitmproxy/exceptions.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/mitmproxy/exceptions.py b/mitmproxy/exceptions.py index 86bf75ae..52fd36d1 100644 --- a/mitmproxy/exceptions.py +++ b/mitmproxy/exceptions.py @@ -7,6 +7,10 @@ See also: http://lucumr.pocoo.org/2014/10/16/on-error-handling/ """ from __future__ import (absolute_import, print_function, division) +import traceback + +import sys + class ProxyException(Exception): """ @@ -59,7 +63,23 @@ class ReplayException(ProxyException): class ScriptException(ProxyException): - pass + @classmethod + def from_exception_context(cls, cut_tb=1): + """ + Must be called while the current stack handles an exception. + + Args: + cut_tb: remove N frames from the stack trace to hide internal calls. + """ + exc_type, exc_value, exc_traceback = sys.exc_info() + + while cut_tb > 0: + exc_traceback = exc_traceback.tb_next + cut_tb -= 1 + + tb = "".join(traceback.format_exception(exc_type, exc_value, exc_traceback)) + + return cls(tb) class FlowReadException(ProxyException): |