Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ jobs:
os: >-
['ubuntu-latest', 'windows-latest']
php: >-
['8.1', '8.2', '8.3', '8.4', '8.5']
['8.1', '8.2', '8.3', '8.4', '8.5', '8.6']
2 changes: 1 addition & 1 deletion .github/workflows/composer-dependency-analyser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ jobs:
uses: yiisoft/actions/.github/workflows/composer-dependency-analyser.yml@master
with:
php: >-
['8.1', '8.2', '8.3', '8.4', '8.5']
['8.1', '8.2', '8.3', '8.4', '8.5', '8.6']
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
- Bug #164: Fix missing items in stack trace HTML output when handling a PHP error (@vjik)
- Bug #166: Fix broken link to error handling guide (@vjik)
- Bug #176: Remove unused `ext-dom` dependency (@samdark)
- Chg #170: Make all parameters of `ErrorException` constructor required (@vjik)
- New #171: Add `$traceFileMap` parameter to `HtmlRenderer` for mapping file paths in trace links (@WarLikeLaux)
- Enh #192: Add PHP 8.6 support (@roxblnfk)
- Bug #192: Escape cURL command in HTML debug output (@roxblnfk)

## 4.3.2 January 09, 2026

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ The package provides advanced error handling. The features are:

## Requirements

- PHP 8.1 - 8.5.
- PHP 8.1 - 8.6.
- `mbstring` PHP extension.

## Installation
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
}
],
"require": {
"php": "8.1 - 8.5",
"php": "8.1 - 8.6",
"ext-mbstring": "*",
"alexkart/curl-builder": "^1.0",
"cebe/markdown": "^1.2",
Expand All @@ -54,7 +54,7 @@
"rector/rector": "^2.1.3",
"shipmonk/composer-dependency-analyser": "^1.8",
"spatie/phpunit-watcher": "^1.24",
"vimeo/psalm": "^5.26.1 || ^6.13.1",
"vimeo/psalm": "^6.21 || ^7.20",
"yiisoft/di": "^1.4",
"yiisoft/test-support": "^3.0.2"
},
Expand Down
1 change: 1 addition & 0 deletions src/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
private readonly LoggerInterface $logger,
private readonly ThrowableRendererInterface $defaultRenderer,
private readonly ?EventDispatcherInterface $eventDispatcher = null,
private readonly int $exitShutdownHandlerDepth = 2,

Check warning on line 56 in src/ErrorHandler.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "IncrementInteger": @@ @@ * @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 ?EventDispatcherInterface $eventDispatcher = null, private readonly int $exitShutdownHandlerDepth = 2) + public function __construct(private readonly LoggerInterface $logger, private readonly ThrowableRendererInterface $defaultRenderer, private readonly ?EventDispatcherInterface $eventDispatcher = null, private readonly int $exitShutdownHandlerDepth = 3) { } /**

Check warning on line 56 in src/ErrorHandler.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "DecrementInteger": @@ @@ * @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 ?EventDispatcherInterface $eventDispatcher = null, private readonly int $exitShutdownHandlerDepth = 2) + public function __construct(private readonly LoggerInterface $logger, private readonly ThrowableRendererInterface $defaultRenderer, private readonly ?EventDispatcherInterface $eventDispatcher = null, private readonly int $exitShutdownHandlerDepth = 1) { } /**
) {}

/**
Expand All @@ -70,7 +70,7 @@
$renderer ??= $this->defaultRenderer;

try {
$this->logger->error($t->getMessage(), ['throwable' => $t]);

Check warning on line 73 in src/ErrorHandler.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "MethodCallRemoval": @@ @@ { $renderer ??= $this->defaultRenderer; try { - $this->logger->error($t->getMessage(), ['throwable' => $t]); + return $this->debug ? $renderer->renderVerbose($t, $request) : $renderer->render($t, $request); } catch (Throwable $t) { return new ErrorData((string) $t);

Check warning on line 73 in src/ErrorHandler.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "ArrayItemRemoval": @@ @@ { $renderer ??= $this->defaultRenderer; try { - $this->logger->error($t->getMessage(), ['throwable' => $t]); + $this->logger->error($t->getMessage(), []); return $this->debug ? $renderer->renderVerbose($t, $request) : $renderer->render($t, $request); } catch (Throwable $t) { return new ErrorData((string) $t);
return $this->debug ? $renderer->renderVerbose($t, $request) : $renderer->render($t, $request);
} catch (Throwable $t) {
return new ErrorData((string) $t);
Expand Down Expand Up @@ -110,14 +110,14 @@
return;
}

if ($this->memoryReserveSize > 0) {

Check warning on line 113 in src/ErrorHandler.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "GreaterThanNegotiation": @@ @@ if ($this->enabled) { return; } - if ($this->memoryReserveSize > 0) { + if ($this->memoryReserveSize <= 0) { $this->memoryReserve = str_repeat('x', $this->memoryReserveSize); } $this->initializeOnce();

Check warning on line 113 in src/ErrorHandler.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "GreaterThan": @@ @@ if ($this->enabled) { return; } - if ($this->memoryReserveSize > 0) { + if ($this->memoryReserveSize >= 0) { $this->memoryReserve = str_repeat('x', $this->memoryReserveSize); } $this->initializeOnce();
$this->memoryReserve = str_repeat('x', $this->memoryReserveSize);
}

$this->initializeOnce();

Check warning on line 117 in src/ErrorHandler.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "MethodCallRemoval": @@ @@ if ($this->memoryReserveSize > 0) { $this->memoryReserve = str_repeat('x', $this->memoryReserveSize); } - $this->initializeOnce(); + // Handles throwable that isn't caught otherwise, echo output and exit. set_exception_handler(function (Throwable $t): void { if (!$this->enabled) {

// Handles throwable that isn't caught otherwise, echo output and exit.
set_exception_handler(function (Throwable $t): void {

Check warning on line 120 in src/ErrorHandler.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "FunctionCallRemoval": @@ @@ $this->memoryReserve = str_repeat('x', $this->memoryReserveSize); } $this->initializeOnce(); - // Handles throwable that isn't caught otherwise, echo output and exit. - set_exception_handler(function (Throwable $t): void { - if (!$this->enabled) { - return; - } - $this->renderThrowableAndTerminate($t); - }); + // Handles PHP execution errors such as warnings and notices. set_error_handler(function (int $severity, string $message, string $file, int $line): bool { if (!$this->enabled) {
if (!$this->enabled) {
return;
}
Expand All @@ -131,12 +131,12 @@
return false;
}

if (!(error_reporting() & $severity)) {

Check warning on line 134 in src/ErrorHandler.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "BitwiseAnd": @@ @@ if (!$this->enabled) { return false; } - if (!(error_reporting() & $severity)) { + if (!(error_reporting() | $severity)) { // This error code is not included in error_reporting. return true; }
// This error code is not included in error_reporting.
return true;
}

$backtrace = debug_backtrace(0);

Check warning on line 139 in src/ErrorHandler.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "DecrementInteger": @@ @@ // This error code is not included in error_reporting. return true; } - $backtrace = debug_backtrace(0); + $backtrace = debug_backtrace(-1); if (!isset($backtrace[0]['file'])) { array_shift($backtrace); }
if (!isset($backtrace[0]['file'])) {
array_shift($backtrace);
}
Expand Down Expand Up @@ -220,6 +220,7 @@
// Set preventive HTTP status code to 500 in case error handling somehow fails and headers are sent.
http_response_code(Status::INTERNAL_SERVER_ERROR);

/** @psalm-suppress TaintedInput Escaping the output is the renderer's responsibility. */
echo $this->handle($t);
$this->eventDispatcher?->dispatch(new ApplicationError($t));

Expand Down
6 changes: 3 additions & 3 deletions src/Renderer/HtmlRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
use Yiisoft\ErrorHandler\ThrowableRendererInterface;
use Yiisoft\FriendlyException\FriendlyExceptionInterface;
use Yiisoft\Http\Header;
use ReflectionClass;
use ReflectionException;
use ReflectionFunction;
use ReflectionMethod;
use ReflectionObject;

use function array_values;
use function dirname;
Expand Down Expand Up @@ -583,7 +583,7 @@ public function removeAnonymous(string $value): string
*/
private function getThrowableDescription(Throwable $throwable): ?string
{
$docComment = (new ReflectionClass($throwable))->getDocComment();
$docComment = (new ReflectionObject($throwable))->getDocComment();
if ($docComment === false) {
return null;
}
Expand Down Expand Up @@ -701,7 +701,7 @@ private function renderTemplate(string $path, array $parameters): string
ob_implicit_flush(false);

try {
/** @psalm-suppress PossiblyNullFunctionCall */
/** @psalm-suppress PossiblyNullFunctionCall, TooManyArguments */
$renderer->bindTo($this)($path, $parameters);
return (string) ob_get_clean();
} catch (Throwable $e) {
Expand Down
4 changes: 2 additions & 2 deletions templates/development.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ class="copy-clipboard"
<?php endif ?>
<?php if ($request && ($curlInfo = $this->renderCurl($request)) !== 'curl'): ?>
<div class="request">
<textarea id="clipboard"><?= $curlInfo ?></textarea>
<textarea id="clipboard"><?= $this->htmlEncode($curlInfo) ?></textarea>
<span id="copied" style="top: 10px">Copied!</span>
<h2>cURL</h2>
<a href="#"
class="copy-clipboard"
data-clipboard="<?= $curlInfo ?>"
data-clipboard="<?= $this->htmlEncode($curlInfo) ?>"
title="Copy the cURL"
style="right: 10px; top: 5px"
>
Expand Down
8 changes: 7 additions & 1 deletion tests/Renderer/HtmlRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use function sprintf;

use const DIRECTORY_SEPARATOR;
use const PHP_VERSION_ID;

final class HtmlRendererTest extends TestCase
{
Expand Down Expand Up @@ -402,7 +403,12 @@ static function (int $code, string $message) use (&$errorMessage) {
restore_error_handler();

$this->assertSame('', $result);
$this->assertSame('file(not-exist): Failed to open stream: No such file or directory', $errorMessage);
$this->assertSame(
PHP_VERSION_ID >= 80600
? 'file(): Failed to open stream: No such file or directory'
: 'file(not-exist): Failed to open stream: No such file or directory',
$errorMessage,
);
}

public function testRenderCallStackWithErrorException(): void
Expand Down
Loading