diff options
| author | Mohamed Bassem <me@mbassem.com> | 2026-02-08 13:07:16 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-02-08 13:07:16 +0000 |
| commit | 960ca9b67915408f26b825886f2b6c6481a658dc (patch) | |
| tree | 2de224f2b3efaedeba3c979f1bad0ace9e658f15 /packages/trpc/lib/__tests__ | |
| parent | 1a01f75d35abb4aa02edee22e1e5640d3f0aa27c (diff) | |
| download | karakeep-960ca9b67915408f26b825886f2b6c6481a658dc.tar.zst | |
fix: treat bookmark not found as a no-op in rule engine instead of a failure (#2464)
When a bookmark is deleted before the rule engine worker processes its
event, the worker would throw an error, triggering failure metrics,
error logging, and retries. This changes both the worker and
RuleEngine.forBookmark to gracefully skip processing with an info log
instead.
Co-authored-by: Claude <noreply@anthropic.com>
Diffstat (limited to 'packages/trpc/lib/__tests__')
| -rw-r--r-- | packages/trpc/lib/__tests__/ruleEngine.test.ts | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/packages/trpc/lib/__tests__/ruleEngine.test.ts b/packages/trpc/lib/__tests__/ruleEngine.test.ts index d7f216e5..b737e3a5 100644 --- a/packages/trpc/lib/__tests__/ruleEngine.test.ts +++ b/packages/trpc/lib/__tests__/ruleEngine.test.ts @@ -172,10 +172,9 @@ describe("RuleEngine", () => { expect(engine).toBeInstanceOf(RuleEngine); }); - it("should throw an error if bookmark is not found", async () => { - await expect( - RuleEngine.forBookmark(ctx, "nonexistent-bookmark"), - ).rejects.toThrow("Bookmark nonexistent-bookmark not found"); + it("should return null if bookmark is not found", async () => { + const engine = await RuleEngine.forBookmark(ctx, "nonexistent-bookmark"); + expect(engine).toBeNull(); }); it("should load rules associated with the bookmark's user", async () => { @@ -189,7 +188,7 @@ describe("RuleEngine", () => { actions: [{ type: "addTag", tagId: tagId2 }], }); - const engine = await RuleEngine.forBookmark(ctx, bookmarkId); + const engine = (await RuleEngine.forBookmark(ctx, bookmarkId))!; // @ts-expect-error Accessing private property for test verification expect(engine.rules).toHaveLength(1); // @ts-expect-error Accessing private property for test verification @@ -201,7 +200,7 @@ describe("RuleEngine", () => { let engine: RuleEngine; beforeEach(async () => { - engine = await RuleEngine.forBookmark(ctx, bookmarkId); + engine = (await RuleEngine.forBookmark(ctx, bookmarkId))!; }); it("should return true for urlContains condition", () => { @@ -320,7 +319,7 @@ describe("RuleEngine", () => { .update(bookmarks) .set({ favourited: true }) .where(eq(bookmarks.id, bookmarkId)); - const updatedEngine = await RuleEngine.forBookmark(ctx, bookmarkId); + const updatedEngine = (await RuleEngine.forBookmark(ctx, bookmarkId))!; const condition: RuleEngineCondition = { type: "isFavourited" }; expect(updatedEngine.doesBookmarkMatchConditions(condition)).toBe(true); }); @@ -335,7 +334,7 @@ describe("RuleEngine", () => { .update(bookmarks) .set({ archived: true }) .where(eq(bookmarks.id, bookmarkId)); - const updatedEngine = await RuleEngine.forBookmark(ctx, bookmarkId); + const updatedEngine = (await RuleEngine.forBookmark(ctx, bookmarkId))!; const condition: RuleEngineCondition = { type: "isArchived" }; expect(updatedEngine.doesBookmarkMatchConditions(condition)).toBe(true); }); @@ -403,7 +402,7 @@ describe("RuleEngine", () => { } as Omit<RuleEngineRule, "id"> & { userId: string }; ruleId = await seedRule(tmp); testRule = { ...tmp, id: ruleId }; - engine = await RuleEngine.forBookmark(ctx, bookmarkId); + engine = (await RuleEngine.forBookmark(ctx, bookmarkId))!; }); it("should evaluate rule successfully when event and conditions match", async () => { @@ -492,7 +491,7 @@ describe("RuleEngine", () => { let engine: RuleEngine; beforeEach(async () => { - engine = await RuleEngine.forBookmark(ctx, bookmarkId); + engine = (await RuleEngine.forBookmark(ctx, bookmarkId))!; }); it("should execute addTag action", async () => { @@ -674,7 +673,7 @@ describe("RuleEngine", () => { actions: [{ type: "addToList", listId: listId1 }], }); - engine = await RuleEngine.forBookmark(ctx, bookmarkId); + engine = (await RuleEngine.forBookmark(ctx, bookmarkId))!; }); it("should process event and return only results for matching, enabled rules", async () => { |
