stream: migrate _stream_readable use error codes
PR-URL: https://github.com/nodejs/node/pull/15042 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
This commit is contained in:
parent
de61f97c3d
commit
88fb359c57
@ -1317,6 +1317,24 @@ Node.js does not allow `stdout` or `stderr` Streams to be closed by user code.
|
||||
Used when an attempt is made to close the `process.stdout` stream. By design,
|
||||
Node.js does not allow `stdout` or `stderr` Streams to be closed by user code.
|
||||
|
||||
<a id="ERR_STREAM_PUSH_AFTER_EOF"></a>
|
||||
### ERR_STREAM_PUSH_AFTER_EOF
|
||||
|
||||
Used when an attempt is made to call [`stream.push()`][] after a `null`(EOF)
|
||||
has been pushed to the stream.
|
||||
|
||||
<a id="ERR_STREAM_READ_NOT_IMPLEMENTED"></a>
|
||||
### ERR_STREAM_READ_NOT_IMPLEMENTED
|
||||
|
||||
Used when an attempt is made to use a readable stream that has not implemented
|
||||
[`readable._read()`][].
|
||||
|
||||
<a id="ERR_STREAM_UNSHIFT_AFTER_END_EVENT"></a>
|
||||
### ERR_STREAM_UNSHIFT_AFTER_END_EVENT
|
||||
|
||||
Used when an attempt is made to call [`stream.unshift()`][] after the
|
||||
`end` event has been emitted.
|
||||
|
||||
<a id="ERR_STREAM_WRAP"></a>
|
||||
### ERR_STREAM_WRAP
|
||||
|
||||
@ -1462,7 +1480,10 @@ closed.
|
||||
[`ERR_INVALID_ARG_TYPE`]: #ERR_INVALID_ARG_TYPE
|
||||
[`hash.digest()`]: crypto.html#crypto_hash_digest_encoding
|
||||
[`hash.update()`]: crypto.html#crypto_hash_update_data_inputencoding
|
||||
[`readable._read()`]: stream.html#stream_readable_read_size_1
|
||||
[`sign.sign()`]: crypto.html#crypto_sign_sign_privatekey_outputformat
|
||||
[`stream.push()`]: stream.html#stream_readable_push_chunk_encoding
|
||||
[`stream.unshift()`]: stream.html#stream_readable_unshift_chunk
|
||||
[`subprocess.kill()`]: child_process.html#child_process_subprocess_kill_signal
|
||||
[`subprocess.send()`]: child_process.html#child_process_subprocess_send_message_sendhandle_options_callback
|
||||
[`fs.readFileSync`]: fs.html#fs_fs_readfilesync_path_options
|
||||
|
@ -31,6 +31,7 @@ const util = require('util');
|
||||
const debug = util.debuglog('stream');
|
||||
const BufferList = require('internal/streams/BufferList');
|
||||
const destroyImpl = require('internal/streams/destroy');
|
||||
const errors = require('internal/errors');
|
||||
var StringDecoder;
|
||||
|
||||
util.inherits(Readable, Stream);
|
||||
@ -233,11 +234,12 @@ function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) {
|
||||
|
||||
if (addToFront) {
|
||||
if (state.endEmitted)
|
||||
stream.emit('error', new Error('stream.unshift() after end event'));
|
||||
stream.emit('error',
|
||||
new errors.Error('ERR_STREAM_UNSHIFT_AFTER_END_EVENT'));
|
||||
else
|
||||
addChunk(stream, state, chunk, true);
|
||||
} else if (state.ended) {
|
||||
stream.emit('error', new Error('stream.push() after EOF'));
|
||||
stream.emit('error', new errors.Error('ERR_STREAM_PUSH_AFTER_EOF'));
|
||||
} else {
|
||||
state.reading = false;
|
||||
if (state.decoder && !encoding) {
|
||||
@ -548,7 +550,7 @@ function maybeReadMore_(stream, state) {
|
||||
// for virtual (non-string, non-buffer) streams, "length" is somewhat
|
||||
// arbitrary, and perhaps not very meaningful.
|
||||
Readable.prototype._read = function(n) {
|
||||
this.emit('error', new Error('_read() is not implemented'));
|
||||
this.emit('error', new errors.Error('ERR_STREAM_READ_NOT_IMPLEMENTED'));
|
||||
};
|
||||
|
||||
Readable.prototype.pipe = function(dest, pipeOpts) {
|
||||
|
@ -325,6 +325,9 @@ E('ERR_SOCKET_CLOSED', 'Socket is closed');
|
||||
E('ERR_SOCKET_DGRAM_NOT_RUNNING', 'Not running');
|
||||
E('ERR_STDERR_CLOSE', 'process.stderr cannot be closed');
|
||||
E('ERR_STDOUT_CLOSE', 'process.stdout cannot be closed');
|
||||
E('ERR_STREAM_PUSH_AFTER_EOF', 'stream.push() after EOF');
|
||||
E('ERR_STREAM_READ_NOT_IMPLEMENTED', '_read() is not implemented');
|
||||
E('ERR_STREAM_UNSHIFT_AFTER_END_EVENT', 'stream.unshift() after end event');
|
||||
E('ERR_STREAM_WRAP', 'Stream has StringDecoder set or is in objectMode');
|
||||
E('ERR_TLS_CERT_ALTNAME_INVALID',
|
||||
'Hostname/IP does not match certificate\'s altnames: %s');
|
||||
|
@ -1,8 +1,12 @@
|
||||
'use strict';
|
||||
require('../common');
|
||||
const common = require('../common');
|
||||
const stream = require('stream');
|
||||
const assert = require('assert');
|
||||
|
||||
const readable = new stream.Readable();
|
||||
|
||||
assert.throws(() => readable.read(), /not implemented/);
|
||||
assert.throws(() => readable.read(), common.expectsError({
|
||||
code: 'ERR_STREAM_READ_NOT_IMPLEMENTED',
|
||||
type: Error,
|
||||
message: '_read() is not implemented'
|
||||
}));
|
||||
|
@ -70,7 +70,11 @@ r._read = function(n) {
|
||||
function pushError() {
|
||||
assert.throws(function() {
|
||||
r.push(Buffer.allocUnsafe(1));
|
||||
}, /^Error: stream\.push\(\) after EOF$/);
|
||||
}, common.expectsError({
|
||||
code: 'ERR_STREAM_PUSH_AFTER_EOF',
|
||||
type: Error,
|
||||
message: 'stream.push() after EOF'
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
@ -84,7 +88,11 @@ w._write = function(chunk, encoding, cb) {
|
||||
r.on('end', common.mustCall(function() {
|
||||
assert.throws(function() {
|
||||
r.unshift(Buffer.allocUnsafe(1));
|
||||
}, /^Error: stream\.unshift\(\) after end event$/);
|
||||
}, common.expectsError({
|
||||
code: 'ERR_STREAM_UNSHIFT_AFTER_END_EVENT',
|
||||
type: Error,
|
||||
message: 'stream.unshift() after end event'
|
||||
}));
|
||||
w.end();
|
||||
}));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user