Skip to content

Commit 490293c

Browse files
author
kai-agent-free
committed
fix: throw SdkError with CapabilityNotSupported code instead of generic Error
Replace the generic `throw new Error()` in `assertCapability()` with `throw new SdkError(SdkErrorCode.CapabilityNotSupported, ...)` so that callers can programmatically distinguish unsupported-capability errors from other failures without fragile message-string matching. Fixes #430
1 parent 8cdb4bb commit 490293c

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

packages/client/src/client/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ export class Client extends Protocol<ClientContext> {
434434

435435
protected assertCapability(capability: keyof ServerCapabilities, method: string): void {
436436
if (!this._serverCapabilities?.[capability]) {
437-
throw new Error(`Server does not support ${capability} (required for ${method})`);
437+
throw new SdkError(SdkErrorCode.CapabilityNotSupported, `Server does not support ${capability} (required for ${method})`);
438438
}
439439
}
440440

test/integration/test/client/client.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,12 @@ test('should respect server capabilities', async () => {
418418
argument: { name: 'test', value: 'test' }
419419
})
420420
).rejects.toThrow('Server does not support completions');
421+
422+
// Verify that unsupported capability errors are SdkError with CapabilityNotSupported code
423+
await expect(client.listPrompts()).rejects.toThrow(SdkError);
424+
await expect(client.listPrompts()).rejects.toMatchObject({
425+
code: SdkErrorCode.CapabilityNotSupported
426+
});
421427
});
422428

423429
/***

0 commit comments

Comments
 (0)