Skip to content

Commit

Permalink
Fix exception thrown in Monolog handler when extra data has numeric a…
Browse files Browse the repository at this point in the history
…rray keys (#834)
  • Loading branch information
pontus-mp authored and ste93cry committed Jun 14, 2019
1 parent 50f5893 commit e85c748
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Monolog/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
25 changes: 25 additions & 0 deletions tests/Monolog/HandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
[],
];
}
}

0 comments on commit e85c748

Please sign in to comment.