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

Tolerate unrecognized messages/fields gracefully #27

Open
vu3rdd opened this issue Apr 12, 2018 · 2 comments
Open

Tolerate unrecognized messages/fields gracefully #27

vu3rdd opened this issue Apr 12, 2018 · 2 comments

Comments

@vu3rdd
Copy link
Collaborator

vu3rdd commented Apr 12, 2018

We do not want to error out and exit if the other sends us messages with null fields or optional fields. eg: the message of type message has an id field that may be set to null. We would like the deserialization of such messages from binary to json be handled leniently.

@warner warner changed the title Handle fields gracefully Tolerate unrecognized messages/fields gracefully May 27, 2018
@warner
Copy link
Collaborator

warner commented May 27, 2018

I'll add: in general, the client needs to ignore unrecognized message types and unknown fields inside known messages. This gives us some room for expansion in the future. The unit tests ought to signal an error if we receive unknown messages, but actual runtime code should ignore them. In Twisted I do this with a log.err() call, and the testing framework knows that anything written to the error log should flunk the test. And we test tolerance by asking the testing framework to selectively ignore those error messages in specific tests. I don't know the Rust testing ecosystem well enough to suggest a technique or a library, but I'm sure one is out there somewhere.

@piegamesde
Copy link
Member

serde has a few options to future-proof deserialization:

  • deny_unknown_fields

    Always error during deserialization when encountering unknown fields. When this attribute is not present, by default unknown fields are ignored for self-describing formats like JSON.

    • So we don't need to do anything here for unknown attributes
  • For known optional attributes, use Optional<> or #[serde(default)]
  • For unknown enum variants, use #[serde(other)]. Sadly, there is no way to access that unknown value yet.
  • There are tricks to store all unmatched keys into a map for dynamic access (I'd have to look it up for an example)

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

3 participants