UNPKG

lifxlan

Version:

TypeScript library for controlling LIFX products over LAN

104 lines 2.77 kB
/** * Comprehensive error types for LIFX LAN protocol operations. */ /** * Base class for all LIFX protocol errors. */ export class LifxError extends Error { context; constructor(message, context = {}) { super(message); this.name = this.constructor.name; this.context = context; if (Error.captureStackTrace) { Error.captureStackTrace(this, this.constructor); } } toJSON() { return { name: this.name, message: this.message, context: this.context, stack: this.stack, }; } } /** * Thrown when a network operation times out. */ export class TimeoutError extends LifxError { timeoutMs; operation; constructor(timeoutMs, operation = 'operation') { super(`${operation} timed out after ${timeoutMs}ms`); this.timeoutMs = timeoutMs; this.operation = operation; } } /** * Thrown when a device returns an unhandled command response. */ export class UnhandledCommandError extends LifxError { commandType; deviceSerial; constructor(commandType, deviceSerial) { super(`Device ${deviceSerial || 'unknown'} returned unhandled command type: ${commandType}`); this.commandType = commandType; this.deviceSerial = deviceSerial; } } /** * Thrown when there's a conflict in message routing. */ export class MessageConflictError extends LifxError { key; source; constructor(key, source) { super(`Message routing conflict for key: ${key}`); this.key = key; this.source = source; } } /** * Thrown when router runs out of available source IDs. */ export class SourceExhaustionError extends LifxError { constructor() { super('No more source IDs available. Consider disposing unused clients.'); } } /** * Thrown when attempting to use a disposed client. */ export class DisposedClientError extends LifxError { source; constructor(source) { super(`Cannot use disposed client with source ${source}`); this.source = source; } } /** * Thrown when an operation is aborted via AbortSignal. */ export class AbortError extends LifxError { operation; constructor(operation = 'operation') { super(`${operation} was aborted`); this.operation = operation; } } /** * Thrown when validation of input parameters fails. */ export class ValidationError extends LifxError { parameter; value; reason; constructor(parameter, value, reason) { super(`Invalid ${parameter}: ${value}${reason ? ` (${reason})` : ''}`); this.parameter = parameter; this.value = value; this.reason = reason; } } //# sourceMappingURL=errors.js.map