Skip to content

All enums should have "Other" option. #723

@kevincox

Description

@kevincox

Describe the bug

Right now many (all?) enums such as PaymentMethodOptionsKlarnaSetupFutureUsage have a fixed set of options. In this case just None. However this is a loaded gun because Stripe can add new values to these enums.

This can result in errors like the following when trying to parse a webhook:

BadParse(Error("unknown variant off_session, expected none", line: 68, column: 3))

This means that every async-stripe user can start throwing errors at any time because Stripe adds a new value to an enum.

The only way I can see to handle this is add an Other option to every enum. Ideally this Other would also capture the raw value so that it can be logged, and in the worst case introspected. But the bare minimum is that parsing the whole object doesn't fail.

To Reproduce

  1. Parse a webhook with a matching API version.

Expected behavior

It successfully parses.

OS

Linux

Rust version

N/A

Library version

0.41.0

API version

2024-06-20

Additional context

I have confirmed with their support engineers that this is expected within an API version:

Ah, I see what you mean. Sorry about the confusion. This is the expected behavior, actually. The enum values in some sense shouldn't be considered static (limited to what API reference lists). We do add new values over time to support new features that are back ported to older API versions so that Stripe users aren't forced to constantly upgrade to the newest version.

Also, in this specific instance, we can't return setup_future_usage as none even on the older API version because that'd be wrong and we also can't omit the field altogether. For example, our first-party SDKs handle this gracefully and expect the values to change dynamically. But yeah, in this case - the rust library would need to be updated to handle this better.

I hope this helps clarify.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions