From 04fa56d0c07b66c77d0fdd6cb4419efb890043eb Mon Sep 17 00:00:00 2001 From: Schuyler Cebulskie Date: Sun, 24 Mar 2019 16:45:34 -0400 Subject: [PATCH] Improve structure extension errors --- src/util/Structures.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/util/Structures.js b/src/util/Structures.js index 4ac562606..62646b404 100644 --- a/src/util/Structures.js +++ b/src/util/Structures.js @@ -45,17 +45,22 @@ class Structures { if (typeof extender !== 'function') { const received = `(received ${typeof extender})`; throw new TypeError( - `"extender" argument must be a function that returns the extended structure class/prototype ${received}` + `"extender" argument must be a function that returns the extended structure class/prototype ${received}.` ); } const extended = extender(structures[structure]); if (typeof extended !== 'function') { - throw new TypeError('The extender function must return the extended structure class/prototype.'); + const received = `(received ${typeof extended})`; + throw new TypeError(`The extender function must return the extended structure class/prototype ${received}.`); } - if (Object.getPrototypeOf(extended) !== structures[structure]) { + + const prototype = Object.getPrototypeOf(extended); + if (prototype !== structures[structure]) { + const received = `${extended.name || 'unnamed'}${prototype.name ? ` extends ${prototype.name}` : ''}`; throw new Error( - 'The class/prototype returned from the extender function must extend the existing structure class/prototype.' + 'The class/prototype returned from the extender function must extend the existing structure class/prototype' + + ` (received function ${received}; expected extension of ${structures[structure].name}).` ); }