Skip to content
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

Do not interfere with errors that were suppressed by the @ operator. #388

Merged
merged 1 commit into from
Feb 1, 2024
Merged
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
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';
Loading