From 47908f8e8bb2da8af4e59028200758477bc927ea Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Fri, 26 Jul 2019 16:22:49 -0500 Subject: [PATCH] Return Failure instead of throwing Closure should fail returned promise, not throw directly from method call. --- lib/OutputStream.php | 2 ++ lib/ResourceOutputStream.php | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/OutputStream.php b/lib/OutputStream.php index e3a6d1d..68f51fc 100644 --- a/lib/OutputStream.php +++ b/lib/OutputStream.php @@ -17,6 +17,7 @@ interface OutputStream * @return Promise Succeeds once the data has been successfully written to the stream. * * @throws ClosedException If the stream has already been closed. + * @throws StreamException If writing to the stream fails. */ public function write(string $data): Promise; @@ -30,6 +31,7 @@ interface OutputStream * @return Promise Succeeds once the data has been successfully written to the stream. * * @throws ClosedException If the stream has already been closed. + * @throws StreamException If writing to the stream fails. */ public function end(string $finalData = ""): Promise; } diff --git a/lib/ResourceOutputStream.php b/lib/ResourceOutputStream.php index e70f5bd..dea2b1a 100644 --- a/lib/ResourceOutputStream.php +++ b/lib/ResourceOutputStream.php @@ -72,7 +72,7 @@ final class ResourceOutputStream implements OutputStream } if (!\is_resource($stream) || (($metaData = @\stream_get_meta_data($stream)) && $metaData['eof'])) { - throw new StreamException("The stream was closed by the peer"); + throw new ClosedException("The stream was closed by the peer"); } // Error reporting suppressed since fwrite() emits E_WARNING if the pipe is broken or the buffer is full. @@ -180,7 +180,7 @@ final class ResourceOutputStream implements OutputStream } if (!\is_resource($this->resource) || (($metaData = @\stream_get_meta_data($this->resource)) && $metaData['eof'])) { - throw new StreamException("The stream was closed by the peer"); + return new Failure(new ClosedException("The stream was closed by the peer")); } // Error reporting suppressed since fwrite() emits E_WARNING if the pipe is broken or the buffer is full.