Просмотр исходного кода

Improve logging around hashes and null byte errors

James Allen 9 лет назад
Родитель
Сommit
dd45a8dd7d

+ 11 - 3
services/document-updater/app/coffee/RedisManager.coffee

@@ -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

+ 0 - 1
services/document-updater/app/coffee/UpdateManager.coffee

@@ -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

+ 6 - 0
services/document-updater/test/unit/coffee/RedisManager/RedisManagerTests.coffee

@@ -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