From c2124b40f660be8f56d16c11d737ca00bd8cbcac Mon Sep 17 00:00:00 2001 From: Brian Broll Date: Thu, 20 Aug 2020 10:50:54 -0500 Subject: [PATCH] Better error message on null node. Fixes #1875 --- src/plugins/TwoPhaseCommit/TwoPhaseCore.js | 2 +- .../plugins/TwoPhaseCommit/TwoPhaseCore.spec.js | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/plugins/TwoPhaseCommit/TwoPhaseCore.js b/src/plugins/TwoPhaseCommit/TwoPhaseCore.js index f087db520..406c3c493 100644 --- a/src/plugins/TwoPhaseCommit/TwoPhaseCore.js +++ b/src/plugins/TwoPhaseCommit/TwoPhaseCore.js @@ -420,7 +420,7 @@ define([ TwoPhaseCore.isValidNode = function (node) { const EXPECTED_KEYS = ['parent', 'children', 'relid']; - const isGMENode = typeof node === 'object' && + const isGMENode = node && typeof node === 'object' && EXPECTED_KEYS.reduce((valid, key) => valid && node.hasOwnProperty(key), true); return isGMENode || node instanceof CreatedNode; }; diff --git a/test/unit/plugins/TwoPhaseCommit/TwoPhaseCore.spec.js b/test/unit/plugins/TwoPhaseCommit/TwoPhaseCore.spec.js index b00f6af2b..f2a417c07 100644 --- a/test/unit/plugins/TwoPhaseCommit/TwoPhaseCore.spec.js +++ b/test/unit/plugins/TwoPhaseCommit/TwoPhaseCore.spec.js @@ -213,11 +213,14 @@ describe('TwoPhaseCore', function() { it('should check node types on loadChildren', async function() { const invalidNode = {relid: 'h'}; - try { - await plugin.core.loadChildren(invalidNode); - throw new Error('Did not throw exception.'); - } catch (err) { - } + await assert.rejects(() => plugin.core.loadChildren(invalidNode)); + }); + + it('should have meaningful error on null node', async function() { + assert.throws( + () => plugin.core.getAttribute(null, 'name'), + /Expected node but found/ + ); }); }); });