mirror of
https://github.com/danog/byte-stream.git
synced 2024-11-27 04:14:49 +01:00
Cleanup exceptions
This commit is contained in:
parent
458e4c68fd
commit
d29c100c9c
@ -2,4 +2,4 @@
|
||||
|
||||
namespace Amp\ByteStream;
|
||||
|
||||
class ClosedException extends \Exception {}
|
||||
class ClosedException extends StreamException {}
|
||||
|
@ -2,14 +2,14 @@
|
||||
|
||||
namespace Amp\ByteStream\Internal;
|
||||
|
||||
use Amp\ByteStream\{ ReadableStream, WritableStream };
|
||||
use Amp\ByteStream\{ ReadableStream, StreamException, WritableStream };
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
function pipe(ReadableStream $source, WritableStream $destination, int $bytes = null): \Generator {
|
||||
if (!$destination->isWritable()) {
|
||||
throw new \LogicException("The destination is not writable");
|
||||
throw new StreamException("The destination is not writable");
|
||||
}
|
||||
|
||||
if (null !== $bytes) {
|
||||
@ -24,7 +24,7 @@ function pipe(ReadableStream $source, WritableStream $destination, int $bytes =
|
||||
$written += yield $destination->write(
|
||||
yield $source->read()
|
||||
);
|
||||
} while ($source->isReadable() && $destination->isWritable());
|
||||
} while ($source->isReadable());
|
||||
|
||||
return $written;
|
||||
}
|
||||
|
@ -77,11 +77,11 @@ class MemoryStream implements DuplexStream {
|
||||
|
||||
private function fetch(int $bytes = null, string $delimiter = null): Promise {
|
||||
if ($bytes !== null && $bytes <= 0) {
|
||||
throw new \InvalidArgumentException("The number of bytes to read should be a positive integer or null");
|
||||
throw new \Error("The number of bytes to read should be a positive integer or null");
|
||||
}
|
||||
|
||||
if (!$this->readable) {
|
||||
return new Failure(new \LogicException("The stream has been closed"));
|
||||
return new Failure(new StreamException("The stream is not readable"));
|
||||
}
|
||||
|
||||
$deferred = new Deferred;
|
||||
@ -153,7 +153,7 @@ class MemoryStream implements DuplexStream {
|
||||
*/
|
||||
protected function send(string $data, bool $end = false): Promise {
|
||||
if (!$this->writable) {
|
||||
return new Failure(new \LogicException("The stream is not writable"));
|
||||
return new Failure(new StreamException("The stream is not writable"));
|
||||
}
|
||||
|
||||
if ($end) {
|
||||
|
5
lib/StreamException.php
Normal file
5
lib/StreamException.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Amp\ByteStream;
|
||||
|
||||
class StreamException extends \Exception {}
|
Loading…
Reference in New Issue
Block a user