| /** | |
| * Symbol used for identifying AI SDK Error instances. | |
| * Enables checking if an error is an instance of AISDKError across package versions. | |
| */ | |
| const marker = 'vercel.ai.error'; | |
| const symbol = Symbol.for(marker); | |
| /** | |
| * Custom error class for AI SDK related errors. | |
| * @extends Error | |
| */ | |
| export class AISDKError extends Error { | |
| private readonly [symbol] = true; // used in isInstance | |
| /** | |
| * The underlying cause of the error, if any. | |
| */ | |
| readonly cause?: unknown; | |
| /** | |
| * Creates an AI SDK Error. | |
| * | |
| * @param {Object} params - The parameters for creating the error. | |
| * @param {string} params.name - The name of the error. | |
| * @param {string} params.message - The error message. | |
| * @param {unknown} [params.cause] - The underlying cause of the error. | |
| */ | |
| constructor({ | |
| name, | |
| message, | |
| cause, | |
| }: { | |
| name: string; | |
| message: string; | |
| cause?: unknown; | |
| }) { | |
| super(message); | |
| this.name = name; | |
| this.cause = cause; | |
| } | |
| /** | |
| * Checks if the given error is an AI SDK Error. | |
| * @param {unknown} error - The error to check. | |
| * @returns {boolean} True if the error is an AI SDK Error, false otherwise. | |
| */ | |
| static isInstance(error: unknown): error is AISDKError { | |
| return AISDKError.hasMarker(error, marker); | |
| } | |
| protected static hasMarker(error: unknown, marker: string): boolean { | |
| const markerSymbol = Symbol.for(marker); | |
| return ( | |
| error != null && | |
| typeof error === 'object' && | |
| markerSymbol in error && | |
| typeof error[markerSymbol] === 'boolean' && | |
| error[markerSymbol] === true | |
| ); | |
| } | |
| } | |
Xet Storage Details
- Size:
- 1.6 kB
- Xet hash:
- 105e0efaf3808bef76923d7e91c78d155ee18df3a139c48d52344a5ba54ff489
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.