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

Error Handling #696

Closed
wesleytodd opened this Issue Mar 5, 2017 · 4 comments

Comments

Projects
None yet
2 participants
@wesleytodd

wesleytodd commented Mar 5, 2017

As far as I can tell there are no docs on error handling for this package. Are errors thrown when using decode/encode? Is there an emitter I can bind to? Maybe I just missed them while looking around?

I would be happy to write up something for the readme, or wherever you prefer. But I think as a noob with this package I would like guidance from the maintainers before I do :)

@dcodeIO

This comment has been minimized.

Owner

dcodeIO commented Mar 5, 2017

decode throws if the buffer cannot be decoded, i.e. is invalid / not matching the schema. Starting with 6.7.0, it will also throw if the argument is not a valid buffer (see).

encode does not verify messages on its own. It just tries to encode whatever is specified, which might, for entirely bogus data, result in a runtime error being thrown somewhere down the road.

For explicit verification of messages, there is verify instead, which can be used where necessary. Having separate methods for encoding and verification avoids performing possibly redundant assertions when encoding. For example, sometimes a developer already knows that a payload is valid, thus it would be unnecessary to verify it (again) implicitly. verify does not throw but returns an error string if there are issues, or null if there are none.

Hope this helps!

@dcodeIO dcodeIO added the question label Mar 5, 2017

@wesleytodd

This comment has been minimized.

wesleytodd commented Mar 5, 2017

That does help, thanks! Would you be opposed to me taking this explanation and adding it to the readme? Or is there a better place to document this so others don't have to dig?

dcodeIO added a commit that referenced this issue Mar 5, 2017

dcodeIO added a commit that referenced this issue Mar 5, 2017

dcodeIO added a commit that referenced this issue Mar 5, 2017

@dcodeIO

This comment has been minimized.

Owner

dcodeIO commented Mar 5, 2017

I've now added respective documentation to the initial README example. Decoders now also throw if required fields are missing so that verify does not have to be called after decode, which it isn't meant for (would introduce new redundant assertions otherwise).

Related: #695

@dcodeIO

This comment has been minimized.

Owner

dcodeIO commented Mar 22, 2017

Closing this issue for now as it hasn't received any replies recently. Feel free to reopen it if necessary!

@dcodeIO dcodeIO closed this Mar 22, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment