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

remove the path in the message from fs errors

Brian Gough 8 лет назад
Родитель
Сommit
df3b889f50

+ 4 - 0
libraries/logger/logging-manager.coffee

@@ -50,6 +50,10 @@ module.exports = Logger =
 				for own key, value of error
 					newError[key] = value
 				error = newError
+			# filter paths from the message to avoid duplicate errors in sentry
+			# (e.g. errors from `fs` methods which have a path attribute)
+			try
+				error.message = error.message.replace(" '#{error.path}'", '') if error.path
 			# send the error to sentry
 			try
 				@raven.captureException(error, {tags: tags, extra: extra, level: level})

+ 6 - 0
libraries/logger/test/unit/coffee/loggingManagerTests.coffee

@@ -40,6 +40,12 @@ describe 'logger.error', ->
 		@logger.error {bar: error2}, "second message"
 		@captureException.callCount.should.equal 2
 
+	it 'should remove the path from fs errors', () ->
+		fsError = new Error("Error: ENOENT: no such file or directory, stat '/tmp/3279b8d0-da10-11e8-8255-efd98985942b'")
+		fsError.path = "/tmp/3279b8d0-da10-11e8-8255-efd98985942b"
+		@logger.error {err: fsError}, "message"
+		@captureException.calledWith(sinon.match.has('message', 'Error: ENOENT: no such file or directory, stat')).should.equal true
+
 	it 'for multiple errors should only report a maximum of 5 errors to sentry', () ->
 		@logger.error {foo:'bar'}, "message"
 		@logger.error {foo:'bar'}, "message"