Skip to content

Commit db7d133

Browse files
committed
stream: migrate to internal/errors
PR-URL: #15665 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 4536128 commit db7d133

4 files changed

+16
-8
lines changed

lib/_stream_transform.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ Transform.prototype.push = function(chunk, encoding) {
157157
// an error, then that'll put the hurt on the whole operation. If you
158158
// never call cb(), then you'll never get another chunk.
159159
Transform.prototype._transform = function(chunk, encoding, cb) {
160-
throw new Error('_transform() is not implemented');
160+
throw new errors.Error('ERR_METHOD_NOT_IMPLEMENTED', '_transform');
161161
};
162162

163163
Transform.prototype._write = function(chunk, encoding, cb) {

lib/_stream_writable.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const internalUtil = require('internal/util');
3333
const Stream = require('stream');
3434
const Buffer = require('buffer').Buffer;
3535
const destroyImpl = require('internal/streams/destroy');
36+
const errors = require('internal/errors');
3637

3738
util.inherits(Writable, Stream);
3839

@@ -319,7 +320,7 @@ Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
319320
if (typeof encoding === 'string')
320321
encoding = encoding.toLowerCase();
321322
if (!Buffer.isEncoding(encoding))
322-
throw new TypeError('Unknown encoding: ' + encoding);
323+
throw new errors.TypeError('ERR_UNKNOWN_ENCODING', encoding);
323324
this._writableState.defaultEncoding = encoding;
324325
return this;
325326
};

test/parallel/test-stream-transform-constructor-set-methods.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@ const t2 = new Transform({});
2727
t.end(Buffer.from('blerg'));
2828
t.resume();
2929

30-
assert.throws(() => {
30+
common.expectsError(() => {
3131
t2.end(Buffer.from('blerg'));
32-
}, /^Error: _transform\(\) is not implemented$/);
33-
32+
}, {
33+
type: Error,
34+
code: 'ERR_METHOD_NOT_IMPLEMENTED',
35+
message: 'The _transform method is not implemented'
36+
});
3437

3538
process.on('exit', () => {
3639
assert.strictEqual(t._transform, _transform);

test/parallel/test-stream-writable-change-default-encoding.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
// USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

2222
'use strict';
23-
require('../common');
23+
const common = require('../common');
2424
const assert = require('assert');
2525

2626
const stream = require('stream');
@@ -55,13 +55,17 @@ MyWritable.prototype._write = function(chunk, encoding, callback) {
5555
m.end();
5656
}());
5757

58-
assert.throws(function changeDefaultEncodingToInvalidValue() {
58+
common.expectsError(function changeDefaultEncodingToInvalidValue() {
5959
const m = new MyWritable(function(isBuffer, type, enc) {
6060
}, { decodeStrings: false });
6161
m.setDefaultEncoding({});
6262
m.write('bar');
6363
m.end();
64-
}, /^TypeError: Unknown encoding: \[object Object\]$/);
64+
}, {
65+
type: TypeError,
66+
code: 'ERR_UNKNOWN_ENCODING',
67+
message: 'Unknown encoding: [object Object]'
68+
});
6569

6670
(function checkVairableCaseEncoding() {
6771
const m = new MyWritable(function(isBuffer, type, enc) {

0 commit comments

Comments
 (0)