Skip to content
This repository has been archived by the owner on Mar 22, 2024. It is now read-only.

Prevent unhandled error events from the first stream of utils.safePipe #75

Merged
merged 1 commit into from Jan 5, 2017

Conversation

jviotti
Copy link
Contributor

@jviotti jviotti commented Jan 5, 2017

We have a utility function called utils.safePipe() that accepts an
array of streams and pipes them all together attaching error handlers at
every step.

We didn't recognise a subtle flaw that would prevent the error handler
(and any event listener, really) to be attached to the first stream on
the pipe chain: we check if current exists, and if not, set the
current stream as current however we return right away, which means
the error handler and event handlers defined just below never get called
on the first stream (which is the only case where current is not
defined).

As a bonus, this commit adds some unit tests for utils.safePipe().

See: balena-io/etcher#981
Signed-off-by: Juan Cruz Viotti jviotti@openmailbox.org

We have a utility function called `utils.safePipe()` that accepts an
array of streams and pipes them all together attaching error handlers at
every step.

We didn't recognise a subtle flaw that would prevent the error handler
(and any event listener, really) to be attached to the first stream on
the pipe chain: we check if `current` exists, and if not, set the
current stream as `current` however we `return` right away, which means
the error handler and event handlers defined just below never get called
on the first stream (which is the only case where `current` is not
defined).

As a bonus, this commit adds some unit tests for `utils.safePipe()`.

See: balena-io/etcher#981
Signed-off-by: Juan Cruz Viotti <jviotti@openmailbox.org>
@jviotti jviotti merged commit 2d4b9b1 into master Jan 5, 2017
@jviotti jviotti deleted the prevent-unhandled-errors branch January 5, 2017 21:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant