Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird behaviour for 0.5.3 #7

Closed
dashed opened this issue Jan 11, 2014 · 5 comments
Closed

Weird behaviour for 0.5.3 #7

dashed opened this issue Jan 11, 2014 · 5 comments

Comments

@dashed
Copy link

dashed commented Jan 11, 2014

I cloned this repo and created some file:

var es = require('event-stream');
var plumber = require('./');

var badBoy = es.through(function(data) {
    if(data % 2 == 0)
        return this.emit('error', new Error(data));

    this.emit('data', data);
});

es.readArray([1,2,3,4,5,6])
    .pipe(plumber())
    .pipe(badBoy)
    .pipe(es.through(console.log))

Output:

1
[gulp] Plumber found unhandled error: Error: 4
[gulp] Plumber found unhandled error: Error: 6

If I use gulp-plumber@0.4.1 using same code, I get output:

1
[gulp] Plumber found unhandled error: Error: 2
3
[gulp] Plumber found unhandled error: Error: 4
5
[gulp] Plumber found unhandled error: Error: 6
@floatdrop
Copy link
Owner

This is issue with this line: if (EE.listenerCount(this, 'error') < 3). I outputed listeners and this is what I see:

1
[ [Function: onerror2], [Function], [Function: onerror] ]
[ [Function: onerror2], [Function] ]
[gulp] Plumber found unhandled error: Error: 4
[ [Function: onerror2], [Function] ]
[gulp] Plumber found unhandled error: Error: 6

Some how default onerror is still there, but it should'nt.

@dashed
Copy link
Author

dashed commented Jan 11, 2014

Oh ah. I found that unusual behaviour when I made the continueOnError hack.

@floatdrop
Copy link
Owner

@dashed seems like streams in 0.10 reattaching onerror handler inside, this patchPipe function fixes your code samples:

    function patchPipe(stream) {
        if (stream.pipe2) {
            removeDefaultHandler(stream, 'error');
            stream._pipe = stream._pipe || stream.pipe;
            stream.pipe = stream.pipe2;
            stream.once('readable', patchPipe.bind(null, stream));
            stream._plumbed = true;
        }
    }

@dashed
Copy link
Author

dashed commented Jan 11, 2014

I get same output for 0.5.4:

1
[gulp] Plumber found unhandled error: Error: 4
[gulp] Plumber found unhandled error: Error: 6

But if it attach error listener:

es.readArray([1,2,3,4,5,6])
    .pipe(plumber())
    .pipe(badBoy)
        .on('error', console.log)
    .pipe(es.through(console.log))

I get output:

1
[Error: 2]
[Error: 4]
[Error: 6]

@floatdrop
Copy link
Owner

Closed in 0.5.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants