UNPKG

probejs-core

Version:

A powerful tool for traversing and investigating nested objects

68 lines 1.93 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CircularReferenceError = exports.KeyError = exports.PathError = exports.ProbeError = void 0; exports.isProbeError = isProbeError; exports.handleError = handleError; /** * Base error class for Probe operations */ class ProbeError extends Error { constructor(message) { super(message); this.name = "ProbeError"; Object.setPrototypeOf(this, ProbeError.prototype); } } exports.ProbeError = ProbeError; /** * Error thrown for invalid path operations */ class PathError extends ProbeError { constructor(path, reason) { super(`Invalid path "${path}": ${reason}`); this.name = "PathError"; Object.setPrototypeOf(this, PathError.prototype); } } exports.PathError = PathError; /** * Error thrown for invalid key operations */ class KeyError extends ProbeError { constructor(key, reason) { super(`Invalid key "${key}": ${reason}`); this.name = "KeyError"; Object.setPrototypeOf(this, KeyError.prototype); } } exports.KeyError = KeyError; /** * Error thrown when circular references are detected */ class CircularReferenceError extends ProbeError { constructor(path) { super(`Circular reference detected at path "${path}"`); this.name = "CircularReferenceError"; Object.setPrototypeOf(this, CircularReferenceError.prototype); } } exports.CircularReferenceError = CircularReferenceError; /** * Type guard for ProbeError */ function isProbeError(error) { return error instanceof ProbeError; } /** * Utility function to handle and wrap unknown errors */ function handleError(error) { if (isProbeError(error)) { throw error; } if (error instanceof Error) { throw new ProbeError(error.message); } throw new ProbeError("An unknown error occurred"); } //# sourceMappingURL=errors.js.map