Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | 57x 57x 57x 57x 33x 33x 33x 33x 33x 6x 6x 10x 10x 7x 7x 8x 8x 2x 2x 3x 2x 11x 11x 11x 6x 6x 6x 2x 2x 2x 2x | /**
* NodeLLM Error Hierarchy
*
* **Stability Contract**: These error types and their semantics are part of the
* public API and will not change without a major version bump.
*
* - Error names are stable
* - Error codes are stable
* - Error semantics (when they're thrown) are stable
* - New errors may be added (non-breaking)
* - Existing error meanings will not change
*
* @see ARCHITECTURE.md for error contract details
*/
/**
* Base class for all NodeLLM errors
*/
export class LLMError extends Error {
constructor(
message: string,
public readonly code?: string
) {
super(message);
this.name = this.constructor.name;
Error.captureStackTrace(this, this.constructor);
}
}
/**
* Errors occurring during API calls to providers
*/
export class APIError extends LLMError {
constructor(
message: string,
public readonly status: number,
public readonly body: unknown,
public readonly provider?: string,
public readonly model?: string
) {
super(message, "API_ERROR");
}
}
/**
* 400 - Invalid request parameters
*/
export class BadRequestError extends APIError {
constructor(message: string, body: unknown, provider?: string, model?: string) {
super(message, 400, body, provider, model);
this.name = "BadRequestError";
}
}
/**
* 401 - Invalid or missing API key
*/
export class UnauthorizedError extends APIError {
constructor(message: string, body: unknown, provider?: string) {
super(message, 401, body, provider);
this.name = "UnauthorizedError";
}
}
/**
* 402 - Payment required (billing issues)
*/
export class PaymentRequiredError extends APIError {
constructor(message: string, body: unknown, provider?: string) {
super(message, 402, body, provider);
this.name = "PaymentRequiredError";
}
}
/**
* 403 - Permission denied
*/
export class ForbiddenError extends APIError {
constructor(message: string, body: unknown, provider?: string) {
super(message, 403, body, provider);
this.name = "ForbiddenError";
}
}
/**
* 401/403 - API key or permission issues
* @deprecated Use UnauthorizedError (401) or ForbiddenError (403) for granular handling
*/
export class AuthenticationError extends APIError {
constructor(message: string, status: number, body: unknown, provider?: string) {
super(message, status, body, provider);
this.name = "AuthenticationError";
}
}
/**
* 429 - Rate limit exceeded
*/
export class RateLimitError extends APIError {
constructor(message: string, body: unknown, provider?: string, model?: string) {
super(message, 429, body, provider, model);
this.name = "RateLimitError";
}
}
/**
* 500+ - Provider server error
*/
export class ServerError extends APIError {
constructor(message: string, status: number, body: unknown, provider?: string, model?: string) {
super(message, status, body, provider, model);
this.name = "ServerError";
}
}
/**
* 502/503/529 - Service overloaded/unavailable
*/
export class ServiceUnavailableError extends ServerError {
constructor(message: string, status: number, body: unknown, provider?: string, model?: string) {
super(message, status, body, provider, model);
this.name = "ServiceUnavailableError";
}
}
/**
* Misconfiguration (e.g. missing API key)
*/
export class ConfigurationError extends LLMError {
constructor(message: string) {
super(message, "CONFIGURATION_ERROR");
}
}
/**
* Requested model or provider not found
*/
export class NotFoundError extends LLMError {
constructor(message: string) {
super(message, "NOT_FOUND_ERROR");
}
}
/**
* Model does not support requested capability
*/
export class CapabilityError extends LLMError {
constructor(message: string) {
super(message, "CAPABILITY_ERROR");
}
}
/**
* Thrown when LLM provider is not configured
*/
export class ProviderNotConfiguredError extends LLMError {
constructor() {
super("LLM provider not configured", "PROVIDER_NOT_CONFIGURED");
}
}
/**
* Thrown when a provider doesn't support a requested feature
*/
export class UnsupportedFeatureError extends LLMError {
constructor(
public readonly provider: string,
public readonly feature: string
) {
super(`${provider} does not support ${feature}`, "UNSUPPORTED_FEATURE");
}
}
/**
* Thrown when a model doesn't support a requested capability
*/
export class ModelCapabilityError extends LLMError {
constructor(
public readonly model: string,
public readonly capability: string
) {
super(`Model ${model} does not support ${capability}`, "MODEL_CAPABILITY_ERROR");
}
}
/**
* Thrown when a tool execution fails
*/
export class ToolError extends LLMError {
constructor(
message: string,
public readonly toolName?: string,
public readonly fatal: boolean = false
) {
super(message, "TOOL_ERROR");
this.name = "ToolError";
}
}
|