Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | import { describe, it, expect } from 'vitest'; |
| 2 | import { KeyringError } from '../src/core/errors'; |
| 3 | |
| 4 | describe('KeyringError', () => { |
| 5 | it('exposes kind via getter and .is() predicate', () => { |
| 6 | const err = new KeyringError({ kind: 'NoEntry' }); |
| 7 | expect(err.kind).toBe('NoEntry'); |
| 8 | expect(err.is('NoEntry')).toBe(true); |
| 9 | expect(err.is('PlatformFailure')).toBe(false); |
| 10 | }); |
| 11 | |
| 12 | it('preserves the underlying cause chain for PlatformFailure', () => { |
| 13 | const inner = new Error('boom'); |
| 14 | const err = new KeyringError({ kind: 'PlatformFailure', cause: inner }); |
| 15 | expect((err as { cause?: unknown }).cause).toBe(inner); |
| 16 | expect(err.message).toContain('boom'); |
| 17 | }); |
| 18 | |
| 19 | it('formats a readable message for every variant', () => { |
| 20 | const cases: KeyringError[] = [ |
| 21 | new KeyringError({ kind: 'NoEntry' }), |
| 22 | new KeyringError({ kind: 'NoDefaultStore' }), |
| 23 | new KeyringError({ kind: 'PlatformFailure', cause: new Error('x') }), |
| 24 | new KeyringError({ kind: 'NoStorageAccess', cause: 'locked' }), |
| 25 | new KeyringError({ kind: 'BadEncoding', bytes: new Uint8Array([0xff, 0xfe]) }), |
| 26 | new KeyringError({ |
| 27 | kind: 'BadDataFormat', |
| 28 | bytes: new Uint8Array(), |
| 29 | cause: new Error('nope'), |
| 30 | }), |
| 31 | new KeyringError({ kind: 'BadStoreFormat', detail: 'corrupt' }), |
| 32 | new KeyringError({ kind: 'TooLong', attr: 'service', limit: 1024 }), |
| 33 | new KeyringError({ kind: 'Invalid', param: 'user', reason: 'empty' }), |
| 34 | new KeyringError({ kind: 'Ambiguous', matches: [] }), |
| 35 | new KeyringError({ kind: 'NotSupportedByStore', operation: 'updateAttributes' }), |
| 36 | ]; |
| 37 | for (const err of cases) { |
| 38 | expect(err.message.length).toBeGreaterThan(0); |
| 39 | expect(err.name).toBe('KeyringError'); |
| 40 | } |
| 41 | }); |
| 42 | }); |