UNPKG

lifxlan

Version:

TypeScript library for controlling LIFX products over LAN

115 lines 3.37 kB
"use strict"; /** * Comprehensive error types for LIFX LAN protocol operations. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.ValidationError = exports.AbortError = exports.DisposedClientError = exports.SourceExhaustionError = exports.MessageConflictError = exports.UnhandledCommandError = exports.TimeoutError = exports.LifxError = void 0; /** * Base class for all LIFX protocol errors. */ 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, }; } } exports.LifxError = LifxError; /** * Thrown when a network operation times out. */ class TimeoutError extends LifxError { timeoutMs; operation; constructor(timeoutMs, operation = 'operation') { super(`${operation} timed out after ${timeoutMs}ms`); this.timeoutMs = timeoutMs; this.operation = operation; } } exports.TimeoutError = TimeoutError; /** * Thrown when a device returns an unhandled command response. */ class UnhandledCommandError extends LifxError { commandType; deviceSerial; constructor(commandType, deviceSerial) { super(`Device ${deviceSerial || 'unknown'} returned unhandled command type: ${commandType}`); this.commandType = commandType; this.deviceSerial = deviceSerial; } } exports.UnhandledCommandError = UnhandledCommandError; /** * Thrown when there's a conflict in message routing. */ class MessageConflictError extends LifxError { key; source; constructor(key, source) { super(`Message routing conflict for key: ${key}`); this.key = key; this.source = source; } } exports.MessageConflictError = MessageConflictError; /** * Thrown when router runs out of available source IDs. */ class SourceExhaustionError extends LifxError { constructor() { super('No more source IDs available. Consider disposing unused clients.'); } } exports.SourceExhaustionError = SourceExhaustionError; /** * Thrown when attempting to use a disposed client. */ class DisposedClientError extends LifxError { source; constructor(source) { super(`Cannot use disposed client with source ${source}`); this.source = source; } } exports.DisposedClientError = DisposedClientError; /** * Thrown when an operation is aborted via AbortSignal. */ class AbortError extends LifxError { operation; constructor(operation = 'operation') { super(`${operation} was aborted`); this.operation = operation; } } exports.AbortError = AbortError; /** * Thrown when validation of input parameters fails. */ 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; } } exports.ValidationError = ValidationError; //# sourceMappingURL=errors.js.map