From 6846371810d7638d85bb797f7680e86e2e3ada0a Mon Sep 17 00:00:00 2001 From: artie Date: Tue, 18 Feb 2025 19:32:21 +0100 Subject: [PATCH] notify about other errors --- src/commands/language/translate.ts | 3 ++- src/commands/ocr/ocr.ts | 3 ++- src/events/interactionCreate.ts | 2 +- src/utils/error.ts | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/commands/language/translate.ts b/src/commands/language/translate.ts index 75bb8d9..caa1d84 100644 --- a/src/commands/language/translate.ts +++ b/src/commands/language/translate.ts @@ -13,7 +13,7 @@ import { isTargetLanguage, translate as translateDeepl, } from "../../utils/deepl"; -import { abort } from "../../utils/error"; +import { abort, notifyError } from "../../utils/error"; import type { OCRResult } from "../../types/ocr"; import { capitalize, languageCodeToName } from "../../utils/functions"; import { translate as translateGoogle } from "../../utils/gtrans"; @@ -52,6 +52,7 @@ export async function translateImpl( target ).catch(err => { logger.error(err, "DeepL error, falling back to Google Translate"); + notifyError(err); return translateGoogle(text, "auto", "en"); }); diff --git a/src/commands/ocr/ocr.ts b/src/commands/ocr/ocr.ts index 64abd6b..306e99e 100644 --- a/src/commands/ocr/ocr.ts +++ b/src/commands/ocr/ocr.ts @@ -6,7 +6,7 @@ import { } from "discord.js"; import { defineCommand } from ".."; import { downloadFile } from "../../utils/http"; -import { abort } from "../../utils/error"; +import { abort, notifyError } from "../../utils/error"; import { yandexOcr } from "../../utils/yandex"; import sharp from "sharp"; import { @@ -88,6 +88,7 @@ export async function ocrImpl(url: string) { const result = await lensOcr(compressed) .catch(err => { logger.error(err, "Google Lens error, falling back to Yandex"); + notifyError(err); return yandexOcr(compressed, type.mime); }) .catch(() => abort("Failed to OCR the image")); diff --git a/src/events/interactionCreate.ts b/src/events/interactionCreate.ts index ba88611..e918c3d 100644 --- a/src/events/interactionCreate.ts +++ b/src/events/interactionCreate.ts @@ -75,7 +75,7 @@ async function handleChatInputCommand( const trace = nanoid(); content += `\ntrace: ${inlineCode(trace)}`; logger.error({ trace, err }); - notifyError(trace, err); + notifyError(err, trace); } await interaction[ diff --git a/src/utils/error.ts b/src/utils/error.ts index bf60009..39bdc26 100644 --- a/src/utils/error.ts +++ b/src/utils/error.ts @@ -14,7 +14,7 @@ export function isExplicitCommandError( return error instanceof ExplicitCommandError; } -export async function notifyError(trace: string, error: any) { +export async function notifyError(error: any, trace?: string) { return (client.channels.cache.get(env.DEV_CHANNEL_ID) as TextChannel).send({ content: trace, embeds: [