Merge pull request #3849 from sarthak212/errorhandling
Fix:Addon OptionsError is neither logged, nor does it stop mitmproxy
This commit is contained in:
commit
3046a628fd
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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()
|
||||
]
|
||||
|
Loading…
Reference in New Issue