diff options
author | Maximilian Hils <git@maximilianhils.com> | 2020-04-02 10:13:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-02 10:13:30 +0200 |
commit | 3046a628fd0b719ff587eac5f5fd6965cd5eac89 (patch) | |
tree | 3985e30c55b75a0e9d0e8904c0db4247893171db | |
parent | 67368232c509a38087c2809aeb193c0b7a1f541d (diff) | |
parent | 79b8fcc052f78f836dac2dcf0221097ff8c10c10 (diff) | |
download | mitmproxy-3046a628fd0b719ff587eac5f5fd6965cd5eac89.tar.gz mitmproxy-3046a628fd0b719ff587eac5f5fd6965cd5eac89.tar.bz2 mitmproxy-3046a628fd0b719ff587eac5f5fd6965cd5eac89.zip |
Merge pull request #3849 from sarthak212/errorhandling
Fix:Addon OptionsError is neither logged, nor does it stop mitmproxy
-rw-r--r-- | mitmproxy/addons/script.py | 13 | ||||
-rw-r--r-- | test/mitmproxy/addons/test_script.py | 11 | ||||
-rw-r--r-- | test/mitmproxy/data/addonscripts/configure.py | 21 |
3 files changed, 40 insertions, 5 deletions
diff --git a/mitmproxy/addons/script.py b/mitmproxy/addons/script.py index 3b2568c9..b3cb0999 100644 --- a/mitmproxy/addons/script.py +++ b/mitmproxy/addons/script.py @@ -105,11 +105,14 @@ class Script: # We're already running, so we have to explicitly register and # configure the addon ctx.master.addons.invoke_addon(self.ns, "running") - ctx.master.addons.invoke_addon( - self.ns, - "configure", - ctx.options.keys() - ) + try: + ctx.master.addons.invoke_addon( + self.ns, + "configure", + ctx.options.keys() + ) + except exceptions.OptionsError as e: + script_error_handler(self.fullpath, e, msg=str(e)) async def watcher(self): last_mtime = 0 diff --git a/test/mitmproxy/addons/test_script.py b/test/mitmproxy/addons/test_script.py index 05472d9a..61e19174 100644 --- a/test/mitmproxy/addons/test_script.py +++ b/test/mitmproxy/addons/test_script.py @@ -137,6 +137,17 @@ class TestScript: assert await tctx.master.await_log("error.py") @pytest.mark.asyncio + async def test_optionexceptions(self, tdata): + with taddons.context() as tctx: + sc = script.Script( + tdata.path("mitmproxy/data/addonscripts/configure.py"), + True, + ) + tctx.master.addons.add(sc) + tctx.configure(sc) + assert await tctx.master.await_log("Options Error") + + @pytest.mark.asyncio async def test_addon(self, tdata): with taddons.context() as tctx: sc = script.Script( diff --git a/test/mitmproxy/data/addonscripts/configure.py b/test/mitmproxy/data/addonscripts/configure.py new file mode 100644 index 00000000..6f6ac06a --- /dev/null +++ b/test/mitmproxy/data/addonscripts/configure.py @@ -0,0 +1,21 @@ +import typing + +from mitmproxy import exceptions + + +class OptionAddon: + def load(self, loader): + loader.add_option( + name = "optionaddon", + typespec = typing.Optional[int], + default = None, + help = "Option Addon", + ) + + def configure(self, updates): + raise exceptions.OptionsError("Options Error") + +addons = [ + OptionAddon() +] + |