Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit d19d1ed

Browse files
Print full startup/initialization error (#15569)
I found the error in the **Before** really vague and obtuse and didn't realize port `5432` corresponded to the Postgres port until searching the codebase. It says to check the logs but that wasn't my first instinct. It's just more obvious if we just print the full thing which gives context of the error type and the traceback to the relevant area of code. #### Before ``` $ poetry run python -m synapse.app.homeserver -c homeserver.yaml ********************************************************************************** Error during initialisation: connection to server at "localhost" (::1), port 5432 failed: Connection refused Is the server running on that host and accepting TCP/IP connections? connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused Is the server running on that host and accepting TCP/IP connections? There may be more information in the logs. ********************************************************************************** ``` #### After ```sh $ poetry run python -m synapse.app.homeserver -c homeserver.yaml ********************************************************************************** Error during initialisation: Traceback (most recent call last): File "/home/eric/Documents/github/element/synapse/synapse/app/homeserver.py", line 352, in setup hs.setup() File "/home/eric/Documents/github/element/synapse/synapse/server.py", line 337, in setup self.datastores = Databases(self.DATASTORE_CLASS, self) File "/home/eric/Documents/github/element/synapse/synapse/storage/databases/__init__.py", line 65, in __init__ with make_conn(database_config, engine, "startup") as db_conn: File "/home/eric/Documents/github/element/synapse/synapse/storage/database.py", line 161, in make_conn native_db_conn = engine.module.connect(**db_params) File "/home/eric/.cache/pypoetry/virtualenvs/matrix-synapse-xCtC9ulO-py3.10/lib/python3.10/site-packages/psycopg2/__init__.py", line 122, in connect conn = _connect(dsn, connection_factory=connection_factory, **kwasync) psycopg2.OperationalError: connection to server at "localhost" (::1), port 5432 failed: Connection refused Is the server running on that host and accepting TCP/IP connections? connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused Is the server running on that host and accepting TCP/IP connections? There may be more information in the logs. ********************************************************************************** ```
1 parent 5a7742a commit d19d1ed

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

changelog.d/15569.feature

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Print full error and stack-trace of any exception that occurs during startup/initialization.

synapse/app/_base.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import sys
2222
import traceback
2323
import warnings
24+
from textwrap import indent
2425
from typing import (
2526
TYPE_CHECKING,
2627
Any,
@@ -212,8 +213,12 @@ def handle_startup_exception(e: Exception) -> NoReturn:
212213
# Exceptions that occur between setting up the logging and forking or starting
213214
# the reactor are written to the logs, followed by a summary to stderr.
214215
logger.exception("Exception during startup")
216+
217+
error_string = "".join(traceback.format_exception(e))
218+
indented_error_string = indent(error_string, " ")
219+
215220
quit_with_error(
216-
f"Error during initialisation:\n {e}\nThere may be more information in the logs."
221+
f"Error during initialisation:\n{indented_error_string}\nThere may be more information in the logs."
217222
)
218223

219224

0 commit comments

Comments
 (0)