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

Handling source stream errors #67

Closed
brian-gates opened this issue Apr 23, 2014 · 6 comments · Fixed by #106
Closed

Handling source stream errors #67

brian-gates opened this issue Apr 23, 2014 · 6 comments · Fixed by #106

Comments

@brian-gates
Copy link

If I wrap a stream that emits an error, the error is uncaught.

This is the stream I'm wrapping: https://github.com/brian-gates/cypher-stream/blob/master/index.js#L36

My syntax is this: _(source).errors(fn). I would expect the errors to be caught, but they are not.

Any help is appreciated.

@glenjamin
Copy link
Collaborator

See the example at http://highlandjs.org/#errors

As far as I can tell, in the node callback style your function should either push(err) or push(null, chunk)

@brian-gates
Copy link
Author

I'm not using any node style callbacks. I also saw the source there, but calling .errors does nothing.

The source stream emits the error but highland is not capturing it, so it just bubbles all the way up.

One way to do it is to use a generator:

  var stream = _(function (push, next){
    db.cypher(query, params)
      .on('error', function (error){
        push(error);
      })
      .on('data', function (result){
        push(null, result);
        next();
      })
      .on('end', function(){
        push(null, $.nil)
      })
  });
  stream.errors(handler) // works

But it seems like I should be able to just wrap it and get the same effect:

_(db.cypher(query,parms)).errors(handler)

But it doesn't work.

@caolan
Copy link
Owner

caolan commented Apr 28, 2014

@brian-gates I think you're right, errors should probably get passed through the highland stream by default when you wrap it.

+1 if you want to make a test case and pull request ;)

@dweinstein
Copy link

+1 -- also in same boat with handling errors. It's late so I'll add an example later.

@makara
Copy link

makara commented May 7, 2014

I think every time you pipe an arbitrary stream to a highland stream you need to handle the error events as well, but I'm not sure how (simply re-emit?).

I see 2 places for the moment, one in function Stream and another in Stream.prototype.through.

@apaleslimghost
Copy link
Collaborator

I'm having a look at this.

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

Successfully merging a pull request may close this issue.

6 participants