From 593a37bdfcff8f9ba3bf1cc2892af4c64abd0719 Mon Sep 17 00:00:00 2001 From: Victor Seiji Hariki Date: Mon, 28 Nov 2022 12:44:01 -0300 Subject: [PATCH] add error for non-existent commands Signed-off-by: Victor Seiji Hariki --- js/commands.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/js/commands.js b/js/commands.js index 7f16c06..87f6ea2 100644 --- a/js/commands.js +++ b/js/commands.js @@ -4,6 +4,9 @@ const _commands_events = new Observer(); +/** CommandNonExistentError */ +class CommandNonExistentError extends Error {} + /** Global Commands Object */ const commands = makeReadOnly( { @@ -150,6 +153,10 @@ const commands = makeReadOnly( * @param {any} options The options to be sent to the command to be run */ runCommand(name, title, options = null) { + if (!this._types[name]) + throw CommandNonExistentError( + `[commands] Command '${name}' does not exist` + ); this._types[name](title, options); }, },