-
-
Notifications
You must be signed in to change notification settings - Fork 17
refactor error-handler #157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 3 commits
b89d1a5
272c885
b71c00d
6f7c6ca
714e586
a5b5d18
ddd497c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,16 +41,16 @@ | |
private bool $initialized = false; | ||
|
||
/** | ||
* @param LoggerInterface $logger Logger to write errors to. | ||
* @param ThrowableRendererInterface $defaultRenderer Default throwable renderer. | ||
* @param LoggerInterface|null $logger Logger to write errors to. | ||
* @param EventDispatcherInterface|null $eventDispatcher Event dispatcher for error events. | ||
* @param int $exitShutdownHandlerDepth Depth of the exit() shutdown handler to ensure it's executed last. | ||
*/ | ||
public function __construct( | ||
private readonly LoggerInterface $logger, | ||
private readonly ThrowableRendererInterface $defaultRenderer, | ||
private readonly ?LoggerInterface $logger = null, | ||
olegbaturin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
private readonly ?EventDispatcherInterface $eventDispatcher = null, | ||
private readonly int $exitShutdownHandlerDepth = 2 | ||
Check warning on line 53 in src/ErrorHandler.php
|
||
) { | ||
} | ||
|
||
|
@@ -68,7 +68,7 @@ | |
$renderer ??= $this->defaultRenderer; | ||
|
||
try { | ||
$this->logger->error($t->getMessage(), ['throwable' => $t]); | ||
$this->logger?->error($t->getMessage(), ['throwable' => $t]); | ||
Check warning on line 71 in src/ErrorHandler.php
|
||
return $this->debug ? $renderer->renderVerbose($t, $request) : $renderer->render($t, $request); | ||
} catch (Throwable $t) { | ||
return new ErrorData((string) $t); | ||
|
@@ -108,14 +108,14 @@ | |
return; | ||
} | ||
|
||
if ($this->memoryReserveSize > 0) { | ||
Check warning on line 111 in src/ErrorHandler.php
|
||
$this->memoryReserve = str_repeat('x', $this->memoryReserveSize); | ||
} | ||
|
||
$this->initializeOnce(); | ||
Check warning on line 115 in src/ErrorHandler.php
|
||
|
||
// Handles throwable that isn't caught otherwise, echo output and exit. | ||
set_exception_handler(function (Throwable $t): void { | ||
Check warning on line 118 in src/ErrorHandler.php
|
||
if (!$this->enabled) { | ||
return; | ||
} | ||
|
@@ -129,12 +129,12 @@ | |
return false; | ||
} | ||
|
||
if (!(error_reporting() & $severity)) { | ||
Check warning on line 132 in src/ErrorHandler.php
|
||
// This error code is not included in error_reporting. | ||
return true; | ||
} | ||
|
||
$backtrace = debug_backtrace(0); | ||
Check warning on line 137 in src/ErrorHandler.php
|
||
array_shift($backtrace); | ||
throw new ErrorException($message, $severity, $severity, $file, $line, null, $backtrace); | ||
}); | ||
|
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.