Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

send parsed clip error to ui

Abhinavb35fbe9fdb95
diff --git a/src/api/clip.ts b/src/api/clip.ts
index 85a8a45979..0ce673c6d3 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<Float32Array> {
- 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 7b001aea68..85673ce1b1 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 07331a23ee..f73493e717 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 0000000000..71904ea0f2
--- /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;
+ }
+};