Better server error messaging#3102
Conversation
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR improves server startup error handling by introducing a new error handling pattern that provides clearer, more user-friendly error messages for common startup issues like port conflicts. It addresses issues #3100 where errors were logged multiple times with confusing stack traces, and requires PR #3101 which upgrades tracerite.
Key changes:
- New error handler module provides clean error reporting for OSError and ServerError during startup
- Simplified socket configuration by removing nested error handling wrapper
- Better management of worker state and EOFError handling with conditional cleanup logic
Reviewed changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| sanic/startup/errors.py | New module introducing error handler pattern for startup failures with OSError and ServerError support |
| sanic/main.py | Integrates tracerite loading and wraps CLI execution with startup error handler |
| sanic/server/socket.py | Removes OSError wrapping logic, allowing errors to propagate to central handler |
| sanic/mixins/startup.py | Adds EOFError handling for Manager creation and tracks worker state to prevent cleanup issues |
| tests/test_startup_errors.py | New test suite covering all error handling scenarios |
| tests/test_exceptions_handler.py | Updates tests to accommodate tracerite HTML rendering changes |
| setup.py | Updates tracerite dependency to version 2.2.0 or higher |
| pyproject.toml | Adds ruff ignore rules for import ordering in main.py |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…value (#3106) * Initial plan * Replace hardcoded errno 98 with errno.EADDRINUSE constant Co-authored-by: ahopkins <166269+ahopkins@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: ahopkins <166269+ahopkins@users.noreply.github.com>
Tronic
left a comment
There was a problem hiding this comment.
LGTM, works here - no more tracebacks shown. Thanks for the quick response!
|
Maybe that's for another PR and pending another tracerite release, but one might consider also adding |
|
I did put int in main.py, it would run only in CLI. I went back and forth on this, but I think this is the right compromise. Happy to entertain other thoughts though. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3102 +/- ##
=============================================
+ Coverage 87.643% 87.683% +0.039%
=============================================
Files 103 104 +1
Lines 7729 7778 +49
Branches 1225 1236 +11
=============================================
+ Hits 6774 6820 +46
- Misses 660 662 +2
- Partials 295 296 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Requires #3101
Resolves #3100
This has long been something that was less than clear: errors when starting with an already in use port.
This PR introduces a new pattern for catching some common startup issues and providing better display.