From b35fbe9fdb95dcce29946e2662f04d23f4cc1b8a Mon Sep 17 00:00:00 2001 From: Abhinav Date: Tue, 21 Nov 2023 12:09:48 +0530 Subject: [PATCH] send parsed clip error to ui --- src/api/clip.ts | 25 +++++++++++++++++++++++-- src/constants/errors.ts | 2 ++ src/services/clipService.ts | 2 ++ src/utils/error.ts | 17 +++++++++++++++++ 4 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 src/utils/error.ts diff --git a/src/api/clip.ts b/src/api/clip.ts index 85a8a4597..0ce673c6d 100644 --- a/src/api/clip.ts +++ b/src/api/clip.ts @@ -1,5 +1,7 @@ import { ipcRenderer } from 'electron'; import { writeStream } from '../services/fs'; +import { isExecError } from '../utils/error'; +import { parseExecError } from '../utils/error'; export async function computeImageEmbedding( imageData: Uint8Array @@ -14,6 +16,13 @@ export async function computeImageEmbedding( tempInputFilePath ); return embedding; + } catch (err) { + if (isExecError(err)) { + const parsedExecError = parseExecError(err); + throw Error(parsedExecError); + } else { + throw err; + } } finally { if (tempInputFilePath) { await ipcRenderer.invoke('remove-temp-file', tempInputFilePath); @@ -24,6 +33,18 @@ export async function computeImageEmbedding( export async function computeTextEmbedding( text: string ): Promise { - const embedding = await ipcRenderer.invoke('compute-text-embedding', text); - return embedding; + try { + const embedding = await ipcRenderer.invoke( + 'compute-text-embedding', + text + ); + return embedding; + } catch (err) { + if (isExecError(err)) { + const parsedExecError = parseExecError(err); + throw Error(parsedExecError); + } else { + throw err; + } + } } diff --git a/src/constants/errors.ts b/src/constants/errors.ts index 7b001aea6..85673ce1b 100644 --- a/src/constants/errors.ts +++ b/src/constants/errors.ts @@ -3,4 +3,6 @@ export const CustomErrors = { 'Windows native image processing is not supported', INVALID_OS: (os: string) => `Invalid OS - ${os}`, WAIT_TIME_EXCEEDED: 'Wait time exceeded', + UNSUPPORTED_PLATFORM: (platform: string, arch: string) => + `Unsupported platform - ${platform} ${arch}`, }; diff --git a/src/services/clipService.ts b/src/services/clipService.ts index 07331a23e..f73493e71 100644 --- a/src/services/clipService.ts +++ b/src/services/clipService.ts @@ -165,6 +165,7 @@ export async function computeImageEmbedding( return embeddingArray; } catch (err) { logErrorSentry(err, 'Error in computeImageEmbedding'); + throw err; } } @@ -200,5 +201,6 @@ export async function computeTextEmbedding( return embeddingArray; } catch (err) { logErrorSentry(err, 'Error in computeTextEmbedding'); + throw err; } } diff --git a/src/utils/error.ts b/src/utils/error.ts new file mode 100644 index 000000000..71904ea0f --- /dev/null +++ b/src/utils/error.ts @@ -0,0 +1,17 @@ +import { CustomErrors } from '../constants/errors'; + +export const isExecError = (err: any) => { + return err.message.includes('Command failed:'); +}; + +export const parseExecError = (err: any) => { + const errMessage = err.message; + if (errMessage.includes('Bad CPU type in executable')) { + return CustomErrors.UNSUPPORTED_PLATFORM( + process.platform, + process.arch + ); + } else { + return errMessage; + } +};