Exception logging writes to the database, so DB outages are recorded nowhere #166

Closed
opened 2026-09-26 08:53:16 +02:00 by myrmidex · 1 comment
Owner

LogExceptionToDatabase::handle() persists every exception via Log::create(). When the database is the thing that failed, the insert fails identically and the exception is lost.

During #164 the only surviving output was the wrapper from app/Listeners/LogExceptionToDatabase.php:35:

Failed to log exception to database: SQLSTATE[HY000] [2002] ... (SQL: insert into `logs` ...)

The message names the failed insert, not the original error. The real cause — a QueryException from SessionGuard::userFromRecaller() during auth — was only recoverable because the nested exception text happened to embed it. Diagnosis depended on that accident.

The existing comment at line 34 already flags the gap:

// Optionally log to file or other non-database destination

Fix

In the catch block, write the original exception through Laravel's file/stderr logger (Log::channel(...)) rather than only error_log() with the wrapper message. Preserve exception class, file, line and trace.

Tests

  • Unit test that when Log::create() throws, the original exception's details reach the fallback channel
`LogExceptionToDatabase::handle()` persists every exception via `Log::create()`. When the database is the thing that failed, the insert fails identically and the exception is lost. During #164 the only surviving output was the wrapper from `app/Listeners/LogExceptionToDatabase.php:35`: ``` Failed to log exception to database: SQLSTATE[HY000] [2002] ... (SQL: insert into `logs` ...) ``` The message names the *failed insert*, not the original error. The real cause — a `QueryException` from `SessionGuard::userFromRecaller()` during auth — was only recoverable because the nested exception text happened to embed it. Diagnosis depended on that accident. The existing comment at line 34 already flags the gap: ```php // Optionally log to file or other non-database destination ``` ## Fix In the catch block, write the original exception through Laravel's file/stderr logger (`Log::channel(...)`) rather than only `error_log()` with the wrapper message. Preserve exception class, file, line and trace. ## Tests - Unit test that when `Log::create()` throws, the original exception's details reach the fallback channel
myrmidex added this to the v1.4.3 milestone 2026-09-26 08:53:16 +02:00
myrmidex added the
bug
label 2026-09-26 08:53:16 +02:00
myrmidex self-assigned this 2026-09-26 08:53:16 +02:00
Author
Owner

Superseded by #164, which now covers the exception-logging fallback along with the healthcheck fix and the startup/Horizon supervision defects from the same incident. Consolidating to keep the work in one ticket.

Superseded by #164, which now covers the exception-logging fallback along with the healthcheck fix and the startup/Horizon supervision defects from the same incident. Consolidating to keep the work in one ticket.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: lvl0/fedi-feed-router#166
No description provided.