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

Union fix #8

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Union fix #8

wants to merge 6 commits into from

Conversation

anujdas
Copy link

@anujdas anujdas commented May 2, 2018

Union validation was broken for a very specific edge case: when a field
that was a container around structs is not set, validation produces a
highly confusing error message indicating that the unset field was, in
fact, not set. As an example, consider the definition

  union UnionExample {
    1: list<SimpleStruct> primary
    2: string alternate
  }

Setting the alternate field caused validation to fail, claiming that
the primary field was not the set_field. This was due to the validator
accessing the unset field, because the code meant to check this case
only ran for specific field types. Now it performs correctly regardless
of field type.

Also adds a bunch of other changes and fixes (error unification, README
fixes, make -> rake conversion).

We already need `rake` to work with this gem, and it's capable of
basically everything that `make` is; unify build tools to prevent
confusion.

Move the test thrift files into the test/ directory to avoid clutter,
plus add a `clean` target for `rake` that wipes built definitions.

Also, add minitest as a dependency, since it’s not built into newer
Ruby versions.
Some things passed/returned to Thrift endpoints are not themselves
Thrift objects, e.g., lists, primitives, or nil. These can and should
still be validated. Since we're anyway not making use of type hints in
the schema and relying on Thrift structs to self-validate, we can just
recurse the struct tree and let what can be validated be validated,
greatly cleaning up implementation while adding functionality.

For example, union validation was broken for a very specific edge case:
when a field that was a container around structs is not set, validation
produces a highly confusing error message indicating that the unset
field is, in fact, not set. Consider the Thrift definition

  union UnionExample {
    1: list<SomeStruct> primary,
    2: string alternate,
  }

Setting the `alternate` field caused validation to fail, claiming that
the `primary` field was not the set_field. This was due to the validator
accessing the unset field, because the code meant to check this case
only ran for specific field types. Now it performs correctly regardless
of field type.
Union validation used to raise a StandardError, which doesn't make sense
when the rest of the validation failures cause ProtocolExceptions.
Make that uniform.
The library's error changes and new functionality seem like enough to
bump the minor version. In particular, union validation now raises a
different error (ProtocolException) than it used to (StandardError).
@anujdas
Copy link
Author

anujdas commented May 2, 2018

@ahawkins sorry for the commit churn. This PR should be final.

Validator#validate is an instance method; reflect this in the docs.
@anujdas anujdas changed the title Wip/union fix Union fix Jul 17, 2018
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.

1 participant