UNPKG

jsout

Version:

A Syslog-compatible, small, and simple logger for Typescript/Javascript projects. Sponsored by https://aeroview.io

46 lines 1.74 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.formatSerializedError = formatSerializedError; exports.isSerializedError = isSerializedError; const node_util_1 = __importDefault(require("node:util")); const colorette_1 = require("colorette"); /** * Formats a serialized error (from serializeError) into human-readable text. */ function formatSerializedError(err) { const lines = []; let current = err; while (current) { // Header lines.push((0, colorette_1.bold)((0, colorette_1.whiteBright)(`${current.name}: ${current.message}`))); // Stack trace for (const line of current.stack.slice(1)) { lines.push((0, colorette_1.gray)(` at ${line.trim()}`)); } // Custom fields for (const key of Object.keys(current)) { // Skip standard fields if (key === 'name' || key === 'message' || key === 'stack' || key === 'cause') continue; lines.push(`${key}: ${node_util_1.default.inspect(current[key], { colors: true, depth: null })}`); } // Cause chain if (current.cause) { lines.push((0, colorette_1.black)((0, colorette_1.bgGreenBright)('↳ Caused by:'))); } current = current.cause; } return lines.join('\n'); } function isSerializedError(obj) { return obj && !(obj instanceof Error) && typeof obj === 'object' && 'message' in obj && 'stack' in obj && Array.isArray(obj.stack); } //# sourceMappingURL=formatSerializedError.js.map