Skip to content

Commit 3eb342d

Browse files
committed
Only report write error when write fails with error and nothing written
1 parent 6385382 commit 3eb342d

File tree

1 file changed

+6
-20
lines changed

1 file changed

+6
-20
lines changed

src/WritableResourceStream.php

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,8 @@ public function close()
113113
public function handleWrite()
114114
{
115115
$error = null;
116-
\set_error_handler(function ($errno, $errstr, $errfile, $errline) use (&$error) {
117-
$error = array(
118-
'message' => $errstr,
119-
'number' => $errno,
120-
'file' => $errfile,
121-
'line' => $errline
122-
);
116+
\set_error_handler(function ($_, $errstr) use (&$error) {
117+
$error = $errstr;
123118
});
124119

125120
if ($this->writeChunkSize === -1) {
@@ -130,25 +125,16 @@ public function handleWrite()
130125

131126
\restore_error_handler();
132127

133-
// Only report errors if *nothing* could be sent.
128+
// Only report errors if *nothing* could be sent and an error has been raised.
129+
// Ignore non-fatal warnings if *some* data could be sent.
134130
// Any hard (permanent) error will fail to send any data at all.
135131
// Sending excessive amounts of data will only flush *some* data and then
136132
// report a temporary error (EAGAIN) which we do not raise here in order
137133
// to keep the stream open for further tries to write.
138134
// Should this turn out to be a permanent error later, it will eventually
139135
// send *nothing* and we can detect this.
140-
if ($sent === 0 || $sent === false) {
141-
if ($error !== null) {
142-
$error = new \ErrorException(
143-
$error['message'],
144-
0,
145-
$error['number'],
146-
$error['file'],
147-
$error['line']
148-
);
149-
}
150-
151-
$this->emit('error', array(new \RuntimeException('Unable to write to stream: ' . ($error !== null ? $error->getMessage() : 'Unknown error'), 0, $error)));
136+
if (($sent === 0 || $sent === false) && $error !== null) {
137+
$this->emit('error', array(new \RuntimeException('Unable to write to stream: ' . $error)));
152138
$this->close();
153139

154140
return;

0 commit comments

Comments
 (0)