From 17d689b6495aee5f76c989a3d48d6db892578734 Mon Sep 17 00:00:00 2001 From: Thomas Watson Date: Tue, 8 Jun 2021 13:19:28 +0200 Subject: [PATCH] Never manually emit errors on streams See: nodejs/node#36053 --- src/es_archiver/actions/load.js | 2 +- src/optimize/public_path_placeholder.js | 2 +- src/utils/streams/concat_stream_providers.js | 2 +- src/utils/streams/concat_stream_providers.test.js | 2 +- .../plugins/reporting/server/browsers/download/download.test.js | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/es_archiver/actions/load.js b/src/es_archiver/actions/load.js index cc3cf8f789b043c..f3ea7f19f546548 100644 --- a/src/es_archiver/actions/load.js +++ b/src/es_archiver/actions/load.js @@ -42,7 +42,7 @@ import { const pipeline = (...streams) => streams .reduce((source, dest) => ( source - .once('error', (error) => dest.emit('error', error)) + .once('error', (error) => dest.destroy(error)) .pipe(dest) )); diff --git a/src/optimize/public_path_placeholder.js b/src/optimize/public_path_placeholder.js index e40a9b4ba759139..c4e60798bd50e01 100644 --- a/src/optimize/public_path_placeholder.js +++ b/src/optimize/public_path_placeholder.js @@ -35,7 +35,7 @@ export function replacePlaceholder(read, replacement) { takeUntil(Rx.fromEvent(read, 'end')) ) .forEach(error => { - replace.emit('error', error); + replace.destroy(error); replace.end(); }); diff --git a/src/utils/streams/concat_stream_providers.js b/src/utils/streams/concat_stream_providers.js index adbbcf9a0d5f9d7..db977d8716fffd9 100644 --- a/src/utils/streams/concat_stream_providers.js +++ b/src/utils/streams/concat_stream_providers.js @@ -51,7 +51,7 @@ export function concatStreamProviders(sourceProviders, options = {}) { source // proxy errors from the source to the destination - .once('error', (error) => destination.emit('error', error)) + .once('error', (error) => destination.destroy(error)) // pipe the source to the destination but only proxy the // end event if this is the last source .pipe(destination, { end: isLast }); diff --git a/src/utils/streams/concat_stream_providers.test.js b/src/utils/streams/concat_stream_providers.test.js index f3997998c967bd9..8f74a9a1353bfef 100644 --- a/src/utils/streams/concat_stream_providers.test.js +++ b/src/utils/streams/concat_stream_providers.test.js @@ -44,7 +44,7 @@ describe('concatStreamProviders() helper', () => { () => new Readable({ read() { - this.emit('error', new Error('foo')); + this.destroy(new Error('foo')); }, }), ]); diff --git a/x-pack/plugins/reporting/server/browsers/download/download.test.js b/x-pack/plugins/reporting/server/browsers/download/download.test.js index 61b505703a75168..76dc71a5ffde0c7 100644 --- a/x-pack/plugins/reporting/server/browsers/download/download.test.js +++ b/x-pack/plugins/reporting/server/browsers/download/download.test.js @@ -22,7 +22,7 @@ jest.mock('request', () => { return new Readable({ read() { if (resp instanceof Error) { - this.emit('error', resp); + this.destroy(resp); return; }