Skip to content

Commit c526aa3

Browse files
committed
fix: exclude deprecations from fatals
1 parent da77b49 commit c526aa3

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

‎src/Crash/Handler.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ public function register(): self
8282
return false;
8383
}
8484

85+
if ($severity === E_DEPRECATED || $severity === E_USER_DEPRECATED) {
86+
return false;
87+
}
88+
8589
throw new \ErrorException($message, 0, $severity, $file, $line);
8690
});
8791

‎tests/handler.test.php‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,25 @@ public function report(Report $report): void
7878
expect($decoded['error'])->toBe('internal');
7979
expect($decoded['id'])->toHaveLength(16);
8080
});
81+
82+
test('deprecations stay warnings instead of crashing the app', function () {
83+
$handler = (new Handler(new Hub(), ['debug' => true]))->register();
84+
$previous = error_reporting(E_ALL);
85+
86+
try {
87+
$thrown = null;
88+
89+
try {
90+
@trigger_error('old api', E_USER_DEPRECATED);
91+
trigger_error('old api', E_USER_DEPRECATED);
92+
} catch (ErrorException $e) {
93+
$thrown = $e;
94+
}
95+
96+
expect($thrown)->toBeNull();
97+
expect(fn () => trigger_error('real problem', E_USER_WARNING))->toThrow(ErrorException::class, 'real problem');
98+
} finally {
99+
error_reporting($previous);
100+
$handler->unregister();
101+
}
102+
});

0 commit comments

Comments
 (0)