Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

errors,stream-transform: migrate to use internal/errors.js #13310

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions lib/_stream_transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
'use strict';

module.exports = Transform;

const errors = require('internal/errors');
const Duplex = require('_stream_duplex');
const util = require('util');
util.inherits(Transform, Duplex);
Expand All @@ -78,7 +78,7 @@ function afterTransform(er, data) {

if (!cb) {
return this.emit('error',
new Error('write callback called multiple times'));
new errors.Error('ERR_TRANSFORM_MULTIPLE_CALLBACK'));
}

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

if (stream._transformState.transforming)
throw new Error('Calling transform done when still transforming');

throw new errors.Error('ERR_TRANSFORM_ALREADY_TRANSFORMING');
return stream.push(null);
}
5 changes: 5 additions & 0 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ E('ERR_PARSE_HISTORY_DATA',
(oldHistoryPath) => `Could not parse history data in ${oldHistoryPath}`);
E('ERR_STDERR_CLOSE', 'process.stderr cannot be closed');
E('ERR_STDOUT_CLOSE', 'process.stdout cannot be closed');
E('ERR_TRANSFORM_ALREADY_TRANSFORMING',
'Calling transform done when still transforming');
E('ERR_TRANSFORM_MULTIPLE_CALLBACK', 'Callback called multiple times');
E('ERR_TRANSFORM_WITH_LENGTH_0',
'Calling transform done when ws.length != 0');
E('ERR_HTTP_TRAILER_INVALID',
'Trailers are invalid with this transfer encoding');
E('ERR_UNKNOWN_BUILTIN_MODULE', (id) => `No such built-in module: ${id}`);
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-stream-transform-callback-twice.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const stream = new Transform({

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

stream.write('foo');