Skip to content

Commit

Permalink
Never manually emit errors on streams
Browse files Browse the repository at this point in the history
  • Loading branch information
watson committed Nov 9, 2020
1 parent f8bcaa7 commit 34737a9
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/kbn-es-archiver/src/actions/load.ts
Expand Up @@ -43,7 +43,7 @@ import {
// are not listened for
const pipeline = (...streams: Readable[]) =>
streams.reduce((source, dest) =>
source.once('error', (error) => dest.emit('error', error)).pipe(dest as any)
source.once('error', (error) => dest.destroy(error)).pipe(dest as any)
);

export async function loadAction({
Expand Down
Expand Up @@ -44,7 +44,7 @@ describe('concatStreamProviders() helper', () => {
() =>
new Readable({
read() {
this.emit('error', new Error('foo'));
this.destroy(new Error('foo'));
},
}),
]);
Expand Down
Expand Up @@ -50,7 +50,7 @@ export function concatStreamProviders(

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 });
Expand Down
Expand Up @@ -44,7 +44,7 @@ describe('concatStreamProviders() helper', () => {
() =>
new Readable({
read() {
this.emit('error', new Error('foo'));
this.destroy(new Error('foo'));
},
}),
]);
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/utils/streams/concat_stream_providers.ts
Expand Up @@ -54,7 +54,7 @@ export function concatStreamProviders(

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 });
Expand Down
Expand Up @@ -283,7 +283,7 @@ describe('copySavedObjectsToSpaces', () => {
new Readable({
objectMode: true,
read() {
this.emit('error', new Error('Something went wrong while reading this stream'));
this.destroy(new Error('Something went wrong while reading this stream'));
},
})
);
Expand Down
Expand Up @@ -290,7 +290,7 @@ describe('resolveCopySavedObjectsToSpacesConflicts', () => {
new Readable({
objectMode: true,
read() {
this.emit('error', new Error('Something went wrong while reading this stream'));
this.destroy(new Error('Something went wrong while reading this stream'));
},
})
);
Expand Down

0 comments on commit 34737a9

Please sign in to comment.