Inline uncaptured errors

This commit is contained in:
Manav Rathi 2024-04-08 14:34:35 +05:30
parent 15e290a993
commit c8089fbb60
No known key found for this signature in database
4 changed files with 5 additions and 10 deletions

View file

@ -15,12 +15,8 @@
export const CustomErrors = {
WINDOWS_NATIVE_IMAGE_PROCESSING_NOT_SUPPORTED:
"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}`,
MODEL_DOWNLOAD_PENDING:
"Model download pending, skipping clip search request",
INVALID_FILE_PATH: "Invalid file path",
INVALID_CLIP_MODEL: (model: string) => `Invalid Clip model - ${model}`,
};

View file

@ -245,14 +245,14 @@ async function computeImageEmbedding_(
inputFilePath: string,
): Promise<Float32Array> {
if (!existsSync(inputFilePath)) {
throw Error(CustomErrors.INVALID_FILE_PATH);
throw new Error("Invalid file path");
}
if (model === Model.GGML_CLIP) {
return await computeGGMLImageEmbedding(inputFilePath);
} else if (model === Model.ONNX_CLIP) {
return await computeONNXImageEmbedding(inputFilePath);
} else {
throw Error(CustomErrors.INVALID_CLIP_MODEL(model));
throw new Error(`Invalid CLIP model ${model}`);
}
}

View file

@ -1,7 +1,6 @@
import pathToFfmpeg from "ffmpeg-static";
import { existsSync } from "node:fs";
import fs from "node:fs/promises";
import { CustomErrors } from "../constants/errors";
import { writeStream } from "../main/fs";
import log from "../main/log";
import { execAsync } from "../main/util";
@ -146,7 +145,7 @@ const promiseWithTimeout = async <T>(
} = { current: null };
const rejectOnTimeout = new Promise<null>((_, reject) => {
timeoutRef.current = setTimeout(
() => reject(Error(CustomErrors.WAIT_TIME_EXCEEDED)),
() => reject(new Error("Operation timed out")),
timeout,
);
});

View file

@ -153,7 +153,7 @@ function constructConvertCommand(
},
);
} else {
throw Error(CustomErrors.INVALID_OS(process.platform));
throw new Error(`Unsupported OS ${process.platform}`);
}
return convertCmd;
}
@ -289,7 +289,7 @@ function constructThumbnailGenerationCommand(
return cmdPart;
});
} else {
throw Error(CustomErrors.INVALID_OS(process.platform));
throw new Error(`Unsupported OS ${process.platform}`);
}
return thumbnailGenerationCmd;
}