From 603865917bca24a0c222281832d074d801a9865e Mon Sep 17 00:00:00 2001 From: MARCROCK22 Date: Wed, 14 Aug 2024 21:23:09 +0000 Subject: [PATCH] fix: the function was being misused --- src/builders/Attachment.ts | 16 +++++++--------- src/builders/Poll.ts | 3 +-- src/builders/SelectMenu.ts | 3 +-- src/index.ts | 4 ---- 4 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/builders/Attachment.ts b/src/builders/Attachment.ts index 935cf4e..c9ee24b 100644 --- a/src/builders/Attachment.ts +++ b/src/builders/Attachment.ts @@ -1,7 +1,7 @@ import type { APIAttachment, RESTAPIAttachment } from '../types'; import { randomBytes } from 'node:crypto'; import path from 'node:path'; -import { type UsingClient, throwError, type RawFile } from '..'; +import type { UsingClient, RawFile } from '..'; import type { ImageResolvable, ObjectToLower } from '../common'; import { Base } from '../structures/extra/Base'; import { promises } from 'node:fs'; @@ -183,14 +183,14 @@ export async function resolveAttachmentData( }> { if (data instanceof AttachmentBuilder) { if (!data.data.resolvable) - return throwError('The attachment type has been expressed as attachment but cannot be resolved as one.'); + throw new Error('The attachment type has been expressed as attachment but cannot be resolved as one.'); return { data: data.data.resolvable! }; } switch (type) { case 'url': { if (!/^https?:\/\//.test(data as string)) - return throwError( + throw new Error( `The attachment type has been expressed as ${type.toUpperCase()} but cannot be resolved as one.`, ); const res = await fetch(data as string); @@ -200,7 +200,7 @@ export async function resolveAttachmentData( const file = path.resolve(data as string); const stats = await promises.stat(file); if (!stats.isFile()) - return throwError( + throw new Error( `The attachment type has been expressed as ${type.toUpperCase()} but cannot be resolved as one.`, ); return { data: await promises.readFile(file) }; @@ -213,12 +213,10 @@ export async function resolveAttachmentData( for await (const resource of data as unknown as AsyncIterable) buffers.push(Buffer.from(resource)); return { data: Buffer.concat(buffers) }; } - return throwError( - `The attachment type has been expressed as ${type.toUpperCase()} but cannot be resolved as one.`, - ); + throw new Error(`The attachment type has been expressed as ${type.toUpperCase()} but cannot be resolved as one.`); } default: { - return throwError(`The attachment type has been expressed as ${type} but cannot be resolved as one.`); + throw new Error(`The attachment type has been expressed as ${type} but cannot be resolved as one.`); } } } @@ -244,7 +242,7 @@ export async function resolveImage(image: ImageResolvable): Promise { data: { type, resolvable }, } = image; if (type && resolvable) return resolveBase64((await resolveAttachmentData(resolvable, type)).data as Buffer); - return throwError( + throw new Error( `The attachment type has been expressed as ${(type ?? 'Attachment').toUpperCase()} but cannot be resolved as one.`, ); } diff --git a/src/builders/Poll.ts b/src/builders/Poll.ts index e26b6a2..7a19375 100644 --- a/src/builders/Poll.ts +++ b/src/builders/Poll.ts @@ -1,6 +1,5 @@ import { type APIPollMedia, PollLayoutType, type RESTAPIPollCreate } from '../types'; import type { DeepPartial, EmojiResolvable, RestOrArray } from '../common'; -import { throwError } from '..'; import { resolvePartialEmoji } from '../structures/extra/functions'; export class PollBuilder { @@ -45,7 +44,7 @@ export class PollBuilder { private resolvedPollMedia(data: PollMedia) { if (!data.emoji) return { text: data.text }; const resolve = resolvePartialEmoji(data.emoji); - if (!resolve) return throwError('Invalid Emoji'); + if (!resolve) throw new Error('Invalid Emoji'); return { text: data.text, emoji: resolve }; } } diff --git a/src/builders/SelectMenu.ts b/src/builders/SelectMenu.ts index 3abfae9..99dfa2a 100644 --- a/src/builders/SelectMenu.ts +++ b/src/builders/SelectMenu.ts @@ -12,7 +12,6 @@ import { ComponentType, SelectMenuDefaultValueType, } from '../types'; -import { throwError } from '..'; import type { EmojiResolvable, RestOrArray, ToClass } from '../common'; import type { ChannelSelectMenuInteraction, @@ -368,7 +367,7 @@ export class StringSelectOption { */ setEmoji(emoji: EmojiResolvable) { const resolve = resolvePartialEmoji(emoji); - if (!resolve) return throwError('Invalid Emoji'); + if (!resolve) throw new Error('Invalid Emoji'); this.data.emoji = resolve as APIMessageComponentEmoji; return this; } diff --git a/src/index.ts b/src/index.ts index 4570d23..90aee96 100644 --- a/src/index.ts +++ b/src/index.ts @@ -28,10 +28,6 @@ export * from './structures'; export * from './client'; /// -export function throwError(msg: string): never { - throw new Error(msg); -} - /** * Creates an event with the specified data and run function. *