diff --git a/lib/BlockingHandle.php b/lib/BlockingHandle.php index e585fd2..396d8c4 100644 --- a/lib/BlockingHandle.php +++ b/lib/BlockingHandle.php @@ -31,7 +31,7 @@ class BlockingHandle implements Handle { */ public function read(int $length = self::DEFAULT_READ_LENGTH): Promise { if ($this->fh === null) { - throw new \Error("The file has been closed"); + throw new FilesystemException("The file has been closed"); } $data = \fread($this->fh, $length); @@ -49,7 +49,7 @@ class BlockingHandle implements Handle { */ public function write(string $data): Promise { if ($this->fh === null) { - throw new \Error("The file has been closed"); + throw new FilesystemException("The file has been closed"); } $len = \fwrite($this->fh, $data); @@ -76,13 +76,13 @@ class BlockingHandle implements Handle { */ public function close(): Promise { if ($this->fh === null) { - throw new \Error("The file has already been closed"); + throw new FilesystemException("The file has already been closed"); } $fh = $this->fh; $this->fh = null; - if (\fclose($fh)) { + if (@\fclose($fh)) { return new Success; } else { return new Failure(new FilesystemException( @@ -96,7 +96,7 @@ class BlockingHandle implements Handle { */ public function seek(int $position, int $whence = \SEEK_SET): Promise { if ($this->fh === null) { - throw new \Error("The file has been closed"); + throw new FilesystemException("The file has been closed"); } switch ($whence) { @@ -119,7 +119,7 @@ class BlockingHandle implements Handle { */ public function tell(): int { if ($this->fh === null) { - throw new \Error("The file has been closed"); + throw new FilesystemException("The file has been closed"); } return \ftell($this->fh); @@ -130,7 +130,7 @@ class BlockingHandle implements Handle { */ public function eof(): bool { if ($this->fh === null) { - throw new \Error("The file has been closed"); + throw new FilesystemException("The file has been closed"); } return \feof($this->fh); diff --git a/lib/ParallelHandle.php b/lib/ParallelHandle.php index ed32a4f..000e3f7 100644 --- a/lib/ParallelHandle.php +++ b/lib/ParallelHandle.php @@ -80,7 +80,7 @@ class ParallelHandle implements Handle { public function read(int $length = self::DEFAULT_READ_LENGTH): Promise { if ($this->id === null) { - throw new \Error("The file has been closed"); + throw new FilesystemException("The file has been closed"); } return new Coroutine($this->doRead($length)); @@ -105,7 +105,7 @@ class ParallelHandle implements Handle { */ public function write(string $data): Promise { if ($this->id === null) { - throw new \Error("The file has been closed"); + throw new FilesystemException("The file has been closed"); } return new Coroutine($this->doWrite($data)); @@ -143,7 +143,7 @@ class ParallelHandle implements Handle { */ public function seek(int $offset, int $whence = SEEK_SET): Promise { if ($this->id === null) { - throw new \Error("The file has been closed"); + throw new FilesystemException("The file has been closed"); } return new Coroutine($this->doSeek($offset, $whence)); diff --git a/test/HandleTest.php b/test/HandleTest.php index 4dce8d9..304d6d8 100644 --- a/test/HandleTest.php +++ b/test/HandleTest.php @@ -144,10 +144,14 @@ abstract class HandleTest extends TestCase { }); } + /** + * @expectedException \Amp\File\FilesystemException + */ public function testClose() { $this->execute(function () { $handle = yield File\open(__FILE__, "r"); yield $handle->close(); + yield $handle->read(); }); } }