Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions bin/codedb-bridge.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,16 @@ export const createHandler = ({ fetchFn, daemonUrl }) => {
if (!res.ok || data?.error) {
return textResult(`codedb daemon error for ${name}: ${data?.error ?? `HTTP ${res.status}`}`, true);
}
// A 200 body that is null or not a JSON object is a daemon malfunction,
// not a result (#6917): the tree path dereferences data.tree (a raw
// TypeError escapes handle() and the caller never gets a response),
// and the JSON paths would report the literal text "null" as success.
if (!data || typeof data !== 'object' || Array.isArray(data)) {
return textResult(
`codedb daemon at ${daemonUrl} returned a ${data === null ? 'null' : Array.isArray(data) ? 'array' : typeof data} JSON body for ${mapped.route}; expected a JSON object`,
true
);
}
try {
data = sliceData(data, mapped.slice);
} catch (err) {
Expand Down
24 changes: 24 additions & 0 deletions bin/codedb-bridge.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,27 @@ test('daemon errors and an unreachable daemon surface as MCP errors naming the c
assert.equal(badArg.result.isError, true);
assert.match(badArg.result.content[0].text, /"regex"/);
});

test('null or non-object daemon bodies are isError results, never a throw or a "null" success (#6917)', async () => {
const handle = createHandler({
fetchFn: stubFetch({
'/explore/tree': null,
'/explore/search?q=x': null,
'/explore/outline?path=a.ts': 'weird',
'/explore/hot': [1, 2],
}),
daemonUrl: 'http://127.0.0.1:7719',
});
const tree = await call(handle, 'codedb_tree', {});
assert.equal(tree.result.isError, true);
assert.match(tree.result.content[0].text, /null JSON body for \/explore\/tree/);
const search = await call(handle, 'codedb_search', { query: 'x' });
assert.equal(search.result.isError, true);
assert.match(search.result.content[0].text, /null JSON body/);
const outline = await call(handle, 'codedb_outline', { path: 'a.ts' });
assert.equal(outline.result.isError, true);
assert.match(outline.result.content[0].text, /string JSON body/);
const hot = await call(handle, 'codedb_hot', {});
assert.equal(hot.result.isError, true);
assert.match(hot.result.content[0].text, /array JSON body/);
});
Loading