Repository navigation
fix: log actionable error when the server cannot bind its port - #243
scottsgevor wants to merge 1 commit into
Conversation
werkzeug reports bind failures by printing to stderr and calling sys.exit(1), which is invisible when aw-qt spawns modules without a console. Catch the SystemExit and log the likely cause (including the Windows Hyper-V/WSL port-reservation hint) so the reason reaches the module log and the aw-qt crash dialog.
Confidence Score: 5/5
[Low impact] The PR appears safe to merge. SummaryAdds a logged explanation when
No actionable issues found. Tests were not run during this review. Reviews (1) · Last reviewed commit: "fix: log actionable error when the serve..." · Reviewed by Greptile |
|
Thanks for making this visible in the module log. I reviewed head 067c863: the nonzero SystemExit is logged and re-raised, so startup failure still propagates. I found no blocking issue in this diff; I have not run its tests locally. The remaining merge prerequisite is CI: Build, Lint and CodeQL are all action_required on this head, not passed. A maintainer with write access needs to approve the fork workflow runs. No author change is requested from this review; once those runs complete green, this can receive the exact-head ready review. Greptile 5/5 alone does not establish that the tests ran. |
Problem
When the server cannot bind its port, werkzeug prints the error to stderr and calls
sys.exit(1).aw-qtstarts modules without a console and deliberately does not pipe stdout/stderr (#27), so the message is lost: the module log stops atUsing database file…and the tray only reports "Module aw-server crashed and was auto-restarted".On Windows this commonly happens when Hyper-V/WSL has reserved a port range that includes 5600 (
WinError 10013), see ActivityWatch/activitywatch#571. The existingexcept OSErrorin_start()never fires because werkzeug exits viaSystemExit.Change
Catch
SystemExitaroundapp.run(). For a non-zero exit code, log the address that failed to bind and the likely causes. On Windows, include the Hyper-V/WSL hint and thenetshcommands that reserve the port for ActivityWatch. The exception is re-raised, so the exit code is unchanged.The aw-qt crash dialog already shows the module log, so the reason becomes visible without any aw-qt change. A companion aw-qt PR adds a dedicated dialog for this case.
Companion PR: ActivityWatch/aw-qt#164
Test
tests/test_server.py::test_start_logs_bind_failure, which simulates werkzeug'sSystemExit(1)and asserts that it propagates and that the log contains the address.pytest tests/test_server.py: 58 passed.ruff check/black --checkon the changed files: clean.Refs ActivityWatch/activitywatch#571