From 3fdffb4b8178a4248a6f09b340a49044baf18d1a Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Wed, 25 May 2016 11:03:38 -0700 Subject: [PATCH] fix(config): removeAtKeyPath => undo, guard with assertions --- .../worker-sync/lib/nylas-long-connection.coffee | 2 +- src/config.coffee | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/internal_packages/worker-sync/lib/nylas-long-connection.coffee b/internal_packages/worker-sync/lib/nylas-long-connection.coffee index 11bbddfef..2efa36138 100644 --- a/internal_packages/worker-sync/lib/nylas-long-connection.coffee +++ b/internal_packages/worker-sync/lib/nylas-long-connection.coffee @@ -111,7 +111,7 @@ class NylasLongConnection res.on 'data', (chunk) => if chunk.toString().indexOf('Invalid cursor') > 0 error = new Error('Delta Connection: Cursor is invalid. Need to blow away local cache.') - NylasEnv.config.removeAtKeyPath("nylas.#{@_accountId}.cursor") + NylasEnv.config.unset("nylas.#{@_accountId}.cursor") DatabaseStore._handleSetupError(error) @close() return diff --git a/src/config.coffee b/src/config.coffee index a57e60754..0124c3b23 100644 --- a/src/config.coffee +++ b/src/config.coffee @@ -485,18 +485,24 @@ class Config pushAtKeyPath: (keyPath, value) -> arrayValue = @get(keyPath) ? [] + unless arrayValue instanceof Array + throw new Error("Config.pushAtKeyPath is intended for array values. Value #{JSON.stringify(arrayValue)} is not an array.") result = arrayValue.push(value) @set(keyPath, arrayValue) result unshiftAtKeyPath: (keyPath, value) -> arrayValue = @get(keyPath) ? [] + unless arrayValue instanceof Array + throw new Error("Config.unshiftAtKeyPath is intended for array values. Value #{JSON.stringify(arrayValue)} is not an array.") result = arrayValue.unshift(value) @set(keyPath, arrayValue) result removeAtKeyPath: (keyPath, value) -> arrayValue = @get(keyPath) ? [] + unless arrayValue instanceof Array + throw new Error("Config.removeAtKeyPath is intended for array values. Value #{JSON.stringify(arrayValue)} is not an array.") result = _.remove(arrayValue, value) @set(keyPath, arrayValue) result