Skip to content

fix: ignore non-object exception context in GroupExceptionsProcessor - #28

Open
artem-yakymchuk-paysera wants to merge 1 commit into
paysera:masterfrom
artem-yakymchuk-paysera:fix/group-exceptions-non-object-context
Open

fix: ignore non-object exception context in GroupExceptionsProcessor#28
artem-yakymchuk-paysera wants to merge 1 commit into
paysera:masterfrom
artem-yakymchuk-paysera:fix/group-exceptions-non-object-context

Conversation

@artem-yakymchuk-paysera

Copy link
Copy Markdown

Problem

GroupExceptionsProcessor (tagged monolog.processor for the Sentry handler, which runs at ERROR level in our services) calls get_class($record->context['exception']) with no guard. Any log call that passes a non-object there — e.g. $logger->error('...', ['exception' => $e->getMessage()]), a string — throws a TypeError from inside the logger call, and since Monolog installs no exception handler it propagates to the caller. In one consumer this crashed whole Kafka batch processing runs.

Fix

Ignore non-object context['exception'] values in both class variants (Monolog v3 and v1/v2): the record passes through unchanged and no Sentry fingerprint grouping is applied. Grouping behaviour for real Throwables is unchanged.

Tests

New GroupExceptionsProcessorTest (uses the shared MonologRecordTrait, so it covers both Monolog branches across the CI matrix):

  • string exception context → record unchanged, no throw, no fingerprint
  • grouped Throwable → fingerprint still set
  • ungrouped Throwable → no fingerprint
  • no exception context → untouched

Full suite: 142 tests OK locally (PHP 8.2, Monolog v3).

Changelog entry added under 3.5.1.

🤖 Generated with Claude Code

https://claude.ai/code/session_012cBCgqnh2hwmR74Ngw8TEi

get_class() was called on context['exception'] unguarded, so any
logger call passing a string there (e.g. ['exception' => $e->getMessage()])
threw a TypeError from inside the logging call and the exception
propagated to the caller. Non-object values are now ignored: the record
passes through unchanged and no Sentry fingerprint grouping is applied.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012cBCgqnh2hwmR74Ngw8TEi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants