Skip to content

Fix the Error Message - With an try catch #102

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
31 changes: 21 additions & 10 deletions src/EventLoop/Internal/AbstractDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ public function __construct()
// PHP GC is broken on early 8.1 and 8.2 versions, see https://github.com/php/php-src/issues/10496
/** @psalm-suppress RiskyTruthyFalsyComparison */
if (!\getenv('REVOLT_DRIVER_SUPPRESS_ISSUE_10496')) {
throw new \Error('Your version of PHP is affected by serious garbage collector bugs related to fibers. Please upgrade to a newer version of PHP, i.e. >= 8.1.17 or => 8.2.4');
throw new \Error(
'Your version of PHP is affected by serious garbage collector bugs related to fibers. Please upgrade to a newer version of PHP, i.e. >= 8.1.17 or => 8.2.4'
);
}
}

Expand Down Expand Up @@ -119,7 +121,7 @@ public function run(): void
$lambda();

throw new \Error(
'Interrupt from event loop must throw an exception: ' . ClosureHelper::getDescription($lambda)
'Interrupt from event loop must throw an exception: '.ClosureHelper::getDescription($lambda)
);
}
}
Expand Down Expand Up @@ -330,7 +332,7 @@ public function getErrorHandler(): ?\Closure
public function __debugInfo(): array
{
// @codeCoverageIgnoreStart
return \array_map(fn (DriverCallback $callback) => [
return \array_map(fn(DriverCallback $callback) => [
'type' => $this->getType($callback->id),
'enabled' => $callback->enabled,
'referenced' => $callback->referenced,
Expand Down Expand Up @@ -400,9 +402,10 @@ final protected function error(\Closure $closure, \Throwable $exception): void
{
if ($this->errorHandler === null) {
// Explicitly override the previous interrupt if it exists in this case, hiding the exception is worse
$this->interrupt = static fn () => $exception instanceof UncaughtThrowable
$this->interrupt = static fn() => $exception instanceof UncaughtThrowable
? throw $exception
: throw UncaughtThrowable::throwingCallback($closure, $exception);

return;
}

Expand Down Expand Up @@ -437,8 +440,12 @@ private function invokeMicrotasks(): void
unset($callback, $args);

if ($this->interrupt) {
/** @noinspection PhpUnhandledExceptionInspection */
\Fiber::suspend($this->internalSuspensionMarker);
try {
/** @noinspection PhpUnhandledExceptionInspection */
\Fiber::suspend($this->internalSuspensionMarker);
} catch (\Throwable) {
return;
}
}
}
}
Expand Down Expand Up @@ -622,7 +629,11 @@ private function createCallbackFiber(): void
}

/** @noinspection PhpUnhandledExceptionInspection */
\Fiber::suspend($this->internalSuspensionMarker);
try {
\Fiber::suspend($this->internalSuspensionMarker);
} catch (\Throwable) {
return;
}
} while (true);
});
}
Expand All @@ -633,7 +644,7 @@ private function createErrorCallback(): void
try {
$errorHandler($exception);
} catch (\Throwable $exception) {
$this->interrupt = static fn () => $exception instanceof UncaughtThrowable
$this->interrupt = static fn() => $exception instanceof UncaughtThrowable
? throw $exception
: throw UncaughtThrowable::throwingErrorHandler($errorHandler, $exception);
}
Expand All @@ -642,11 +653,11 @@ private function createErrorCallback(): void

final public function __serialize(): never
{
throw new \Error(__CLASS__ . ' does not support serialization');
throw new \Error(__CLASS__.' does not support serialization');
}

final public function __unserialize(array $data): never
{
throw new \Error(__CLASS__ . ' does not support deserialization');
throw new \Error(__CLASS__.' does not support deserialization');
}
}
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy