1
0
mirror of https://github.com/danog/byte-stream.git synced 2024-11-26 20:04:51 +01:00

Throw new exception carrying $chunk when fwrite returns 0

This commit is contained in:
Gabriel Ostrolucký 2019-03-05 00:07:22 +01:00
parent 6bbfcb6f47
commit eb4d03504d
No known key found for this signature in database
GPG Key ID: 0B618B95BA22CEEF
2 changed files with 24 additions and 1 deletions

View File

@ -0,0 +1,23 @@
<?php
namespace Amp\ByteStream;
final class CannotWriteChunkException extends StreamException
{
/**
* @var string
*/
private $chunk;
public function __construct(string $chunk, string $message = "", int $code = 0, \Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
$this->chunk = $chunk;
}
public function getChunk(): string
{
return $this->chunk;
}
}

View File

@ -92,7 +92,7 @@ final class ResourceOutputStream implements OutputStream
if ($error = \error_get_last()) {
$message .= \sprintf("; %s", $error["message"]);
}
throw new StreamException($message);
throw new CannotWriteChunkException($data, $message);
}
$writes->unshift([$data, $previous, $deferred]);