Repository navigation
Conversation
Add a client event that reports incoming packets the deserializer could not parse (ReadError), could only partially read (PartialReadError, via protodef's partialReadError event) or did not fully consume (SizeMismatch), with the raw buffer, packet id and name resolved from the version's protocol data. Nothing is computed unless something listens for the event, and the diagnostic can never throw into the stream pipeline. Existing error behaviour is unchanged. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VkmDtSAEEP841Htah1acp8
u9g
added a commit
to u9g/mineflayer
that referenced
this pull request
Oct 28, 2026
Instead of wrapping the deserializer's parsePacketBuffer (and rewrapping it on every state change), listen to the client's packetParseFailure event added in PrismarineJS/node-minecraft-protocol#1551, which already reports ReadError, PartialReadError and SizeMismatch with the packet id, name and raw buffer. This drops mineflayer's own varint and packet-name lookup. The test now covers SizeMismatch (trailing bytes), which works with the released protodef, and keeps the PartialReadError case, skipped on protodef < 1.20.0 since only 1.20.0 emits partialReadError.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
packetParseFailureclient event so that consumers can diagnose incoming packets that could not be parsed, without reaching into the deserializer.This is the NMP side of PrismarineJS/mineflayer#4164 ("Dump packets that fail to parse to a local file"). That PR currently monkey-patches
client.deserializer.parsePacketBufferon every state change to catch the three failure kinds; @rom1504 asked in PrismarineJS/mineflayer#4164 (comment) for NMP to own the diagnostic so Mineflayer only consumes it. Once this is released, mineflayer#4164 will be reworked to listen to this event instead.The event
client.on('packetParseFailure', failure => ...)with:errorhandler, before the existingerrorevent. Existing behaviour is unchanged.partialReadErroreventFullPacketParseremits since FullPacketParser: emit partialReadError with the chunk it could not read ProtoDef-io/node-protodef#178 (protodef 1.20.0, merged but not yet published to npm). Still not turned into anerrorevent.datahandler, whenmetadata.size !== fullBuffer.length; the packet is then emitted as before.Nothing is computed unless there is a listener (
listenerCount), and the diagnostic is wrapped so it can never throw into the stream pipeline. No stack-frame parsing:error.field/error.stackare passed through as-is.Also adds the event to
src/index.d.tsand documents it indocs/API.md.Tests
test/packetParseFailureTest.jsspins up an NMP server per supported version, connects a client, and has the serverwriteRaw:keep_aliveid with no body →PartialReadErrorwithstate: 'play',direction: 'toClient',packetName: 'keep_alive'and the sent buffer. This case is marked pending until protodef >= 1.20.0 is installed, since 1.19.0 swallows partial reads silently.keep_alivewith trailing bytes →SizeMismatchwithbytesRead < buffer.length, and thekeep_alivepacket is still emitted.keep_alive→ no event.A ReadError case is not covered: an unknown packet id parses as a 1-byte packet (a SizeMismatch) rather than throwing, so there is no easy raw-bytes way to trigger one.
Local results (protodef 1.19.0, Java 21): lint clean;
packetTest,serverTest,cyclePacketTest,compressionTest,pingTest,docTestand the new test pass for 26.1, 1.12.2 and 1.8.8, plus the vanilla-serverclientTestfor 1.8.8 (26.1's vanilla server needs Java 25). With protodef master installed, the new PartialReadError case passes for all 30 versions.Generated by Claude Code