Skip to content

Commit 6b41ea0

Browse files
committed
Only emit error event for fatal errors
1 parent f4d90ca commit 6b41ea0

3 files changed

Lines changed: 52 additions & 54 deletions

File tree

README.md

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ stream.
124124

125125
#### error event
126126

127-
The `error` event will be emitted whenever an error occurs, usually while
127+
The `error` event will be emitted once a fatal error occurs, usually while
128128
trying to read from this stream.
129129
The event receives a single `Exception` argument for the error instance.
130130

@@ -134,23 +134,23 @@ $server->on('error', function (Exception $e) {
134134
});
135135
```
136136

137-
This event MAY be emitted any number of times, which should be zero
138-
times if this is a stream that is successfully terminated.
139-
It SHOULD be emitted whenever the stream detects an error, such as a
140-
transmission error or after an unexpected `data` or premature `end` event.
141-
It SHOULD NOT be emitted after a `close` event.
137+
This event SHOULD be emitted once the stream detects a fatal error, such
138+
as a fatal transmission error or after an unexpected `data` or premature
139+
`end` event.
140+
It SHOULD NOT be emitted after a previous `error`, `end` or `close` event.
141+
It MUST NOT be emitted if this is not a fatal error condition, such as
142+
a temporary network issue that did not cause any data to be lost.
143+
144+
After the stream errors, it MUST close the stream and SHOULD thus be
145+
followed by a `close` event and then switch to non-readable mode, see
146+
also `close()` and `isReadable()`.
142147

143148
Many common streams (such as a TCP/IP connection or a file-based stream)
144149
only deal with data transmission and do not make assumption about data
145150
boundaries (such as unexpected `data` or premature `end` events).
146151
In other words, many lower-level protocols (such as TCP/IP) may choose
147-
to only emit this for a fatal transmission error once and will thus
148-
likely close (terminate) the stream in response.
149-
If this is a fatal error that results in the stream being closed, it
150-
SHOULD be followed by a `close` event.
151-
152-
Other higher-level protocols may choose to keep the stream alive after
153-
this event, if they can recover from an error condition.
152+
to only emit this for a fatal transmission error once and will then
153+
close (terminate) the stream in response.
154154

155155
If this stream is a `DuplexStreamInterface`, you should also notice
156156
how the writable side of the stream also implements an `error` event.
@@ -177,7 +177,7 @@ see also `isReadable()`.
177177
Unlike the `end` event, this event SHOULD be emitted whenever the stream
178178
closes, irrespective of whether this happens implicitly due to an
179179
unrecoverable error or explicitly when either side closes the stream.
180-
If you only want to detect a *succesful* end, you should use the `end`
180+
If you only want to detect a *successful* end, you should use the `end`
181181
event instead.
182182

183183
Many common streams (such as a TCP/IP connection or a file-based stream)
@@ -434,7 +434,7 @@ This event is mostly used internally, see also `pipe()` for more details.
434434

435435
#### error event
436436

437-
The `error` event will be emitted whenever an error occurs, usually while
437+
The `error` event will be emitted once a fatal error occurs, usually while
438438
trying to write to this stream.
439439
The event receives a single `Exception` argument for the error instance.
440440

@@ -444,21 +444,20 @@ $stream->on('error', function (Exception $e) {
444444
});
445445
```
446446

447-
This event MAY be emitted any number of times, which should be zero
448-
times if this is a stream that is successfully terminated.
449-
It SHOULD be emitted whenever the stream detects an error, such as a
450-
transmission error.
451-
It SHOULD NOT be emitted after a `close` event.
447+
This event SHOULD be emitted once the stream detects a fatal error, such
448+
as a fatal transmission error.
449+
It SHOULD NOT be emitted after a previous `error` or `close` event.
450+
It MUST NOT be emitted if this is not a fatal error condition, such as
451+
a temporary network issue that did not cause any data to be lost.
452+
453+
After the stream errors, it MUST close the stream and SHOULD thus be
454+
followed by a `close` event and then switch to non-writable mode, see
455+
also `close()` and `isWritable()`.
452456

453457
Many common streams (such as a TCP/IP connection or a file-based stream)
454458
only deal with data transmission and may choose
455-
to only emit this for a fatal transmission error once and will thus
456-
likely close (terminate) the stream in response.
457-
If this is a fatal error that results in the stream being closed, it
458-
SHOULD be followed by a `close` event.
459-
460-
Other higher-level protocols may choose to keep the stream alive after
461-
this event, if they can recover from an error condition.
459+
to only emit this for a fatal transmission error once and will then
460+
close (terminate) the stream in response.
462461

463462
If this stream is a `DuplexStreamInterface`, you should also notice
464463
how the readable side of the stream also implements an `error` event.

src/ReadableStreamInterface.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
* stream.
8080
*
8181
* error event:
82-
* The `error` event will be emitted whenever an error occurs, usually while
82+
* The `error` event will be emitted once a fatal error occurs, usually while
8383
* trying to read from this stream.
8484
* The event receives a single `Exception` argument for the error instance.
8585
*
@@ -89,23 +89,23 @@
8989
* });
9090
* ```
9191
*
92-
* This event MAY be emitted any number of times, which should be zero
93-
* times if this is a stream that is successfully terminated.
94-
* It SHOULD be emitted whenever the stream detects an error, such as a
95-
* transmission error or after an unexpected `data` or premature `end` event.
96-
* It SHOULD NOT be emitted after a `close` event.
92+
* This event SHOULD be emitted once the stream detects a fatal error, such
93+
* as a fatal transmission error or after an unexpected `data` or premature
94+
* `end` event.
95+
* It SHOULD NOT be emitted after a previous `error`, `end` or `close` event.
96+
* It MUST NOT be emitted if this is not a fatal error condition, such as
97+
* a temporary network issue that did not cause any data to be lost.
98+
*
99+
* After the stream errors, it MUST close the stream and SHOULD thus be
100+
* followed by a `close` event and then switch to non-readable mode, see
101+
* also `close()` and `isReadable()`.
97102
*
98103
* Many common streams (such as a TCP/IP connection or a file-based stream)
99104
* only deal with data transmission and do not make assumption about data
100105
* boundaries (such as unexpected `data` or premature `end` events).
101106
* In other words, many lower-level protocols (such as TCP/IP) may choose
102-
* to only emit this for a fatal transmission error once and will thus
103-
* likely close (terminate) the stream in response.
104-
* If this is a fatal error that results in the stream being closed, it
105-
* SHOULD be followed by a `close` event.
106-
*
107-
* Other higher-level protocols may choose to keep the stream alive after
108-
* this event, if they can recover from an error condition.
107+
* to only emit this for a fatal transmission error once and will then
108+
* close (terminate) the stream in response.
109109
*
110110
* If this stream is a `DuplexStreamInterface`, you should also notice
111111
* how the writable side of the stream also implements an `error` event.
@@ -131,7 +131,7 @@
131131
* Unlike the `end` event, this event SHOULD be emitted whenever the stream
132132
* closes, irrespective of whether this happens implicitly due to an
133133
* unrecoverable error or explicitly when either side closes the stream.
134-
* If you only want to detect a *succesful* end, you should use the `end`
134+
* If you only want to detect a *successful* end, you should use the `end`
135135
* event instead.
136136
*
137137
* Many common streams (such as a TCP/IP connection or a file-based stream)

src/WritableStreamInterface.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
* This event is mostly used internally, see also `pipe()` for more details.
6060
*
6161
* error event:
62-
* The `error` event will be emitted whenever an error occurs, usually while
62+
* The `error` event will be emitted once a fatal error occurs, usually while
6363
* trying to write to this stream.
6464
* The event receives a single `Exception` argument for the error instance.
6565
*
@@ -69,21 +69,20 @@
6969
* });
7070
* ```
7171
*
72-
* This event MAY be emitted any number of times, which should be zero
73-
* times if this is a stream that is successfully terminated.
74-
* It SHOULD be emitted whenever the stream detects an error, such as a
75-
* transmission error.
76-
* It SHOULD NOT be emitted after a `close` event.
72+
* This event SHOULD be emitted once the stream detects a fatal error, such
73+
* as a fatal transmission error.
74+
* It SHOULD NOT be emitted after a previous `error` or `close` event.
75+
* It MUST NOT be emitted if this is not a fatal error condition, such as
76+
* a temporary network issue that did not cause any data to be lost.
77+
*
78+
* After the stream errors, it MUST close the stream and SHOULD thus be
79+
* followed by a `close` event and then switch to non-writable mode, see
80+
* also `close()` and `isWritable()`.
7781
*
7882
* Many common streams (such as a TCP/IP connection or a file-based stream)
7983
* only deal with data transmission and may choose
80-
* to only emit this for a fatal transmission error once and will thus
81-
* likely close (terminate) the stream in response.
82-
* If this is a fatal error that results in the stream being closed, it
83-
* SHOULD be followed by a `close` event.
84-
*
85-
* Other higher-level protocols may choose to keep the stream alive after
86-
* this event, if they can recover from an error condition.
84+
* to only emit this for a fatal transmission error once and will then
85+
* close (terminate) the stream in response.
8786
*
8887
* If this stream is a `DuplexStreamInterface`, you should also notice
8988
* how the readable side of the stream also implements an `error` event.

0 commit comments

Comments
 (0)