diff options
-rw-r--r-- | mitmproxy/addons/script.py | 8 | ||||
-rw-r--r-- | test/mitmproxy/addons/test_script.py | 6 |
2 files changed, 7 insertions, 7 deletions
diff --git a/mitmproxy/addons/script.py b/mitmproxy/addons/script.py index a1e632db..f5c4d599 100644 --- a/mitmproxy/addons/script.py +++ b/mitmproxy/addons/script.py @@ -48,7 +48,7 @@ def script_error_handler(path, exc, msg="", tb=False): lineno = "" if hasattr(exc, "lineno"): lineno = str(exc.lineno) - log_msg = "Error in Script {}:{} {}".format(path, lineno, exception) + log_msg = "in Script {}:{} {}".format(path, lineno, exception) if tb: etype, value, tback = sys.exc_info() tback = addonmanager.cut_traceback(tback, "invoke_addon") @@ -73,7 +73,7 @@ class Script: self.last_load = 0 self.last_mtime = 0 if not os.path.isfile(self.fullpath): - raise exceptions.OptionsError('No such script: "%s"' % self.fullpath) + raise exceptions.OptionsError('No such script') @property def addons(self): @@ -148,13 +148,13 @@ class ScriptLoader: for evt, arg in eventsequence.iterate(f): ctx.master.addons.invoke_addon(s, evt, arg) except exceptions.OptionsError as e: - raise exceptions.CommandError("Error running script: %s" % e) from e + script_error_handler(path, e, msg=str(e)) def configure(self, updated): if "scripts" in updated: for s in ctx.options.scripts: if ctx.options.scripts.count(s) > 1: - raise exceptions.OptionsError("Duplicate script: %s" % s) + raise exceptions.OptionsError("Duplicate script") for a in self.addons[:]: if a.path not in ctx.options.scripts: diff --git a/test/mitmproxy/addons/test_script.py b/test/mitmproxy/addons/test_script.py index 623ed9a1..79fa22dc 100644 --- a/test/mitmproxy/addons/test_script.py +++ b/test/mitmproxy/addons/test_script.py @@ -183,9 +183,9 @@ class TestScriptLoader: def test_script_run_nonexistent(self): sc = script.ScriptLoader() - with taddons.context(sc): - with pytest.raises(exceptions.CommandError): - sc.script_run([tflow.tflow(resp=True)], "/") + with taddons.context(sc) as tctx: + sc.script_run([tflow.tflow(resp=True)], "/") + tctx.master.has_log("/: No such script") def test_simple(self): sc = script.ScriptLoader() |