From 2bd3ff1eff520f302229686eff5b823cf1f6ba59 Mon Sep 17 00:00:00 2001 From: Kartik Date: Mon, 6 Jul 2026 14:57:30 +0530 Subject: [PATCH] fix(vector-stores): prevent unhandled promise rejection in Supabase & Redis constructors (#6111) --- mem0-ts/src/oss/src/vector_stores/redis.ts | 1 - mem0-ts/src/oss/src/vector_stores/supabase.ts | 1 - .../oss/tests/vector-stores-compat.test.ts | 39 +++++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/mem0-ts/src/oss/src/vector_stores/redis.ts b/mem0-ts/src/oss/src/vector_stores/redis.ts index deae5e3ac..5b72e53b5 100644 --- a/mem0-ts/src/oss/src/vector_stores/redis.ts +++ b/mem0-ts/src/oss/src/vector_stores/redis.ts @@ -197,7 +197,6 @@ export class RedisDB implements VectorStore { this.initialize().catch((err) => { console.error("Failed to initialize Redis:", err); - throw err; }); } diff --git a/mem0-ts/src/oss/src/vector_stores/supabase.ts b/mem0-ts/src/oss/src/vector_stores/supabase.ts index 3e357c575..748fe8283 100644 --- a/mem0-ts/src/oss/src/vector_stores/supabase.ts +++ b/mem0-ts/src/oss/src/vector_stores/supabase.ts @@ -96,7 +96,6 @@ export class SupabaseDB implements VectorStore { this.initialize().catch((err) => { console.error("Failed to initialize Supabase:", err); - throw err; }); } diff --git a/mem0-ts/src/oss/tests/vector-stores-compat.test.ts b/mem0-ts/src/oss/tests/vector-stores-compat.test.ts index a9ecda1b1..81c9c7f34 100644 --- a/mem0-ts/src/oss/tests/vector-stores-compat.test.ts +++ b/mem0-ts/src/oss/tests/vector-stores-compat.test.ts @@ -600,6 +600,45 @@ describe("Supabase – backward compat with mocked client", () => { await Promise.all([p1, p2]); // No crash = idempotent (Supabase init runs test insert only once) }); + + it("constructor does not emit an unhandled rejection when init fails", async () => { + jest.resetModules(); + jest.doMock("@supabase/supabase-js", () => { + const failing = { + from: jest.fn().mockReturnValue({ + insert: jest.fn().mockReturnValue({ + select: jest.fn().mockResolvedValue({ + error: { code: "42P01", message: "no table" }, + }), + }), + delete: jest.fn().mockReturnValue({ + eq: jest.fn().mockResolvedValue({ error: null }), + }), + }), + }; + return { createClient: jest.fn().mockReturnValue(failing) }; + }); + const FailingSupabaseDB = + require("../src/vector_stores/supabase").SupabaseDB; + + const rejections: unknown[] = []; + const onUnhandled = (reason: unknown) => rejections.push(reason); + process.on("unhandledRejection", onUnhandled); + try { + const store = new FailingSupabaseDB({ + supabaseUrl: "https://example.supabase.co", + supabaseKey: "fake-key", + tableName: "memories", + collectionName: "test", + }); + expect(store).toBeDefined(); + await new Promise((resolve) => setTimeout(resolve, 25)); + } finally { + process.removeListener("unhandledRejection", onUnhandled); + } + + expect(rejections).toEqual([]); + }); }); // ───────────────────────────────────────────────────────────────────────────