send parsed clip error to ui
This commit is contained in:
parent
62814e1334
commit
b35fbe9fdb
4 changed files with 44 additions and 2 deletions
|
@ -1,5 +1,7 @@
|
||||||
import { ipcRenderer } from 'electron';
|
import { ipcRenderer } from 'electron';
|
||||||
import { writeStream } from '../services/fs';
|
import { writeStream } from '../services/fs';
|
||||||
|
import { isExecError } from '../utils/error';
|
||||||
|
import { parseExecError } from '../utils/error';
|
||||||
|
|
||||||
export async function computeImageEmbedding(
|
export async function computeImageEmbedding(
|
||||||
imageData: Uint8Array
|
imageData: Uint8Array
|
||||||
|
@ -14,6 +16,13 @@ export async function computeImageEmbedding(
|
||||||
tempInputFilePath
|
tempInputFilePath
|
||||||
);
|
);
|
||||||
return embedding;
|
return embedding;
|
||||||
|
} catch (err) {
|
||||||
|
if (isExecError(err)) {
|
||||||
|
const parsedExecError = parseExecError(err);
|
||||||
|
throw Error(parsedExecError);
|
||||||
|
} else {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (tempInputFilePath) {
|
if (tempInputFilePath) {
|
||||||
await ipcRenderer.invoke('remove-temp-file', tempInputFilePath);
|
await ipcRenderer.invoke('remove-temp-file', tempInputFilePath);
|
||||||
|
@ -24,6 +33,18 @@ export async function computeImageEmbedding(
|
||||||
export async function computeTextEmbedding(
|
export async function computeTextEmbedding(
|
||||||
text: string
|
text: string
|
||||||
): Promise<Float32Array> {
|
): Promise<Float32Array> {
|
||||||
const embedding = await ipcRenderer.invoke('compute-text-embedding', text);
|
try {
|
||||||
|
const embedding = await ipcRenderer.invoke(
|
||||||
|
'compute-text-embedding',
|
||||||
|
text
|
||||||
|
);
|
||||||
return embedding;
|
return embedding;
|
||||||
|
} catch (err) {
|
||||||
|
if (isExecError(err)) {
|
||||||
|
const parsedExecError = parseExecError(err);
|
||||||
|
throw Error(parsedExecError);
|
||||||
|
} else {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,4 +3,6 @@ export const CustomErrors = {
|
||||||
'Windows native image processing is not supported',
|
'Windows native image processing is not supported',
|
||||||
INVALID_OS: (os: string) => `Invalid OS - ${os}`,
|
INVALID_OS: (os: string) => `Invalid OS - ${os}`,
|
||||||
WAIT_TIME_EXCEEDED: 'Wait time exceeded',
|
WAIT_TIME_EXCEEDED: 'Wait time exceeded',
|
||||||
|
UNSUPPORTED_PLATFORM: (platform: string, arch: string) =>
|
||||||
|
`Unsupported platform - ${platform} ${arch}`,
|
||||||
};
|
};
|
||||||
|
|
|
@ -165,6 +165,7 @@ export async function computeImageEmbedding(
|
||||||
return embeddingArray;
|
return embeddingArray;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logErrorSentry(err, 'Error in computeImageEmbedding');
|
logErrorSentry(err, 'Error in computeImageEmbedding');
|
||||||
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,5 +201,6 @@ export async function computeTextEmbedding(
|
||||||
return embeddingArray;
|
return embeddingArray;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logErrorSentry(err, 'Error in computeTextEmbedding');
|
logErrorSentry(err, 'Error in computeTextEmbedding');
|
||||||
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
17
src/utils/error.ts
Normal file
17
src/utils/error.ts
Normal file
|
@ -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;
|
||||||
|
}
|
||||||
|
};
|
Loading…
Add table
Reference in a new issue