Replies: 2 comments
-
If you setup the reports to ignore RecordsNotFoundException and then you say don't ignore a child of those, the behavior seems ok. A merge between the 2 options could be done but it needs refactoring the logic of dontReport by adding an extra stopIgnoring public function stopIgnoring(array|string $exceptions)
{
$exceptions = Arr::wrap($exceptions);
$this->stopIgnoring = \array_unique(\array_merge($this->stopIgnoring, exceptions)); // new line
$this->dontReport = collect($this->dontReport)
->reject(fn ($ignored) => in_array($ignored, $exceptions))->values()->all();
$this->internalDontReport = collect($this->internalDontReport)
->reject(fn ($ignored) => in_array($ignored, $exceptions))->values()->all();
return $this;
} and then in \Illuminate\Foundation\Exceptions\Handler::shouldntReport $dontReport = array_merge($this->dontReport, $this->internalDontReport);
if (! is_null(Arr::first($dontReport, fn ($type) => $e instanceof $type))) {
return true;
} should be converted into $dontReport = array_merge($this->dontReport, $this->internalDontReport);
if (! is_null(Arr::first($dontReport, fn (string $type): bool => !\in_array($e::class, $this->stopIgnoring, true) && $e instanceof $type))) {
return true;
} |
Beta Was this translation helpful? Give feedback.
-
This seems to be a breaking change request. Moving to Ideas |
Beta Was this translation helpful? Give feedback.
-
Laravel Version
11.40
PHP Version
8.3.14
Database Driver & Version
n/a
Description
Problem
When
Exceptions::stopIgnoring(ModelNotFoundException::class)
is called Laravel will continue to ignore model not found exceptions. This appears to be becauseModelNotFoundException
extendsRecordsNotFoundException
which also on the ignore list. When checking whether to ignore an exception Laravel usesinstanceof
which will returntrue
.This will also happen for other exception types if their parent is on the ignore list.
How to fix this
I think there two (non-breaking) ways to address this:
Exceptions::forceReport($e)
orExceptions::withoutIgnoring()->report($e)
)Exceptions::stopIgnoring(...)
Steps To Reproduce
This should return
true
but returnsfalse
Beta Was this translation helpful? Give feedback.
All reactions