Skip to content

gRPC JSON transcoding — Fixed parsing string values into enum when provided string is not valid enum value #52402

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

Merged

Conversation

zorix
Copy link
Contributor

@zorix zorix commented Nov 27, 2023

Fixed parsing string values into enum when provided string is not valid enum value

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

NullReferenceException is thrown when string value cannot be converted to gRPC enum value.

Description

Right now when we provided JSON string value (for example INVALID) into gRPC enum like this (I took it from tests)

enum NestedEnum {
  NESTED_ENUM_UNSPECIFIED = 0;
  FOO = 1;
  BAR = 2;
  BAZ = 3;
  NEG = -1;  // Intentionally negative.
}

We will get NullReferenceException in this line because valueDescriptor won't be found.

Not related issue found

@ghost ghost added area-grpc Includes: GRPC wire-up, templates community-contribution Indicates that the PR has been added by a community member labels Nov 27, 2023
@ghost
Copy link

ghost commented Nov 27, 2023

Thanks for your PR, @zorix. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@zorix
Copy link
Contributor Author

zorix commented Nov 27, 2023

@dotnet-policy-service agree

@zorix zorix changed the title Fixed parsing string values into enum when provided string is not valid enum value gRPC JSON transcoding — Fixed parsing string values into enum when provided string is not valid enum value Nov 27, 2023
Copy link
Member

@JamesNK JamesNK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Some minor changes to the error message and variable names.

@zorix zorix force-pushed the fix-handling-not-alloawed-string-values-in-enums branch from c60f1da to 80de8ba Compare November 29, 2023 10:10
Co-authored-by: James Newton-King <[email protected]>
@JamesNK JamesNK merged commit df46227 into dotnet:main Nov 29, 2023
@ghost ghost added this to the 9.0-preview1 milestone Nov 29, 2023
@JamesNK
Copy link
Member

JamesNK commented Nov 29, 2023

Thanks!

@zorix zorix deleted the fix-handling-not-alloawed-string-values-in-enums branch November 30, 2023 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-grpc Includes: GRPC wire-up, templates community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants