stream: migrate to internal/errors
PR-URL: https://github.com/nodejs/node/pull/15665 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
4536128e7c
commit
db7d1339c3
@ -157,7 +157,7 @@ Transform.prototype.push = function(chunk, encoding) {
|
|||||||
// an error, then that'll put the hurt on the whole operation. If you
|
// an error, then that'll put the hurt on the whole operation. If you
|
||||||
// never call cb(), then you'll never get another chunk.
|
// never call cb(), then you'll never get another chunk.
|
||||||
Transform.prototype._transform = function(chunk, encoding, cb) {
|
Transform.prototype._transform = function(chunk, encoding, cb) {
|
||||||
throw new Error('_transform() is not implemented');
|
throw new errors.Error('ERR_METHOD_NOT_IMPLEMENTED', '_transform');
|
||||||
};
|
};
|
||||||
|
|
||||||
Transform.prototype._write = function(chunk, encoding, cb) {
|
Transform.prototype._write = function(chunk, encoding, cb) {
|
||||||
|
@ -33,6 +33,7 @@ const internalUtil = require('internal/util');
|
|||||||
const Stream = require('stream');
|
const Stream = require('stream');
|
||||||
const Buffer = require('buffer').Buffer;
|
const Buffer = require('buffer').Buffer;
|
||||||
const destroyImpl = require('internal/streams/destroy');
|
const destroyImpl = require('internal/streams/destroy');
|
||||||
|
const errors = require('internal/errors');
|
||||||
|
|
||||||
util.inherits(Writable, Stream);
|
util.inherits(Writable, Stream);
|
||||||
|
|
||||||
@ -319,7 +320,7 @@ Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
|
|||||||
if (typeof encoding === 'string')
|
if (typeof encoding === 'string')
|
||||||
encoding = encoding.toLowerCase();
|
encoding = encoding.toLowerCase();
|
||||||
if (!Buffer.isEncoding(encoding))
|
if (!Buffer.isEncoding(encoding))
|
||||||
throw new TypeError('Unknown encoding: ' + encoding);
|
throw new errors.TypeError('ERR_UNKNOWN_ENCODING', encoding);
|
||||||
this._writableState.defaultEncoding = encoding;
|
this._writableState.defaultEncoding = encoding;
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
@ -27,10 +27,13 @@ const t2 = new Transform({});
|
|||||||
t.end(Buffer.from('blerg'));
|
t.end(Buffer.from('blerg'));
|
||||||
t.resume();
|
t.resume();
|
||||||
|
|
||||||
assert.throws(() => {
|
common.expectsError(() => {
|
||||||
t2.end(Buffer.from('blerg'));
|
t2.end(Buffer.from('blerg'));
|
||||||
}, /^Error: _transform\(\) is not implemented$/);
|
}, {
|
||||||
|
type: Error,
|
||||||
|
code: 'ERR_METHOD_NOT_IMPLEMENTED',
|
||||||
|
message: 'The _transform method is not implemented'
|
||||||
|
});
|
||||||
|
|
||||||
process.on('exit', () => {
|
process.on('exit', () => {
|
||||||
assert.strictEqual(t._transform, _transform);
|
assert.strictEqual(t._transform, _transform);
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
require('../common');
|
const common = require('../common');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
const stream = require('stream');
|
const stream = require('stream');
|
||||||
@ -55,13 +55,17 @@ MyWritable.prototype._write = function(chunk, encoding, callback) {
|
|||||||
m.end();
|
m.end();
|
||||||
}());
|
}());
|
||||||
|
|
||||||
assert.throws(function changeDefaultEncodingToInvalidValue() {
|
common.expectsError(function changeDefaultEncodingToInvalidValue() {
|
||||||
const m = new MyWritable(function(isBuffer, type, enc) {
|
const m = new MyWritable(function(isBuffer, type, enc) {
|
||||||
}, { decodeStrings: false });
|
}, { decodeStrings: false });
|
||||||
m.setDefaultEncoding({});
|
m.setDefaultEncoding({});
|
||||||
m.write('bar');
|
m.write('bar');
|
||||||
m.end();
|
m.end();
|
||||||
}, /^TypeError: Unknown encoding: \[object Object\]$/);
|
}, {
|
||||||
|
type: TypeError,
|
||||||
|
code: 'ERR_UNKNOWN_ENCODING',
|
||||||
|
message: 'Unknown encoding: [object Object]'
|
||||||
|
});
|
||||||
|
|
||||||
(function checkVairableCaseEncoding() {
|
(function checkVairableCaseEncoding() {
|
||||||
const m = new MyWritable(function(isBuffer, type, enc) {
|
const m = new MyWritable(function(isBuffer, type, enc) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user