Skip to content

Stream's api methods must never throw - handling errors in DecodeStream, EncodeStream#81

Open
royaltm wants to merge 1 commit into
kawanet:masterfrom
royaltm:master
Open

Stream's api methods must never throw - handling errors in DecodeStream, EncodeStream#81
royaltm wants to merge 1 commit into
kawanet:masterfrom
royaltm:master

Conversation

@royaltm

@royaltm royaltm commented Jan 12, 2018

Copy link
Copy Markdown

Hello there!

This is just a quick fix for #75.
Nodejs stream api is callback based and doesn't handle errors thrown inside api methods.
I've just wrapped in try/catch block implementation of Transform stream in DecodeStream and EncodeStream to handle errors according to stream specs. It's rather mandatory to be able to handle errors when working with streams. In current version of msgpack-lite node process dies due to unhandled error when such error occures: e.g. DecodeStream fed with garbage data or EncodeStream with circular references.

Test cases included.

@DarrenCook DarrenCook left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me.

The before code uses if(callback)..., but the after code does not. Should that be added, just in case? Or is callback guaranteed to always be a callable object when working with streams?

@royaltm

royaltm commented Mar 27, 2018

Copy link
Copy Markdown
Author

AFAIK the callback is guaranteed and mandatory in node's stream api: https://nodejs.org/dist/latest-v8.x/docs/api/stream.html#stream_transform_transform_chunk_encoding_callback
IDK why it was like that.

@kawanet

kawanet commented Mar 27, 2018

Copy link
Copy Markdown
Owner

Thanks for the patch and the approval comment.
The patch looks good and minimal. I like the style. I will be merging it, asap.
I'm sorry for the late replies. I was too busy for those months.

@qqtrend

qqtrend commented Jun 11, 2018

Copy link
Copy Markdown

@kawanet Is it possible to merge this now? The Travis failure appears to be unrelated. I.e. all pull requests are failing at the same point (something to do with IE10?)

@robertsLando

Copy link
Copy Markdown

@kawanet Ping?

@kawanet

kawanet commented Sep 29, 2020

Copy link
Copy Markdown
Owner

pong

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 this pull request may close these issues.

5 participants