From 31235beee5888e9f91d83271672092df74c5b7eb Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Mon, 20 Mar 2017 16:17:22 +0000 Subject: [PATCH] Don't throw error if the function is not invoked with callback. Instead, log the error and return early. --- .../metrics/test/unit/coffee/timeAsyncMethodTests.coffee | 6 ++---- libraries/metrics/timeAsyncMethod.coffee | 6 +++--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/libraries/metrics/test/unit/coffee/timeAsyncMethodTests.coffee b/libraries/metrics/test/unit/coffee/timeAsyncMethodTests.coffee index a7f3a83c94..c606b5f719 100644 --- a/libraries/metrics/test/unit/coffee/timeAsyncMethodTests.coffee +++ b/libraries/metrics/test/unit/coffee/timeAsyncMethodTests.coffee @@ -93,12 +93,10 @@ describe 'timeAsyncMethod', -> @testObject.nextNumber = (n) -> return n+1 - it 'should throw an error', -> + it 'should not throw an error', -> @timeAsyncMethod @testObject, 'nextNumber', 'test.nextNumber' badCall = () => @testObject.nextNumber 2 - expect(badCall).to.throw( - /^.*expected wrapped method 'nextNumber' to be invoked with a callback.*$/ - ) + expect(badCall).to.not.throw(Error) diff --git a/libraries/metrics/timeAsyncMethod.coffee b/libraries/metrics/timeAsyncMethod.coffee index 7ec64f3d41..d980ce48a0 100644 --- a/libraries/metrics/timeAsyncMethod.coffee +++ b/libraries/metrics/timeAsyncMethod.coffee @@ -11,10 +11,10 @@ module.exports = (obj, methodName, prefix, logger) -> obj[methodName] = (originalArgs...) -> [firstArgs..., callback] = originalArgs + if !callback? || typeof callback != 'function' - throw new Error( - "[Metrics] expected wrapped method '#{methodName}' to be invoked with a callback" - ) + logger.log "[Metrics] expected wrapped method '#{methodName}' to be invoked with a callback" + return timer = new metrics.Timer(key)