Skip to content

V2: Fix JSON error message - #849

Merged
timostamm merged 1 commit into
v2from
tstamm/fix-json-error-message
May 22, 2024
Merged

V2: Fix JSON error message#849
timostamm merged 1 commit into
v2from
tstamm/fix-json-error-message

Conversation

@timostamm

Copy link
Copy Markdown
Member

No description provided.

@timostamm
timostamm requested a review from srikrsna-buf May 22, 2024 15:13
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
Copy Markdown
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
Copy Markdown
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.

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