UNPKG

jsout

Version:

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

44 lines 1.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.formatSerializedError = formatSerializedError; exports.isSerializedError = isSerializedError; const portableInspect_1 = require("../lib/portableInspect"); const colors_1 = require("../lib/colors"); /** * Formats a serialized error (from serializeError) into human-readable text. */ function formatSerializedError(err) { const { bold, bgGreenBright, black, whiteBright, gray } = (0, colors_1.getColorFunctions)(); const lines = []; let current = err; while (current) { // Header lines.push(bold(whiteBright(`${current.name}: ${current.message}`))); // Stack trace for (const line of current.stack.slice(1)) { lines.push(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}: ${(0, portableInspect_1.portableInspect)(current[key], { colors: true, depth: null })}`); } // Cause chain if (current.cause) { lines.push(black(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