mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 03:23:29 +01:00
Improve structure extension errors
This commit is contained in:
@@ -45,17 +45,22 @@ class Structures {
|
|||||||
if (typeof extender !== 'function') {
|
if (typeof extender !== 'function') {
|
||||||
const received = `(received ${typeof extender})`;
|
const received = `(received ${typeof extender})`;
|
||||||
throw new TypeError(
|
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]);
|
const extended = extender(structures[structure]);
|
||||||
if (typeof extended !== 'function') {
|
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(
|
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}).`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user