Skip to content
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

V2: Fix JSON error message #849

Merged
merged 1 commit into from
May 22, 2024
Merged

V2: Fix JSON error message #849

merged 1 commit into from
May 22, 2024

Conversation

timostamm
Copy link
Member

No description provided.

@@ -140,7 +140,7 @@ function reflectToJson(msg: ReflectMessage, opts: JsonWriteOptions): JsonValue {
if (!msg.isSet(f)) {
if (f.presence == LEGACY_REQUIRED) {
throw new Error(
`cannot encode field ${msg.desc.typeName}.${f.name} to binary: required field not set`,
`cannot encode field ${msg.desc.typeName}.${f.name} to JSON: required field not set`,
Copy link
Member Author

Choose a reason for hiding this comment

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

The fix.

string a = 3;
string b = 4 [json_name = ""];
string c = 5 [json_name = "@type"];
string d = 6 [json_name = "1d"];
Copy link
Member Author

Choose a reason for hiding this comment

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

This is an unrelated change. Proto field names cannot start with a digit (it's an error in the compiler), but there's no such restriction on json_name. JSON itself doesn't have that restriction either, but something like generated JSON types will have to quote the property. I'm adding this case here in advance.

@timostamm timostamm merged commit d20225e into v2 May 22, 2024
7 checks passed
@timostamm timostamm deleted the tstamm/fix-json-error-message branch May 22, 2024 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants