Skip to content

Commit

Permalink
Better error message on null node. Fixes #1875 (#1876)
Browse files Browse the repository at this point in the history
  • Loading branch information
brollb authored Aug 20, 2020
1 parent 3190598 commit a1e20f8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/plugins/TwoPhaseCommit/TwoPhaseCore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
13 changes: 8 additions & 5 deletions test/unit/plugins/TwoPhaseCommit/TwoPhaseCore.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/
);
});
});
});

0 comments on commit a1e20f8

Please sign in to comment.