Skip to content

Commit c71a6e8

Browse files
committed
add missing File error handling
1 parent fc3f457 commit c71a6e8

File tree

1 file changed

+18
-4
lines changed
  • templates/components/vectordbs/typescript/llamacloud

1 file changed

+18
-4
lines changed

templates/components/vectordbs/typescript/llamacloud/generate.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,24 @@ async function loadAndIndex() {
3232
for await (const filePath of walk(DATA_DIR)) {
3333
const buffer = await fs.readFile(filePath);
3434
const filename = path.basename(filePath);
35-
const file = new File([buffer], filename);
36-
await LLamaCloudFileService.addFileToPipeline(projectId, pipelineId, file, {
37-
private: "false",
38-
});
35+
try {
36+
await LLamaCloudFileService.addFileToPipeline(
37+
projectId,
38+
pipelineId,
39+
new File([buffer], filename),
40+
{ private: "false" },
41+
);
42+
} catch (error) {
43+
if (
44+
error instanceof ReferenceError &&
45+
error.message.includes("File is not defined")
46+
) {
47+
throw new Error(
48+
"File class is not supported in the current Node.js version. Please use Node.js 20 or higher.",
49+
);
50+
}
51+
throw error;
52+
}
3953
}
4054

4155
console.log(`Successfully uploaded documents to LlamaCloud!`);

0 commit comments

Comments
 (0)