Repository navigation
fix: log actionable error when the server cannot bind its port - #243
Open
scottsgevor wants to merge 1 commit into
Open
scottsgevor wants to merge 1 commit into
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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