Improve exception in ProtocolStreamWriter::write()
parent
9f6cf32e5d
commit
a9c8f9c49e
|
@ -4,6 +4,7 @@ declare(strict_types = 1);
|
|||
namespace LanguageServer;
|
||||
|
||||
use LanguageServer\Protocol\Message;
|
||||
use RuntimeException;
|
||||
|
||||
class ProtocolStreamWriter implements ProtocolWriter
|
||||
{
|
||||
|
@ -30,9 +31,15 @@ class ProtocolStreamWriter implements ProtocolWriter
|
|||
$totalBytesWritten = 0;
|
||||
|
||||
while ($totalBytesWritten < $msgSize) {
|
||||
error_clear_last();
|
||||
$bytesWritten = @fwrite($this->output, substr($data, $totalBytesWritten));
|
||||
if ($bytesWritten === false) {
|
||||
throw new Exception('Could not write message.');
|
||||
$error = error_get_last();
|
||||
if ($error !== null) {
|
||||
throw new RuntimeException('Could not write message: ' . error_get_last()['message']);
|
||||
} else {
|
||||
throw new RuntimeException('Could not write message');
|
||||
}
|
||||
}
|
||||
$totalBytesWritten += $bytesWritten;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue