Skip to content

Commit

Permalink
Do not interfere with errors that were suppressed by the @ operator.
Browse files Browse the repository at this point in the history
  • Loading branch information
maciej committed Sep 25, 2023
1 parent 73b8abb commit 5131c41
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Ignition.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,12 @@ public function renderError(
int $line = 0,
array $context = []
): void {
if(error_reporting() === (E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR | E_PARSE)) {
// This happens when PHP version is >=8 and we caught an error that was suppressed with the "@" operator
// See the first warning box in https://www.php.net/manual/en/language.operators.errorcontrol.php
return;
}

throw new ErrorException($message, 0, $level, $file, $line);
}

Expand Down
12 changes: 12 additions & 0 deletions tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@
expect($output)->toEqual('ok');
});

it('can render the error page for unsuppressed errors', function () {
$output = getOutputOfApp('unsuppressed-error.php');

expect($output)->toContain('window.ignite');
});

it('will not render if an error was explicitly suppressed', function () {
$output = getOutputOfApp('suppressed-error.php');

expect($output)->toEqual('ok');
});

it('can show a solution', function () {
$output = getOutputOfApp('exception-with-solution.php');

Expand Down
11 changes: 11 additions & 0 deletions tests/stubs/apps/suppressed-error.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

use Spatie\Ignition\Ignition;

include('../../../vendor/autoload.php');

Ignition::make()->register();

@include('./file-not-found.txt');

echo 'ok';
11 changes: 11 additions & 0 deletions tests/stubs/apps/unsuppressed-error.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

use Spatie\Ignition\Ignition;

include('../../../vendor/autoload.php');

Ignition::make()->register();

include('./file-not-found.txt');

echo 'ok';

0 comments on commit 5131c41

Please sign in to comment.