Skip to content

Commit ee72b9f

Browse files
pncclaude
andcommitted
Show mitmproxy startup errors instead of failing silently
Poll for up to 3s instead of sleeping 1s to reliably catch fast failures like port-in-use. Print the actual mitmdump log output so the user sees the real error. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent b3d0970 commit ee72b9f

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

vm.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -461,13 +461,17 @@ def start_mitmproxy(proxy_port: int = PROXY_PORT) -> subprocess.Popen:
461461
log_file = log_path.open("w")
462462
print(f"Starting mitmproxy on port {proxy_port} (log: .vm/mitmdump.log)...")
463463
proc = subprocess.Popen(cmd, stdout=log_file, stderr=log_file)
464-
time.sleep(1)
465-
if proc.poll() is not None:
466-
log_file.flush()
467-
sys.exit(
468-
f"mitmdump failed to start (exit code {proc.returncode}). "
469-
f"Check {log_path} — port {proxy_port} may already be in use."
470-
)
464+
465+
# Poll for up to 3 seconds to catch fast failures (e.g. port in use).
466+
for _ in range(15):
467+
time.sleep(0.2)
468+
if proc.poll() is not None:
469+
log_file.flush()
470+
log_tail = log_path.read_text(errors="replace").strip()
471+
sys.exit(
472+
f"mitmdump failed to start (exit code {proc.returncode}).\n"
473+
f"{log_tail}"
474+
)
471475
return proc
472476

473477

0 commit comments

Comments
 (0)