Skip to content

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Fix silent error handling in getToolkits - throw errors instead of returning empty array

Sushmithamalleshb0f5b358ac3b
diff --git a/fumadocs/app/(home)/toolkits/[[...slug]]/page.tsx b/fumadocs/app/(home)/toolkits/[[...slug]]/page.tsx
index a3ae62763..7619f4a2e 100644
--- a/fumadocs/app/(home)/toolkits/[[...slug]]/page.tsx
+++ b/fumadocs/app/(home)/toolkits/[[...slug]]/page.tsx
@@ -9,12 +9,30 @@ import type { Metadata } from 'next';
import type { Toolkit } from '@/types/toolkit';
async function getToolkits(): Promise<Toolkit[]> {
+ const filePath = join(process.cwd(), 'public/data/toolkits.json');
+
try {
- const filePath = join(process.cwd(), 'public/data/toolkits.json');
const data = await readFile(filePath, 'utf-8');
- return JSON.parse(data);
- } catch {
- return [];
+ const toolkits = JSON.parse(data) as Toolkit[];
+
+ if (!Array.isArray(toolkits)) {
+ throw new Error('toolkits.json must contain an array');
+ }
+
+ if (toolkits.length === 0) {
+ console.warn('[Toolkits] Warning: toolkits.json is empty');
+ }
+
+ return toolkits;
+ } catch (error) {
+ const err = error as NodeJS.ErrnoException;
+ if (err.code === 'ENOENT') {
+ throw new Error(`Toolkits data file not found: ${filePath}`);
+ }
+ if (error instanceof SyntaxError) {
+ throw new Error(`Invalid JSON in toolkits.json: ${error.message}`);
+ }
+ throw error;
}
}