Skip to content

Commit d50a802

Browse files
sreepurnajastimhdawson
sreepurnajasti
authored andcommitted
errors,stream-transform: migrate to use internal/errors.js
PR-URL: #13310 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
1 parent 3c506af commit d50a802

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

lib/_stream_transform.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
'use strict';
6565

6666
module.exports = Transform;
67-
67+
const errors = require('internal/errors');
6868
const Duplex = require('_stream_duplex');
6969
const util = require('util');
7070
util.inherits(Transform, Duplex);
@@ -78,7 +78,7 @@ function afterTransform(er, data) {
7878

7979
if (!cb) {
8080
return this.emit('error',
81-
new Error('write callback called multiple times'));
81+
new errors.Error('ERR_TRANSFORM_MULTIPLE_CALLBACK'));
8282
}
8383

8484
ts.writechunk = null;
@@ -210,10 +210,9 @@ function done(stream, er, data) {
210210
// if there's nothing in the write buffer, then that means
211211
// that nothing more will ever be provided
212212
if (stream._writableState.length)
213-
throw new Error('Calling transform done when ws.length != 0');
213+
throw new errors.Error('ERR_TRANSFORM_WITH_LENGTH_0');
214214

215215
if (stream._transformState.transforming)
216-
throw new Error('Calling transform done when still transforming');
217-
216+
throw new errors.Error('ERR_TRANSFORM_ALREADY_TRANSFORMING');
218217
return stream.push(null);
219218
}

lib/internal/errors.js

+5
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ E('ERR_PARSE_HISTORY_DATA',
157157
(oldHistoryPath) => `Could not parse history data in ${oldHistoryPath}`);
158158
E('ERR_STDERR_CLOSE', 'process.stderr cannot be closed');
159159
E('ERR_STDOUT_CLOSE', 'process.stdout cannot be closed');
160+
E('ERR_TRANSFORM_ALREADY_TRANSFORMING',
161+
'Calling transform done when still transforming');
162+
E('ERR_TRANSFORM_MULTIPLE_CALLBACK', 'Callback called multiple times');
163+
E('ERR_TRANSFORM_WITH_LENGTH_0',
164+
'Calling transform done when ws.length != 0');
160165
E('ERR_HTTP_TRAILER_INVALID',
161166
'Trailers are invalid with this transfer encoding');
162167
E('ERR_UNKNOWN_BUILTIN_MODULE', (id) => `No such built-in module: ${id}`);

test/parallel/test-stream-transform-callback-twice.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ const stream = new Transform({
88

99
stream.on('error', common.mustCall((err) => {
1010
assert.strictEqual(err.toString(),
11-
'Error: write callback called multiple times');
11+
'Error [ERR_TRANSFORM_MULTIPLE_CALLBACK]: ' +
12+
'Callback called multiple times');
1213
}));
1314

1415
stream.write('foo');

0 commit comments

Comments
 (0)