From be10850cef0e7f55e39c8d232ec920495a826f2a Mon Sep 17 00:00:00 2001 From: Khasms <36800359+Khasms@users.noreply.github.com> Date: Sat, 11 Dec 2021 01:02:07 -0800 Subject: [PATCH 1/2] style: improve error messages --- src/interactions/contextMenuCommands/Assertions.ts | 2 +- src/interactions/slashCommands/Assertions.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/interactions/contextMenuCommands/Assertions.ts b/src/interactions/contextMenuCommands/Assertions.ts index 5a22e2f3..1e52f86e 100644 --- a/src/interactions/contextMenuCommands/Assertions.ts +++ b/src/interactions/contextMenuCommands/Assertions.ts @@ -14,7 +14,7 @@ const namePredicate = z .string() .min(1) .max(32) - .regex(/^( *[\p{L}\p{N}_-]+ *)+$/u); + .regex(/^( *[\p{L}\p{N}_-]+ *)+$/u, 'Name must match /^( *[\\p{L}\\p{N}_-]+ *)+$/u'); export function validateName(name: unknown): asserts name is string { namePredicate.parse(name); diff --git a/src/interactions/slashCommands/Assertions.ts b/src/interactions/slashCommands/Assertions.ts index 24f2240e..f032e25a 100644 --- a/src/interactions/slashCommands/Assertions.ts +++ b/src/interactions/slashCommands/Assertions.ts @@ -24,7 +24,7 @@ const namePredicate = z .string() .min(1) .max(32) - .regex(/^[\P{Lu}\p{N}_-]+$/u); + .regex(/^[\P{Lu}\p{N}_-]+$/u, 'Name must match /^[\\P{Lu}\\p{N}_-]+$/u'); export function validateName(name: unknown): asserts name is string { namePredicate.parse(name); From ad16465e98fbbbe8cfa5d58f838f2155d449ecca Mon Sep 17 00:00:00 2001 From: Khasms <36800359+Khasms@users.noreply.github.com> Date: Thu, 16 Dec 2021 12:50:14 -0800 Subject: [PATCH 2/2] style: add more error messages --- src/interactions/contextMenuCommands/Assertions.ts | 2 +- src/interactions/slashCommands/Assertions.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/interactions/contextMenuCommands/Assertions.ts b/src/interactions/contextMenuCommands/Assertions.ts index 1e52f86e..b0ad273d 100644 --- a/src/interactions/contextMenuCommands/Assertions.ts +++ b/src/interactions/contextMenuCommands/Assertions.ts @@ -11,7 +11,7 @@ export function validateRequiredParameters(name: string, type: number) { } const namePredicate = z - .string() + .string({ required_error: 'Name must be provided' }) .min(1) .max(32) .regex(/^( *[\p{L}\p{N}_-]+ *)+$/u, 'Name must match /^( *[\\p{L}\\p{N}_-]+ *)+$/u'); diff --git a/src/interactions/slashCommands/Assertions.ts b/src/interactions/slashCommands/Assertions.ts index f032e25a..3da05521 100644 --- a/src/interactions/slashCommands/Assertions.ts +++ b/src/interactions/slashCommands/Assertions.ts @@ -21,7 +21,7 @@ export function validateRequiredParameters( } const namePredicate = z - .string() + .string({ required_error: 'Name must be provided' }) .min(1) .max(32) .regex(/^[\P{Lu}\p{N}_-]+$/u, 'Name must match /^[\\P{Lu}\\p{N}_-]+$/u'); @@ -30,7 +30,7 @@ export function validateName(name: unknown): asserts name is string { namePredicate.parse(name); } -const descriptionPredicate = z.string().min(1).max(100); +const descriptionPredicate = z.string({ required_error: 'Description must be provided' }).min(1).max(100); export function validateDescription(description: unknown): asserts description is string { descriptionPredicate.parse(description);