From f65e7385074979c41b7a480499b4130cadb43d4f Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Mon, 8 Apr 2024 14:42:36 +0530 Subject: [PATCH] Move to types --- desktop/src/constants/errors.ts | 22 ---------------------- desktop/src/services/clipService.ts | 2 +- desktop/src/services/imageProcessor.ts | 2 +- desktop/src/types/ipc.ts | 26 ++++++++++++++++++++++++++ 4 files changed, 28 insertions(+), 24 deletions(-) delete mode 100644 desktop/src/constants/errors.ts diff --git a/desktop/src/constants/errors.ts b/desktop/src/constants/errors.ts deleted file mode 100644 index 14ce2fa8f..000000000 --- a/desktop/src/constants/errors.ts +++ /dev/null @@ -1,22 +0,0 @@ -/** - * [Note: Custom errors across Electron/Renderer boundary] - * - * We need to use the `message` field to disambiguate between errors thrown by - * the main process when invoked from the renderer process. This is because: - * - * > Errors thrown throw `handle` in the main process are not transparent as - * > they are serialized and only the `message` property from the original error - * > is provided to the renderer process. - * > - * > - https://www.electronjs.org/docs/latest/tutorial/ipc - * > - * > Ref: https://github.com/electron/electron/issues/24427 - */ -export const CustomErrors = { - WINDOWS_NATIVE_IMAGE_PROCESSING_NOT_SUPPORTED: - "Windows native image processing is not supported", - UNSUPPORTED_PLATFORM: (platform: string, arch: string) => - `Unsupported platform - ${platform} ${arch}`, - MODEL_DOWNLOAD_PENDING: - "Model download pending, skipping clip search request", -}; diff --git a/desktop/src/services/clipService.ts b/desktop/src/services/clipService.ts index 7d05c17e0..2c70c7296 100644 --- a/desktop/src/services/clipService.ts +++ b/desktop/src/services/clipService.ts @@ -2,7 +2,7 @@ import { app, net } from "electron/main"; import { existsSync } from "fs"; import fs from "node:fs/promises"; import path from "node:path"; -import { CustomErrors } from "../constants/errors"; +import { CustomErrors } from "../types/ipc"; import { writeStream } from "../main/fs"; import log from "../main/log"; import { execAsync, isDev } from "../main/util"; diff --git a/desktop/src/services/imageProcessor.ts b/desktop/src/services/imageProcessor.ts index a7e9f5a1c..630db9724 100644 --- a/desktop/src/services/imageProcessor.ts +++ b/desktop/src/services/imageProcessor.ts @@ -1,7 +1,7 @@ import { existsSync } from "fs"; import fs from "node:fs/promises"; import path from "path"; -import { CustomErrors } from "../constants/errors"; +import { CustomErrors } from "../types/ipc"; import { writeStream } from "../main/fs"; import log from "../main/log"; import { execAsync, isDev } from "../main/util"; diff --git a/desktop/src/types/ipc.ts b/desktop/src/types/ipc.ts index 93586f29a..16869c25c 100644 --- a/desktop/src/types/ipc.ts +++ b/desktop/src/types/ipc.ts @@ -4,6 +4,32 @@ * This file is manually kept in sync with the renderer code. * See [Note: types.ts <-> preload.ts <-> ipc.ts] */ + +/** + * Errors that have special semantics on the web side. + * + * [Note: Custom errors across Electron/Renderer boundary] + * + * We need to use the `message` field to disambiguate between errors thrown by + * the main process when invoked from the renderer process. This is because: + * + * > Errors thrown throw `handle` in the main process are not transparent as + * > they are serialized and only the `message` property from the original error + * > is provided to the renderer process. + * > + * > - https://www.electronjs.org/docs/latest/tutorial/ipc + * > + * > Ref: https://github.com/electron/electron/issues/24427 + */ +export const CustomErrors = { + WINDOWS_NATIVE_IMAGE_PROCESSING_NOT_SUPPORTED: + "Windows native image processing is not supported", + UNSUPPORTED_PLATFORM: (platform: string, arch: string) => + `Unsupported platform - ${platform} ${arch}`, + MODEL_DOWNLOAD_PENDING: + "Model download pending, skipping clip search request", +}; + /** * Deprecated - Use File + webUtils.getPathForFile instead *