From 7f94a3e0555c4cc0f35c815dee24c760018796e1 Mon Sep 17 00:00:00 2001 From: Peter-MJ-Parker <34216187+Peter-MJ-Parker@users.noreply.github.com> Date: Tue, 6 Aug 2024 17:58:08 -0500 Subject: [PATCH] refactor: more clear errors for descriptions --- packages/publisher/index.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/publisher/index.ts b/packages/publisher/index.ts index fb9b3cd..0763083 100644 --- a/packages/publisher/index.ts +++ b/packages/publisher/index.ts @@ -18,11 +18,16 @@ const intoApplicationType = (type: number) => type === 3 ? 1 : Math.log2(type); const makeDescription = (type: number, desc: string) => { - if (type !== CommandType.Text && desc !== '') { - console.warn('Found context menu that has non empty description field. Implictly publishing with empty description'); - return ''; - } - return desc; + if ((type == CommandType.Slash || type == CommandType.Both) && (!desc || desc.length === 0)) { + throw new Error('Found application command that has no description field or is empty.'); + } + if ((type == CommandType.CtxMsg || type == CommandType.CtxUser) && desc.length > 0) { + console.warn( + 'Found context menu that has non empty description field. Implictly publishing with empty description.' + ); + return ''; + } + return desc; }; const serializePerms = (perms: unknown) => {