Skip to content

Commit

Permalink
errors,stream-transform: migrate to use internal/errors.js
Browse files Browse the repository at this point in the history
PR-URL: #13310
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
  • Loading branch information
sreepurnajasti authored and mhdawson committed Jun 15, 2017
1 parent 3c506af commit d50a802
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
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 @@ -157,6 +157,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');

0 comments on commit d50a802

Please sign in to comment.