Skip to content

Commit d37352c

Browse files
committed
Refactor Health Service to Remove Redundant Try/Catch #7527
1 parent 31de4de commit d37352c

2 files changed

Lines changed: 29 additions & 9 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
title: "Refactor Health Service to Remove Redundant Try/Catch"
3+
labels: enhancement, AI
4+
---
5+
6+
Parent epic: #7520
7+
GH ticket id: #7514
8+
9+
**Phase:** 2
10+
**Assignee:** tobiu
11+
**Status:** To Do
12+
13+
## Description
14+
15+
The `buildHealthResponse` function in `healthService.mjs` contains two inner `try...catch` blocks that are redundant. The empty `catch` blocks obscure the logic. This ticket is to remove them for clarity.
16+
17+
## Acceptance Criteria
18+
19+
1. The `buildHealthResponse` function in `healthService.mjs` is updated.
20+
2. The two inner `try...catch` blocks are removed.
21+
3. The logic remains correct: if a collection doesn't exist, its `exists` flag is correctly reported as `false` and its `count` as `0`.

ai/mcp/server/memory-core/services/healthService.mjs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import chromaManager from './chromaManager.mjs';
2+
import aiConfig from '../../../../../buildScripts/ai/aiConfig.mjs';
23

34
/**
45
* Verifies that the server is running and can successfully connect to the
@@ -12,18 +13,16 @@ export async function buildHealthResponse() {
1213
let memoryCollection, summaryCollection;
1314
let memoryCount = 0, summaryCount = 0;
1415

15-
try {
16-
memoryCollection = await chromaManager.getMemoryCollection();
16+
// These calls will throw if the collection doesn't exist. We let the outer block catch it
17+
// if it's a connection issue, but for "not found", we handle it gracefully.
18+
memoryCollection = await chromaManager.getMemoryCollection().catch(() => null);
19+
if (memoryCollection) {
1720
memoryCount = await memoryCollection.count();
18-
} catch (e) {
19-
// Collection does not exist, which is a valid state.
2021
}
2122

22-
try {
23-
summaryCollection = await chromaManager.getSummaryCollection();
23+
summaryCollection = await chromaManager.getSummaryCollection().catch(() => null);
24+
if (summaryCollection) {
2425
summaryCount = await summaryCollection.count();
25-
} catch (e) {
26-
// Collection does not exist.
2726
}
2827

2928
return {
@@ -55,4 +54,4 @@ export async function buildHealthResponse() {
5554
}
5655
};
5756
}
58-
}
57+
}

0 commit comments

Comments
 (0)