mirror of
https://github.com/vee1e/mitmproxy.git
synced 2026-09-02 02:37:15 +00:00
Improve error message for missing packages in frozen binaries (#5740)
This commit is contained in:
parent
0bbb0215c1
commit
d5f1d1c623
3 changed files with 20 additions and 0 deletions
|
|
@ -39,6 +39,17 @@ def load_script(path: str) -> Optional[types.ModuleType]:
|
|||
loader.exec_module(m)
|
||||
if not getattr(m, "name", None):
|
||||
m.name = path # type: ignore
|
||||
except ImportError as e:
|
||||
err_msg = str(e)
|
||||
if getattr(sys, "frozen", False):
|
||||
err_msg = (
|
||||
f"{err_msg}. \n"
|
||||
f"Note that mitmproxy's binaries include their own Python environment. "
|
||||
f"If your addon requires the installation of additional dependencies, "
|
||||
f"please install mitmproxy from PyPI "
|
||||
f"(https://docs.mitmproxy.org/stable/overview-installation/#installation-from-the-python-package-index-pypi)."
|
||||
)
|
||||
script_error_handler(path, e, msg=err_msg)
|
||||
except Exception as e:
|
||||
script_error_handler(path, e, msg=str(e))
|
||||
finally:
|
||||
|
|
|
|||
|
|
@ -123,6 +123,14 @@ class TestScript:
|
|||
await caplog_async.await_log("error.py")
|
||||
sc.done()
|
||||
|
||||
async def test_import_error(self, monkeypatch, tdata, caplog):
|
||||
monkeypatch.setattr(sys, "frozen", True, raising=False)
|
||||
script.Script(
|
||||
tdata.path("mitmproxy/data/addonscripts/import_error.py"),
|
||||
False,
|
||||
)
|
||||
assert "Note that mitmproxy's binaries include their own Python environment" in caplog.text
|
||||
|
||||
async def test_optionexceptions(self, tdata, caplog_async):
|
||||
with taddons.context() as tctx:
|
||||
sc = script.Script(
|
||||
|
|
|
|||
1
test/mitmproxy/data/addonscripts/import_error.py
Normal file
1
test/mitmproxy/data/addonscripts/import_error.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
import nonexistent
|
||||
Loading…
Add table
Add a link
Reference in a new issue