redis-parser
Advanced tools
Comparing version 2.4.0 to 2.5.0
@@ -0,1 +1,18 @@ | ||
## v.2.5.0 - 11 Mar, 2017 | ||
Features | ||
- Added a `ParserError` class to differentiate them to ReplyErrors. The class is also exported | ||
Bugfixes | ||
- All errors now show their error message again next to the error name in the stack trace | ||
- ParserErrors now show the offset and buffer attributes while being logged | ||
## v.2.4.1 - 05 Feb, 2017 | ||
Bugfixes | ||
- Fixed minimal memory consumtion overhead for chunked buffers | ||
## v.2.4.0 - 25 Jan, 2017 | ||
@@ -2,0 +19,0 @@ |
@@ -6,1 +6,2 @@ 'use strict' | ||
module.exports.RedisError = require('./lib/redisError') | ||
module.exports.ParserError = require('./lib/redisError') |
@@ -5,2 +5,3 @@ 'use strict' | ||
var ReplyError = require('../lib/replyError') | ||
var ParserError = require('../lib/parserError') | ||
@@ -12,3 +13,3 @@ /** | ||
*/ | ||
function parseData (parser) { | ||
function parseData (parser, data) { | ||
try { | ||
@@ -20,3 +21,3 @@ return parser.reader.get() | ||
parser.reader = new hiredis.Reader(parser.options) | ||
parser.returnFatalError(new ReplyError(err.message)) | ||
parser.returnFatalError(new ParserError(err.message, JSON.stringify(data), -1)) | ||
} | ||
@@ -43,3 +44,3 @@ } | ||
this.reader.feed(data) | ||
var reply = parseData(this) | ||
var reply = parseData(this, data) | ||
@@ -52,3 +53,3 @@ while (reply !== undefined) { | ||
} | ||
reply = parseData(this) | ||
reply = parseData(this, data) | ||
} | ||
@@ -55,0 +56,0 @@ } |
@@ -6,2 +6,3 @@ 'use strict' | ||
var ReplyError = require('./replyError') | ||
var ParserError = require('./parserError') | ||
var bufferPool = new Buffer(32 * 1024) | ||
@@ -294,6 +295,7 @@ var bufferOffset = 0 | ||
default: | ||
var err = new ReplyError('Protocol error, got ' + JSON.stringify(String.fromCharCode(type)) + ' as reply type byte', 20) | ||
err.offset = parser.offset | ||
err.buffer = JSON.stringify(parser.buffer) | ||
return handleError(parser, err) | ||
return handleError(parser, new ParserError( | ||
'Protocol error, got ' + JSON.stringify(String.fromCharCode(type)) + ' as reply type byte', | ||
JSON.stringify(parser.buffer), | ||
parser.offset | ||
)) | ||
} | ||
@@ -455,7 +457,8 @@ } | ||
parser.offset = offset | ||
if (offset === 1) { | ||
if (offset <= 2) { | ||
if (chunks === 2) { | ||
return list[0].toString('utf8', parser.bigOffset, list[0].length - 1) | ||
return list[0].toString('utf8', parser.bigOffset, list[0].length + offset - 2) | ||
} | ||
chunks-- | ||
offset = list[list.length - 2].length + offset | ||
} | ||
@@ -484,21 +487,20 @@ var res = decoder.write(list[0].slice(parser.bigOffset)) | ||
parser.offset = offset | ||
if (offset === 1) { | ||
if (offset <= 2) { | ||
if (chunks === 2) { | ||
return list[0].slice(parser.bigOffset, list[0].length - 1) | ||
return list[0].slice(parser.bigOffset, list[0].length + offset - 2) | ||
} | ||
chunks-- | ||
offset = list[list.length - 1].length + 1 | ||
offset = list[list.length - 2].length + offset | ||
} | ||
resizeBuffer(length) | ||
var pos = bufferOffset | ||
list[0].copy(bufferPool, pos, parser.bigOffset, list[0].length) | ||
pos += list[0].length - parser.bigOffset | ||
for (var i = 1; i < list.length - 1; i++) { | ||
list[i].copy(bufferPool, pos) | ||
pos += list[i].length | ||
var start = bufferOffset | ||
list[0].copy(bufferPool, start, parser.bigOffset, list[0].length) | ||
bufferOffset += list[0].length - parser.bigOffset | ||
for (var i = 1; i < chunks - 1; i++) { | ||
list[i].copy(bufferPool, bufferOffset) | ||
bufferOffset += list[i].length | ||
} | ||
list[i].copy(bufferPool, pos, 0, offset - 2) | ||
var buffer = bufferPool.slice(bufferOffset, length + bufferOffset) | ||
bufferOffset += length | ||
return buffer | ||
list[i].copy(bufferPool, bufferOffset, 0, offset - 2) | ||
bufferOffset += offset - 2 | ||
return bufferPool.slice(start, bufferOffset) | ||
} | ||
@@ -505,0 +507,0 @@ |
@@ -5,9 +5,11 @@ 'use strict' | ||
function RedisError (message) { | ||
Error.call(this, message) | ||
Error.captureStackTrace(this, this.constructor) | ||
function RedisError (message, stack) { | ||
Object.defineProperty(this, 'message', { | ||
value: message || '', | ||
configurable: true, | ||
writable: true | ||
}) | ||
if (stack || stack === undefined) { | ||
Error.captureStackTrace(this, RedisError) | ||
} | ||
} | ||
@@ -19,2 +21,3 @@ | ||
value: 'RedisError', | ||
configurable: true, | ||
writable: true | ||
@@ -21,0 +24,0 @@ }) |
@@ -5,8 +5,10 @@ 'use strict' | ||
var RedisError = require('./redisError') | ||
var ADD_STACKTRACE = false | ||
function ReplyError (message, newLimit) { | ||
var limit = Error.stackTraceLimit | ||
Error.stackTraceLimit = newLimit || 2 | ||
RedisError.call(this, message) | ||
Error.stackTraceLimit = limit | ||
function ReplyError (message) { | ||
var tmp = Error.stackTraceLimit | ||
Error.stackTraceLimit = 2 | ||
RedisError.call(this, message, ADD_STACKTRACE) | ||
Error.captureStackTrace(this, ReplyError) | ||
Error.stackTraceLimit = tmp | ||
} | ||
@@ -18,2 +20,3 @@ | ||
value: 'ReplyError', | ||
configurable: true, | ||
writable: true | ||
@@ -20,0 +23,0 @@ }) |
{ | ||
"name": "redis-parser", | ||
"version": "2.4.0", | ||
"version": "2.5.0", | ||
"description": "Javascript Redis protocol (RESP) parser", | ||
@@ -9,3 +9,4 @@ "main": "index.js", | ||
"benchmark": "node ./benchmark", | ||
"posttest": "standard && npm run coverage:check", | ||
"lint": "standard --fix", | ||
"posttest": "npm run lint && npm run coverage:check", | ||
"coverage": "node ./node_modules/istanbul/lib/cli.js cover --preserve-comments ./node_modules/mocha/bin/_mocha -- -R spec", | ||
@@ -12,0 +13,0 @@ "coverage:check": "node ./node_modules/istanbul/lib/cli.js check-coverage --branch 100 --statement 100" |
@@ -39,5 +39,9 @@ [![Build Status](https://travis-ci.org/NodeRedis/node-redis-parser.png?branch=master)](https://travis-ci.org/NodeRedis/node-redis-parser) | ||
All errors returned by the parser are of the class `ReplyError` that is a sub class of `RedisError`. | ||
Both types are exported by the parser. | ||
* `RedisError` sub class of Error | ||
* `ReplyError` sub class of RedisError | ||
* `ParserError` sub class of RedisError | ||
All Redis errors will be returned as `ReplyErrors` while a parser error is returned as `ParserError`. | ||
All error classes are exported by the parser. | ||
### Example | ||
@@ -44,0 +48,0 @@ |
Sorry, the diff of this file is not supported yet
30808
649
164