Skip to content

Commit

Permalink
Include buffer context when throwing error in deserializer streams
Browse files Browse the repository at this point in the history
This makes it possible to debug issues with schemas or invalid buffers
  • Loading branch information
extremeheat authored Dec 22, 2024
1 parent 0002700 commit b8614e1
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class Parser extends Transform {
try {
packet = this.parsePacketBuffer(this.queue)
} catch (e) {
e.buffer = this.queue
if (e.partialReadError) { return cb() } else {
e.buffer = this.queue
this.queue = Buffer.alloc(0)
return cb(e)
}
Expand Down Expand Up @@ -77,6 +77,7 @@ class FullPacketParser extends Transform {
JSON.stringify(packet.data) + '; buffer :' + chunk.toString('hex'))
}
} catch (e) {
e.buffer = this.queue
if (e.partialReadError) {
if (!this.noErrorLogging) {
console.log(e.stack)
Expand Down

0 comments on commit b8614e1

Please sign in to comment.