fix(agent): keep the error code when a request fails without a message

Node 22 rejects a refused connection to a host that resolves to both ::1
and 127.0.0.1 with an AggregateError whose message is empty and whose code
is ECONNREFUSED. The readiness fallback dropped that code, and the agent
CLI's top-level error line and the MCP server's "Cannot reach Codeman"
error printed nothing at all for it.

Add describeRequestError() (message, else code, else a generic line) and
use it at all three sites.
This commit is contained in:
Aamer Akhter committed 2026-10-24 22:39:58 -04:00
1 parent d25d71b595
commit 77ce4816a8
4 files changed
+54 -4

No files matched your search

+11
View File
@@ -248,6 +248,17 @@ describe('protocol: both eras', () => {
expect(result.isError).toBe(true);
expect(result.content[0].text).toContain('CODEMAN_API_URL');
});
it('a refused connection with an empty AggregateError still names the error code', async () => {
const refused: ApiRequest = async () => {
throw Object.assign(new AggregateError([new Error('connect ECONNREFUSED ::1:9')], ''), { code: 'ECONNREFUSED' });
};
const { out, send } = server(config(), { request: refused, calls: [] });
await send({ jsonrpc: '2.0', id: 1, method: 'tools/call', params: { name: 'list_sessions', arguments: {} } });
const result = (out[0] as { result: { isError: boolean; content: Array<{ text: string }> } }).result;
expect(result.isError).toBe(true);
expect(result.content[0].text).toContain('Cannot reach Codeman at http://127.0.0.1:9: ECONNREFUSED.');
});
});
describe('tool definitions', () => {