From b237a0e1ab2586f593def1e00d65626f8dc9fef7 Mon Sep 17 00:00:00 2001 From: Kurt Thiemann Date: Thu, 6 Mar 2025 14:17:09 +0100 Subject: [PATCH] Use StdStreams instead of STDERR constant for error output --- src/Proxy/ProxyRuntime.php | 5 +++-- src/Runtime/SocketRuntime.php | 5 +++-- src/Task/Task.php | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Proxy/ProxyRuntime.php b/src/Proxy/ProxyRuntime.php index 1d1da43..d40fdf1 100644 --- a/src/Proxy/ProxyRuntime.php +++ b/src/Proxy/ProxyRuntime.php @@ -12,6 +12,7 @@ use Aternos\Taskmaster\Communication\Socket\Exception\SocketWriteException; use Aternos\Taskmaster\Communication\Socket\SelectableSocketInterface; use Aternos\Taskmaster\Communication\Socket\SocketCommunicatorTrait; +use Aternos\Taskmaster\Communication\StdStreams; use Aternos\Taskmaster\Runtime\AsyncRuntimeInterface; use Aternos\Taskmaster\Taskmaster; use Aternos\Taskmaster\Worker\Instance\ProxyableWorkerInstanceInterface; @@ -244,7 +245,7 @@ protected function handleFail(null|string|Exception $reason = null): static if ($reason instanceof Exception) { $reason = $reason->getMessage(); } - fwrite(STDERR, "Proxy runtime failed: " . $reason . PHP_EOL); + fwrite(StdStreams::getInstance()->getStderr(), "Proxy runtime failed: " . $reason . PHP_EOL); exit(1); } -} \ No newline at end of file +} diff --git a/src/Runtime/SocketRuntime.php b/src/Runtime/SocketRuntime.php index 7ed1350..33be369 100644 --- a/src/Runtime/SocketRuntime.php +++ b/src/Runtime/SocketRuntime.php @@ -8,6 +8,7 @@ use Aternos\Taskmaster\Communication\Socket\Socket; use Aternos\Taskmaster\Communication\Socket\SocketCommunicatorTrait; use Aternos\Taskmaster\Communication\Socket\SocketInterface; +use Aternos\Taskmaster\Communication\StdStreams; use Aternos\Taskmaster\Exception\PhpError; use Aternos\Taskmaster\Exception\PhpFatalErrorException; use Aternos\Taskmaster\Taskmaster; @@ -102,7 +103,7 @@ protected function handleFail(null|string|Exception $reason = null): static if ($reason instanceof Exception) { $reason = $reason->getMessage(); } - fwrite(STDERR, "Runtime failed: " . $reason . PHP_EOL); + fwrite(StdStreams::getInstance()->getStderr(), "Runtime failed: " . $reason . PHP_EOL); exit(1); } -} \ No newline at end of file +} diff --git a/src/Task/Task.php b/src/Task/Task.php index 0d1ea71..33d5e0d 100644 --- a/src/Task/Task.php +++ b/src/Task/Task.php @@ -6,6 +6,7 @@ use Aternos\Taskmaster\Communication\Promise\TaskPromise; use Aternos\Taskmaster\Communication\Request\ExecuteFunctionRequest; use Aternos\Taskmaster\Communication\ResponseInterface; +use Aternos\Taskmaster\Communication\StdStreams; use Aternos\Taskmaster\Exception\PhpError; use Aternos\Taskmaster\Runtime\RuntimeInterface; use Closure; @@ -175,7 +176,7 @@ public function handleResult(mixed $result): void public function handleError(Exception $error): void { $this->error = $error; - fwrite(STDERR, $error->getMessage() . PHP_EOL); + fwrite(StdStreams::getInstance()->getStderr(), $error->getMessage() . PHP_EOL); } /** @@ -287,4 +288,4 @@ protected function isSync(): bool { return $this->sync; } -} \ No newline at end of file +}