diff --git a/lib/_stream_transform.js b/lib/_stream_transform.js index f3e83e3a24cbeb..0f607a6da38593 100644 --- a/lib/_stream_transform.js +++ b/lib/_stream_transform.js @@ -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); @@ -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; @@ -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); } diff --git a/lib/internal/errors.js b/lib/internal/errors.js index 3e4f6f426b594e..570ed6d5ba6b42 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -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}`); diff --git a/test/parallel/test-stream-transform-callback-twice.js b/test/parallel/test-stream-transform-callback-twice.js index 31a4aea29e5f65..afb55faa1a27c1 100644 --- a/test/parallel/test-stream-transform-callback-twice.js +++ b/test/parallel/test-stream-transform-callback-twice.js @@ -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');