Skip to content

Serializer: name the packet in write errors from a compiled protocol - #180

Open
u9g wants to merge 1 commit into
ProtoDef-io:masterfrom
u9g:serializer-packet-name
Open

u9g wants to merge 1 commit into
ProtoDef-io:masterfrom
u9g:serializer-packet-name

Conversation

@u9g

@u9g u9g commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Problem

Every packet write goes through Serializer.createPacketBuffer, but a compiled protocol never sets e.field, so the errors coming out say nothing about which packet failed:

Error: Write error for undefined : Missing field 'x'
Error: SizeOf error for undefined : 0 is not in the mappings value

The interpreter names it through the switch's field path (params.position.face); the compiler reports no path at all. The error is thrown inside _transform and surfaces asynchronously on the stream, so a caller cannot attribute it after the fact either.

Change

Serializer.createPacketBuffer prefixes the message with in packet <name>: when the value has a name and the error's field path does not already contain it:

in packet position: SizeOf error for undefined : up is not in the mappings value

Interpreted errors and values without a name are untouched.

Testing

  • New tests in test/misc.js: compiled gets the prefix, interpreted keeps its field path with no duplicate, a value with no name is left alone.
  • npm test: lint clean, 504 passing.

@extremeheat

Copy link
Copy Markdown
Contributor

Every packet write goes through Serializer.createPacketBuffer, but a compiled protocol never sets e.field, so the errors coming out say nothing about which packet failed:

Seems like correct fix is to fix that

@Pix3lPirat3

Copy link
Copy Markdown

Nice, this is the packet-level half of the problem. I have a complementary branch that fills in the other half: it threads e.field through the compiled container read/write/sizeOf codegen (mirroring the interpreted tryDoc), so a compiled protocol produces a real dotted field path instead of undefined - e.g. SizeOf error for meta.label rather than SizeOf error for undefined. It stacks cleanly with this PR (your in packet <name>: prefix plus a populated field path -> in packet position: SizeOf error for meta.label), and it's what surfaces which field of a bedrock packet is missing/wrong (the recurring "bad_packet / SizeOf undefined" reports). Happy to open it as a follow-up on top of this once it lands, or fold it in here if you'd prefer. Verified with a nested round-trip matching the interpreted path exactly, full suite green + a regression test.

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.

3 participants