node/test/parallel/test-wrap-js-stream-exceptions.js
Robert Nagy 8f86986985 stream: use callback to properly propagate error
The stream will be destroyed upstream through the proper error
flow.

PR-URL: https://github.com/nodejs/node/pull/29179
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2020-04-03 19:00:28 +02:00

24 lines
603 B
JavaScript

// Flags: --expose-internals
'use strict';
const common = require('../common');
const assert = require('assert');
const JSStreamWrap = require('internal/js_stream_socket');
const { Duplex } = require('stream');
process.once('uncaughtException', common.mustCall((err) => {
assert.strictEqual(err.message, 'exception!');
}));
const socket = new JSStreamWrap(new Duplex({
read: common.mustCall(),
write: common.mustCall((buffer, data, cb) => {
throw new Error('exception!');
})
}));
socket.end('foo');
socket.on('error', common.expectsError({
name: 'Error',
message: 'write EPROTO'
}));