-
Notifications
You must be signed in to change notification settings - Fork 192
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
Server enums should not have Unknown
variants
#1187
Comments
Strong enums are a big reason for me to use Rust when writing server code (no need to handle corner cases all the time). Not having |
@david-perez Should a server be able to hook into this error case of unknown enums? A service might need to specify which error to return in each case. Functionally-wise, a specific error could make the difference between a client receiving a generic "Bad request" error, vs. getting a specific "InvalidXXX" error. Just one quick example from the top of my mind is the
|
@guymguym I think yes. Ideally, users should be able to opt into hooking into errors resulting from constraint traint violations, and map them to modeled errors. I was thinking of doing something like this: #1199 (comment)
We're still far away from implementing such hooks, since constraint traits (besides |
The server must have the most up to date variants and the unknown enum variant should not be used. Clients are generated with it because they might not have the most recent model and the server might return an unknown variant to them. Closes #1187 Signed-off-by: Daniele Ahmed <[email protected]>
The server must have the most up to date variants and the unknown enum variant should not be used. Clients are generated with it because they might not have the most recent model and the server might return an unknown variant to them. Closes #1187 Signed-off-by: Daniele Ahmed <[email protected]>
The server must have the most up to date variants and the unknown enum variant should not be used. Clients are generated with it because they might not have the most recent model and the server might return an unknown variant to them. Closes #1187 Signed-off-by: Daniele Ahmed <[email protected]>
The server must have the most up to date variants and the unknown enum variant should not be used. Clients are generated with it because they might not have the most recent model and the server might return an unknown variant to them. Closes #1187 Signed-off-by: Daniele Ahmed <[email protected]> Co-authored-by: Daniele Ahmed <[email protected]> Co-authored-by: david-perez <[email protected]> Co-authored-by: Matteo Bigoi <[email protected]>
When generating enums for the server, we're generating an
Unknown
variant.https://github.com/awslabs/smithy-rs/blob/548f6ed4307faae5bb98e431db96ae90a59e489d/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/EnumGenerator.kt#L154-L155
Server enums should not contain this variant. This also means we can no longer
impl From<&str> for MyEnum
, sinceFrom
is required to never fail. We should instead implementTryFrom
. This also means deserialization code will be affected, since deserializing a&str
into an enum can now fail.The text was updated successfully, but these errors were encountered: