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

Error Handling #696

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

Error Handling #696

wesleytodd opened this issue Mar 5, 2017 · 4 comments
Labels

Comments

@wesleytodd
Copy link

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
Copy link
Member

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!

@wesleytodd
Copy link
Author

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
Copy link
Member

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
Copy link
Member

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 as completed Mar 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants