1
0
Fork 0

Improve exception in ProtocolStreamWriter::write()

pull/31/head
Felix Becker 2016-09-30 10:39:09 +02:00
parent 9f6cf32e5d
commit a9c8f9c49e
1 changed files with 8 additions and 1 deletions

View File

@ -4,6 +4,7 @@ declare(strict_types = 1);
namespace LanguageServer; namespace LanguageServer;
use LanguageServer\Protocol\Message; use LanguageServer\Protocol\Message;
use RuntimeException;
class ProtocolStreamWriter implements ProtocolWriter class ProtocolStreamWriter implements ProtocolWriter
{ {
@ -30,9 +31,15 @@ class ProtocolStreamWriter implements ProtocolWriter
$totalBytesWritten = 0; $totalBytesWritten = 0;
while ($totalBytesWritten < $msgSize) { while ($totalBytesWritten < $msgSize) {
error_clear_last();
$bytesWritten = @fwrite($this->output, substr($data, $totalBytesWritten)); $bytesWritten = @fwrite($this->output, substr($data, $totalBytesWritten));
if ($bytesWritten === false) { 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; $totalBytesWritten += $bytesWritten;
} }