From a9c8f9c49e64d0d2ddeb2be57008cfcb7af7aa29 Mon Sep 17 00:00:00 2001 From: Felix Becker Date: Fri, 30 Sep 2016 10:39:09 +0200 Subject: [PATCH] Improve exception in ProtocolStreamWriter::write() --- src/ProtocolStreamWriter.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ProtocolStreamWriter.php b/src/ProtocolStreamWriter.php index d32a9d3..2ac3579 100644 --- a/src/ProtocolStreamWriter.php +++ b/src/ProtocolStreamWriter.php @@ -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; }