Add message and field name to binary serialization errors#984
Add message and field name to binary serialization errors#984timostamm merged 6 commits intobufbuild:mainfrom
Conversation
|
Thanks for the PR, Ben. We'll need some insight whether / how this impacts performance and bundle size. I think it would be ideal to use the same mechanism for error messages that |
|
Running Edit: Hmm, looks like there aren't any performance tests for Before: After: |
7dee7dd to
624cc52
Compare
| } | ||
|
|
||
| function setupTests(): Test[] { | ||
| const tests: Test[] = []; |
There was a problem hiding this comment.
This looks like a huge change but I'm just switching to generating the benchmark cases instead of having to repeat code.
| return [ | ||
| { | ||
| name: `fromBinary ${name}`, |
There was a problem hiding this comment.
This is the actual change - we now benchmark fromBinary, fromJsonString, toBinary, and toJsonString for each example message.
|
Thanks for the updates, Ben. I'll take a look as soon as possible, but have to take care of some Connect work first. |
|
A gentle nudge on this - it would still be of great benefit to have this information. |
timostamm
left a comment
There was a problem hiding this comment.
A gentle nudge on this - it would still be of great benefit to have this information.
Apologies for the delay, Ben.
It doesn't seem ideal that we have to pass message and field name around. It would be great if we could use checkField from reflect-check.ts like toJson does, but I wasn't able to find a way to utilize it without larger refactors.
We may extend and improve reflect-check.ts in the near future for protovalidate, and it's possible that this gives us new options to tighten up the code and also improve error messages. I don't think it's useful to wait for that though, and I think it makes sense to merge this improvement.
Two minor things though, before we merge:
- Let's include #1051.
- Fields have a reference to the message they are defined in - we can use that instead of passing the message name. See comments below.
|
Sure, here are those changes. |
This adds the message and field name to errors thrown during binary serialization of scalar fields. It should convert a message like:
To:
I followed the wording of the error thrown here for the phrasing: https://github.com/bufbuild/protobuf-es/blob/main/packages/protobuf/src/to-binary.ts#L74
Fixes #983