Skip to content

Commit

Permalink
Remove empty lines if a custom stack trace parser returns null, fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Dec 5, 2024
1 parent 5958473 commit 0745038
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Monolog/Formatter/LineFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,6 @@ private function stacktracesParser(\Throwable $e): string

private function stacktracesParserCustom(string $trace): string
{
return implode("\n", array_filter(array_map($this->stacktracesParser, explode("\n", $trace)), fn ($line) => $line !== false && $line !== ''));
return implode("\n", array_filter(array_map($this->stacktracesParser, explode("\n", $trace)), fn ($line) => is_string($line) && trim($line) !== ''));
}
}
3 changes: 1 addition & 2 deletions tests/Monolog/Formatter/LineFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,9 @@ public function testDefFormatWithExceptionAndStacktraceParserEmpty()
});

$message = $formatter->format($this->getRecord(Level::Critical, context: ['exception' => new \RuntimeException('Foo')]));

$trace = explode('[stacktrace]', $message, 2)[1];

$this->assertStringNotContainsString('#', $trace);
$this->assertSame(PHP_EOL . PHP_EOL . '"} []' . PHP_EOL, $trace);
}

public function testDefFormatWithPreviousException()
Expand Down

0 comments on commit 0745038

Please sign in to comment.