Skip to content

Commit

Permalink
added Debugger::tryLog() [WIP]
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jul 27, 2024
1 parent 29b44a7 commit 50ca0fb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
16 changes: 12 additions & 4 deletions src/Tracy/Debugger/Debugger.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,7 @@ public static function exceptionHandler(\Throwable $exception): void
$handler($exception);
}
} catch (\Throwable $e) {
try {
self::log($e, self::EXCEPTION);
} catch (\Throwable) {
}
self::tryLog($e, self::EXCEPTION);
}
}

Expand Down Expand Up @@ -564,6 +561,17 @@ public static function log(mixed $message, string $level = ILogger::INFO): mixed
}


/** @internal */
public static function tryLog(mixed $message, string $level = ILogger::INFO): ?\Throwable
{
try {
self::log($message, $level);
} catch (\Throwable $e) {
}
return $e ?? null;
}


/** @internal */
public static function addSourceMapper(callable $mapper): void
{
Expand Down
14 changes: 4 additions & 10 deletions src/Tracy/Debugger/ProductionStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ public function initialize(): void

public function handleException(\Throwable $exception, bool $firstTime): void
{
try {
Debugger::log($exception, Debugger::EXCEPTION);
} catch (\Throwable $e) {
}
$e = Debugger::tryLog($exception, Debugger::EXCEPTION);

if (!$firstTime) {
// nothing
Expand All @@ -40,11 +37,11 @@ public function handleException(\Throwable $exception, bool $firstTime): void
header('Content-Type: text/html; charset=UTF-8');
}

(fn($logged) => require Debugger::$errorTemplate ?: __DIR__ . '/assets/error.500.phtml')(empty($e));
(fn($logged) => require Debugger::$errorTemplate ?: __DIR__ . '/assets/error.500.phtml')(!$e);

} elseif (Helpers::isCli() && is_resource(STDERR)) {
fwrite(STDERR, "ERROR: {$exception->getMessage()}\n"
. (isset($e)
. ($e
? 'Unable to log error. You may try enable debug mode to inspect the problem.'
: 'Check log to see more info.')
. "\n");
Expand All @@ -66,10 +63,7 @@ public function handleError(
$err = 'PHP ' . Helpers::errorTypeToString($severity) . ': ' . Helpers::improveError($message) . " in $file:$line";
}

try {
Debugger::log($err, Debugger::ERROR);
} catch (\Throwable $e) {
}
Debugger::tryLog($err, Debugger::ERROR);
}


Expand Down

0 comments on commit 50ca0fb

Please sign in to comment.