Skip to content

Commit

Permalink
fail more gracefully if the app runtime crashes before a logger hsa b…
Browse files Browse the repository at this point in the history
…een set
  • Loading branch information
dotchetter committed Dec 22, 2023
1 parent 39d658e commit b3fd307
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions pyttman/core/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,18 @@ def _generate_error_entry(message: MessageMixin, exc: BaseException) -> Reply:
traceback.print_exc()
warnings.warn(f"{datetime.now()} - A critical error occurred in the "
f"application logic. Error id: {error_id}")
pyttman.logger.log(level="error",
message=f"CRITICAL ERROR: ERROR ID={error_id} - "
f"The error was caught while processing "
f"message: '{message}'. Error message: '{exc}'")

auto_reply = pyttman.settings.MIDDLEWARE['FATAL_EXCEPTION_AUTO_REPLY']
error_message = (f"CRITICAL ERROR: ERROR ID={error_id} - "
f"The error was caught while processing message: "
f"'{message}'. Error message: '{exc}'")
try:
pyttman.logger.log(level="error", message=error_message)
except Exception:
print(error_message)

try:
auto_reply = pyttman.settings.MIDDLEWARE['FATAL_EXCEPTION_AUTO_REPLY']
except Exception:
auto_reply = "An internal error occurred in the application."
return Reply(f"{auto_reply} ({error_id})")


Expand Down

0 comments on commit b3fd307

Please sign in to comment.