fix(vector-stores): prevent unhandled promise rejection in Supabase & Redis constructors (#6111)
This commit is contained in:
@@ -197,7 +197,6 @@ export class RedisDB implements VectorStore {
|
|||||||
|
|
||||||
this.initialize().catch((err) => {
|
this.initialize().catch((err) => {
|
||||||
console.error("Failed to initialize Redis:", err);
|
console.error("Failed to initialize Redis:", err);
|
||||||
throw err;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -96,7 +96,6 @@ export class SupabaseDB implements VectorStore {
|
|||||||
|
|
||||||
this.initialize().catch((err) => {
|
this.initialize().catch((err) => {
|
||||||
console.error("Failed to initialize Supabase:", err);
|
console.error("Failed to initialize Supabase:", err);
|
||||||
throw err;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -600,6 +600,45 @@ describe("Supabase – backward compat with mocked client", () => {
|
|||||||
await Promise.all([p1, p2]);
|
await Promise.all([p1, p2]);
|
||||||
// No crash = idempotent (Supabase init runs test insert only once)
|
// 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([]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// ───────────────────────────────────────────────────────────────────────────
|
// ───────────────────────────────────────────────────────────────────────────
|
||||||
|
|||||||
Reference in New Issue
Block a user