This commit is contained in:
Eason Goodale
2025-04-19 22:55:37 -07:00
parent 2bcc15a839
commit 1e0a7cc313
7 changed files with 168 additions and 39 deletions

View File

@@ -20,7 +20,23 @@ export async function createInputItem(
for (const filePath of images) {
/* eslint-disable no-await-in-loop */
const binary = await fs.readFile(filePath);
let binary: Buffer;
try {
binary = await fs.readFile(filePath);
} catch (err: unknown) {
// Gracefully skip files that no longer exist on disk. This can happen
// when an image was attached earlier but has since been moved or
// deleted before the user submitted the prompt. For any other error
// codes rethrow so callers are still notified of unexpected issues
// (e.g. permission errors).
const e = err as NodeJS.ErrnoException;
if (e?.code === "ENOENT") {
// Skip silently user will simply not include the missing image.
continue;
}
throw err as Error;
}
const kind = await fileTypeFromBuffer(binary);
/* eslint-enable no-await-in-loop */
const encoded = binary.toString("base64");