Skip to content

Commit 6c149ea

Browse files
author
Ruben Bridgewater
committed
Improve error handling
1 parent 926d8c6 commit 6c149ea

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

lib/parser.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,10 @@ function parseType (parser, type) {
223223
case 45: // -
224224
return parseError(parser)
225225
default:
226-
return handleError(parser, new ReplyError('Protocol error, got ' + JSON.stringify(String.fromCharCode(type)) + ' as reply type byte'))
226+
const err = new ReplyError('Protocol error, got ' + JSON.stringify(String.fromCharCode(type)) + ' as reply type byte', 20)
227+
err.offset = parser.offset
228+
err.buffer = JSON.stringify(parser.buffer)
229+
return handleError(parser, err)
227230
}
228231
}
229232

lib/replyError.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
var util = require('util')
44

5-
function ReplyError (message) {
5+
function ReplyError (message, newLimit) {
66
var limit = Error.stackTraceLimit
7-
Error.stackTraceLimit = 2
7+
Error.stackTraceLimit = newLimit || 2
8+
Error.call(this, message)
89
Error.captureStackTrace(this, this.constructor)
910
Error.stackTraceLimit = limit
1011
Object.defineProperty(this, 'message', {

test/parsers.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ describe('parsers', function () {
722722
})
723723

724724
it('handle big data 2 with buffers', function (done) {
725-
this.timeout(4000)
725+
this.timeout(5000)
726726
var lorem = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, ' +
727727
'sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. ' +
728728
'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ' +

0 commit comments

Comments
 (0)