Skip to content

Commit

Permalink
V2: Fix JSON error message (#849)
Browse files Browse the repository at this point in the history
  • Loading branch information
timostamm authored May 22, 2024
1 parent 43b5dde commit d20225e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
14 changes: 6 additions & 8 deletions packages/protobuf-test/extra/msg-json-names.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ package spec;


message JsonNamesMessage {

string scalar_field = 1 [json_name = "scalarFieldJsonName"];
repeated string repeated_scalar_field = 2 [json_name = "repeatedScalarFieldJsonName"];

string a = 3;
string b = 4 [json_name = ""];
string c = 5 [json_name = "@type"];

string scalar_field = 1 [json_name = "scalarFieldJsonName"];
repeated string repeated_scalar_field = 2 [json_name = "repeatedScalarFieldJsonName"];
string a = 3;
string b = 4 [json_name = ""];
string c = 5 [json_name = "@type"];
string d = 6 [json_name = "1d"];
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion packages/protobuf-test/src/gen/ts/extra/msg-json-names_pb.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/protobuf/src/to-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
);
}
if (!opts.emitDefaultValues || f.presence !== IMPLICIT) {
Expand Down

0 comments on commit d20225e

Please sign in to comment.