Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

fix: handle unexpected fal response (#7158)

darkskygitb75da1f3e0b5
diff --git a/packages/backend/server/src/plugins/copilot/providers/fal.ts b/packages/backend/server/src/plugins/copilot/providers/fal.ts
index 9fc1e56630..3f492d4a8a 100644
--- a/packages/backend/server/src/plugins/copilot/providers/fal.ts
+++ b/packages/backend/server/src/plugins/copilot/providers/fal.ts
@@ -26,8 +26,8 @@ const FalImageSchema = z
url: z.string(),
seed: z.number().optional(),
content_type: z.string(),
- file_name: z.string(),
- file_size: z.number(),
+ file_name: z.string().optional(),
+ file_size: z.number().optional(),
width: z.number(),
height: z.number(),
})
@@ -200,8 +200,10 @@ export class FalProvider
if (model.startsWith('workflows/')) {
const stream = await falStream(model, { input: prompt });
- const result = FalStreamOutputSchema.parse(await stream.done());
- return result.output;
+ const result = FalStreamOutputSchema.safeParse(await stream.done());
+ if (result.success) return result.data.output;
+ const errors = JSON.stringify(result.error.errors);
+ throw new Error(`Unexpected fal response: ${errors}`);
} else {
const response = await fetch(`https://fal.run/fal-ai/${model}`, {
method: 'POST',
@@ -217,7 +219,10 @@ export class FalProvider
}),
signal: options.signal,
});
- return FalResponseSchema.parse(await response.json());
+ const result = FalResponseSchema.safeParse(await response.json());
+ if (result.success) return result.data;
+ const errors = JSON.stringify(result.error.errors);
+ throw new Error(`Unexpected fal response: ${errors}`);
}
}