diff --git a/dist/cjs/device/Capability.js b/dist/cjs/device/Capability.js index bcedbca..923f645 100644 --- a/dist/cjs/device/Capability.js +++ b/dist/cjs/device/Capability.js @@ -36,8 +36,9 @@ class Capability { if (name !== "*" && this.descriptor.tier !== 3 && !names.includes(name)) { throw new types_js_1.DeclarationError(this, `${name} is not a directive of the interface, which has ${names.join(", ") || "none"}`); } - if (typeof handler !== "function") - throw new types_js_1.DeclarationError(this, `the handler of ${name} is a function`); + if (typeof handler !== "function") { + throw new types_js_1.DeclarationError(this, `on("${name}") got ${handler === null ? "null" : typeof handler} as the handler: pass a function that takes the context of the directive`); + } this.handlers.set(name, handler); return this; } diff --git a/dist/esm/device/Capability.js b/dist/esm/device/Capability.js index 8eb316b..ecbb7a3 100644 --- a/dist/esm/device/Capability.js +++ b/dist/esm/device/Capability.js @@ -33,8 +33,9 @@ export class Capability { if (name !== "*" && this.descriptor.tier !== 3 && !names.includes(name)) { throw new DeclarationError(this, `${name} is not a directive of the interface, which has ${names.join(", ") || "none"}`); } - if (typeof handler !== "function") - throw new DeclarationError(this, `the handler of ${name} is a function`); + if (typeof handler !== "function") { + throw new DeclarationError(this, `on("${name}") got ${handler === null ? "null" : typeof handler} as the handler: pass a function that takes the context of the directive`); + } this.handlers.set(name, handler); return this; } diff --git a/src/device/Capability.ts b/src/device/Capability.ts index ceca181..c4c427b 100644 --- a/src/device/Capability.ts +++ b/src/device/Capability.ts @@ -101,7 +101,9 @@ export class Capability
power.on("Toggle", by("Toggle")), (err) => err instanceof DeclarationError && err.message === "lamp-1: Alexa.PowerController: Toggle is not a directive of the interface, which has TurnOn, TurnOff"); + assert.throws(() => power.on("TurnOff"), (err) => err instanceof DeclarationError + && err.message === "lamp-1: Alexa.PowerController: on(\"TurnOff\") got undefined as the handler: pass a function that takes the context of the directive"); }); test("a handler that throws or rejects answers INTERNAL_ERROR, the bridge reports what it threw, and nothing is left unhandled", async () => {