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

Print full startup/initialization error #15569

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/15569.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Print full error and stack-trace of any exception that occurs during startup/initialization.
19 changes: 18 additions & 1 deletion synapse/app/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import sys
import traceback
import warnings
from textwrap import indent
from typing import (
TYPE_CHECKING,
Any,
Expand Down Expand Up @@ -208,12 +209,28 @@ def quit_with_error(error_string: str) -> NoReturn:
sys.exit(1)


# via https://peps.python.org/pep-3134/#enhanced-reporting
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved
def format_exception_chain(exc: BaseException) -> str:
if exc.__cause__:
result = format_exception_chain(exc.__cause__)
result += "\nThe above exception was the direct cause..."
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved
elif exc.__context__:
result = format_exception_chain(exc.__context__)
result += "\nDuring handling of the above exception, ..."

return "".join(traceback.format_exception(exc))
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved


def handle_startup_exception(e: Exception) -> NoReturn:
# Exceptions that occur between setting up the logging and forking or starting
# the reactor are written to the logs, followed by a summary to stderr.
logger.exception("Exception during startup")

error_string = format_exception_chain(e)
indendeted_error_string = indent(error_string, " ")
Copy link
Contributor Author

@MadLittleMods MadLittleMods May 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indenting is optional to me (feel free to poke to remove). Just trying to do what we did before but actually do it correctly for multi-line messages

MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved

quit_with_error(
f"Error during initialisation:\n {e}\nThere may be more information in the logs."
f"Error during initialisation:\n{indendeted_error_string}\nThere may be more information in the logs."
)


Expand Down