/** * SDK error hierarchy. Adapters (and tests) `instanceof`-check against these * to distinguish predictable failure modes from genuine bugs. */ export class SDKError extends Error { public override readonly cause?: unknown; constructor(message: string, cause?: unknown) { super(message); this.name = "SDKError"; if (cause !== undefined) this.cause = cause; } } /** * Thrown by `appendMessage` on any duplicate key, and by `idempotentAppend` * only when the duplicate has a different canonical-JSON byte sequence. * * `existingBytes` and `attemptedBytes` capture what was stored vs what we * tried to write — useful for debugging conflict storms. */ export class MessageIDConflict extends SDKError { constructor( public readonly taskId: string, public readonly messageId: string, public readonly existingBytes: Uint8Array, public readonly attemptedBytes: Uint8Array, ) { super(`message ${messageId} already exists in task ${taskId} with different content`); this.name = "MessageIDConflict"; } } export class ObjectURLError extends SDKError { constructor(message: string, cause?: unknown) { super(message, cause); this.name = "ObjectURLError"; } } export class MaterializePartError extends SDKError { constructor(message: string, cause?: unknown) { super(message, cause); this.name = "MaterializePartError"; } }