From e85c7480e41e6f417d4207a4f68dd5a09b429a63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pontus=20M=C3=A5rdn=C3=A4s?= Date: Fri, 14 Jun 2019 12:50:36 +0200 Subject: [PATCH] Fix exception thrown in Monolog handler when extra data has numeric array keys (#834) --- CHANGELOG.md | 2 ++ src/Monolog/Handler.php | 2 +- tests/Monolog/HandlerTest.php | 25 +++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce43cc22b..ce2a8210d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- Fix `TypeError` in `Sentry\Monolog\Handler` when the extra data array has numeric keys (#833). + ## 2.1.1 (2019-06-13) - Fix the behavior of the `excluded_exceptions` option: now it's used to skip capture of exceptions, not to purge the diff --git a/src/Monolog/Handler.php b/src/Monolog/Handler.php index 40c646a35..d1a7ea1b3 100644 --- a/src/Monolog/Handler.php +++ b/src/Monolog/Handler.php @@ -59,7 +59,7 @@ protected function write(array $record): void if (isset($record['context']['extra']) && \is_array($record['context']['extra'])) { foreach ($record['context']['extra'] as $key => $value) { - $scope->setExtra($key, $value); + $scope->setExtra((string) $key, $value); } } diff --git a/tests/Monolog/HandlerTest.php b/tests/Monolog/HandlerTest.php index c065f9211..8b544b333 100644 --- a/tests/Monolog/HandlerTest.php +++ b/tests/Monolog/HandlerTest.php @@ -281,5 +281,30 @@ public function handleDataProvider(): \Generator 'bar.tag' => 'bar tag value', ], ]; + + yield [ + [ + 'message' => 'foo bar', + 'level' => Logger::INFO, + 'level_name' => Logger::getLevelName(Logger::INFO), + 'channel' => 'channel.foo', + 'context' => [ + 'extra' => [ + 1 => 'numeric key', + ], + ], + 'extra' => [], + ], + [ + 'level' => Severity::info(), + 'message' => 'foo bar', + ], + [ + 'monolog.channel' => 'channel.foo', + 'monolog.level' => Logger::getLevelName(Logger::INFO), + '1' => 'numeric key', + ], + [], + ]; } }