-
Notifications
You must be signed in to change notification settings - Fork 24
Proposal for handling unknown enums #700
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
base: main
Are you sure you want to change the base?
Conversation
🔍 SDK Breaking Change Detection ResultsSDK Version:
Breaking change detection completed. View SDK workflow |
|
Great job! No new security vulnerabilities introduced in this pull request |
dani-garcia
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds like a fairly reasonable solution, I like that we don't lose the unknown value now. A couple of notes:
- Why name the variant
__Unknownrather than justUnknown? The users of this are going to be expected to handle it somehow, so it seems strange when__could imply internal only. - It's a bit strange that the macro is adding an entirely new variant that is not there at all, it could cause some confusion if users check the enum definition and think these enums don't have an unkown branch, only for the compiler to tell them it does have it.
- Somewhat related, but why use a macro? The code is all autogenerated so we don't really benefit that much from the code duplication, while the macro might make the IDE navigation and code discovery worse.
As a middle ground, if we want to reduce some duplication, I think it would be better to change the templates to generate code like:
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum KdfType {
PBKDF2_SHA256 = 0,
Argon2id = 1,
Unknown(usize),
}
// Implement these as part of the template, so they're more easily discovered
pub fn as_usize() {}
pub fn from_usize() {}
// The macro implements serialize/deserialize based on the previous functions. This is an implementation detail so it's okay to hide behind a macro
impl_int_enum_deserialize!(KdfType);
It seems
Yea fair, I could tweak the bindings to generate it.
No reason really. It was nice getting rid of a decent chunk of boilerplate binding code but happy to put it in |
67db6f0 to
dab6567
Compare
dani-garcia
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks reasonable to me, just needs fixing all the existing uses now
coroiu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have not gone through the consumers and updated them yet though.
@Hinton two questions:
- What is your thinking on how the consumers should handle the unknown scenario?
- Have you considered making the API enums
#[non_exhaustive]to make adding new known types easier in the future?
It's up to each team to decide. If they WANT forward compatibility they would have to default to some value. If they don't they can use
There is benefit in having compile time errors when new enums are added since you definitively know everything supports the new value. Making it non exhaustive would remove this safe guard. |

🎟️ Tracking
https://bitwarden.atlassian.net/browse/PM-6169
📔 Objective
Improved iteration of bitwarden/sdk-sm#595.
Adds a
__Unknown(value)enum to all endpoints to handle any unknown enums in api bindings. Leaving it up to the caller to determine if it should result in a parse error or if there is a graceful way to handle it.Uses
untaggedto handle strings and for integers swaps out the serde_repr for a custom macro.Note: For ease of reviewing this is split into two commits, one that updates the templates and another that updates the bindings. I have not gone through the consumers and updated them yet though.
⏰ Reminders before review
team
🦮 Reviewer guidelines
:+1:) or similar for great changes:memo:) or ℹ️ (:information_source:) for notes or general info:question:) for questions:thinking:) or 💭 (:thought_balloon:) for more open inquiry that's not quite a confirmedissue and could potentially benefit from discussion
:art:) for suggestions / improvements:x:) or:warning:) for more significant problems or concerns needing attention:seedling:) or ♻️ (:recycle:) for future improvements or indications of technical debt:pick:) for minor or nitpick changes