Merge pull request #3849 from sarthak212/errorhandling

Fix:Addon OptionsError is neither logged, nor does it stop mitmproxy
This commit is contained in:
Maximilian Hils 2020-04-02 10:13:30 +02:00 committed by GitHub
commit 3046a628fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 5 deletions

View File

@ -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

View File

@ -136,6 +136,17 @@ class TestScript:
assert await tctx.master.await_log("ValueError: Error!")
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:

View File

@ -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()
]