Improve logging around hashes and null byte errors

This commit is contained in:
James Allen
2017-02-27 10:06:24 +01:00
parent 60f3393c44
commit dd45a8dd7d
3 changed files with 17 additions and 4 deletions
@@ -32,7 +32,9 @@ module.exports = RedisManager =
_callback(error)
docLines = JSON.stringify(docLines)
if docLines.indexOf("\u0000") != -1
return callback(new Error("null bytes found in doc lines"))
error = new Error("null bytes found in doc lines")
logger.error err: error, doc_id: doc_id, docLines: docLines, error.message
return callback(error)
docHash = RedisManager._computeHash(docLines)
logger.log project_id:project_id, doc_id:doc_id, version: version, hash:docHash, "putting doc in redis"
ranges = RedisManager._serializeRanges(ranges)
@@ -150,12 +152,18 @@ module.exports = RedisManager =
error = new Error("Version mismatch. '#{doc_id}' is corrupted.")
logger.error {err: error, doc_id, currentVersion, newVersion, opsLength: appliedOps.length}, "version mismatch"
return callback(error)
jsonOps = appliedOps.map (op) -> JSON.stringify op
multi = rclient.multi()
newDocLines = JSON.stringify(docLines)
if newDocLines.indexOf("\u0000") != -1
return callback(new Error("null bytes found in doc lines"))
error = new Error("null bytes found in doc lines")
logger.error err: error, doc_id: doc_id, newDocLines: newDocLines, error.message
return callback(error)
newHash = RedisManager._computeHash(newDocLines)
logger.log doc_id: doc_id, version: newVersion, hash: newHash, "updating doc in redis"
multi = rclient.multi()
multi.eval setScript, 1, keys.docLines(doc_id:doc_id), newDocLines
multi.set keys.docVersion(doc_id:doc_id), newVersion
multi.set keys.docHash(doc_id:doc_id), newHash
@@ -61,7 +61,6 @@ module.exports = UpdateManager =
return callback(error) if error?
RangesManager.applyUpdate project_id, doc_id, ranges, appliedOps, (error, new_ranges) ->
return callback(error) if error?
logger.log doc_id: doc_id, version: version, "updating doc in redis"
RedisManager.updateDocument doc_id, updatedDocLines, version, appliedOps, new_ranges, (error) ->
return callback(error) if error?
HistoryManager.pushUncompressedHistoryOps project_id, doc_id, appliedOps, callback
@@ -331,6 +331,9 @@ describe "RedisManager", ->
afterEach ->
@JSON.stringify = @_stringify
it "should log an error", ->
@logger.error.called.should.equal true
it "should call the callback with an error", ->
@callback.calledWith(new Error("null bytes found in doc lines")).should.equal true
@@ -416,6 +419,9 @@ describe "RedisManager", ->
afterEach ->
@JSON.stringify = @_stringify
it "should log an error", ->
@logger.error.called.should.equal true
it "should call the callback with an error", ->
@callback.calledWith(new Error("null bytes found in doc lines")).should.equal true