Skip to content
This repository has been archived by the owner on Jun 22, 2021. It is now read-only.

Better handling of unknown enums #139

Open
abhinav opened this issue Jul 21, 2016 · 5 comments
Open

Better handling of unknown enums #139

abhinav opened this issue Jul 21, 2016 · 5 comments

Comments

@abhinav
Copy link
Contributor

abhinav commented Jul 21, 2016

Because thriftrw-node exposes enums as strings, it doesn't have any way of handling unknown enums.

In other languages, since it's exposed as an integer, there's no parse error and you can have a catch-all for unrecognized cases:

if value == MyEnum.SomeItem:
    # ...
elif value == MyEnum.AnotherItem:
    # ...
else:
    # catch-all

We need thriftrw-node to have some way of dealing with unrecognized enums. One
possibility is to expose the received integer as-is in the unrecognized item
case.

if (value === 'SomeItem') {
    // ...
} else if (value == 'AnotherItem') {
    // ...
} else {
    console.log("Received item " + value);
}
@abhinav
Copy link
Contributor Author

abhinav commented Jul 21, 2016

CC @kriskowal @blampe @breerly

@kriskowal
Copy link
Contributor

It may be reasonable to surface an unrecognized enum as the underlying number. That would mean that an enum would be reified as either number or string, the latter if it is recognized.

I’m leery of folks switching on the number instead of the updating the IDL and using a name. We could alternately surface all unrecognized values as null.

@kriskowal
Copy link
Contributor

Would it make sense to distinguish optional enum from required enum for purposes of validating enums in either the request or response context?

@abhinav
Copy link
Contributor Author

abhinav commented Jul 21, 2016

I don't think we should differentiate between required and optional enums.

The idea behind exposing the number in the unrecognized case is not to let
people switch on that. It's for users to be able to switch on "Do I know how
to handle this?" We want them to be able to act on up to N different enum
items they do recognize, and have a consistent way of failing or handling the
cases that they don't recognize.

@Raynos
Copy link
Contributor

Raynos commented Nov 22, 2016

We should at the very least return some special string like "thriftrw-node: unknown enum value from future" to get forwards compatibility working in some fashion instead of getting a "Cannot read thrift response" exception in the client.

A cannot read thrift response should only happen for "truly" breaking changes or malformed binary payloads.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants