@visulima/error 4.4.10 → 4.4.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/dist/code-frame/index.cjs +136 -6
- package/dist/code-frame/index.mjs +131 -6
- package/dist/error/index.cjs +18 -1
- package/dist/error/index.d.cts +2 -2
- package/dist/error/index.d.mts +2 -2
- package/dist/error/index.d.ts +2 -2
- package/dist/error/index.mjs +5 -1
- package/dist/index.cjs +25 -1
- package/dist/index.mjs +8 -1
- package/dist/packem_shared/captureRawStackTrace-CAQrHENg.mjs +12 -0
- package/dist/packem_shared/captureRawStackTrace-DjD7FUtZ.cjs +14 -0
- package/dist/packem_shared/getErrorCauses-CG_JRE6j.mjs +24 -0
- package/dist/packem_shared/getErrorCauses-miTeYJEG.cjs +26 -0
- package/dist/packem_shared/indexToLineColumn-DjmjeiIY.cjs +56 -0
- package/dist/packem_shared/indexToLineColumn-Dx91YDU1.mjs +54 -0
- package/dist/packem_shared/isVisulimaError-BVLWvREw.cjs +45 -0
- package/dist/packem_shared/isVisulimaError-H6TqEA42.mjs +40 -0
- package/dist/packem_shared/parseStacktrace-B-BUrkkI.mjs +280 -0
- package/dist/packem_shared/parseStacktrace-CPbfvO-n.cjs +282 -0
- package/dist/packem_shared/renderError-DV9rZ4rp.mjs +163 -0
- package/dist/packem_shared/renderError-NCKbKLok.cjs +167 -0
- package/dist/packem_shared/serializeError-BNAsxuJ_.mjs +153 -0
- package/dist/packem_shared/serializeError-C3BTAUm5.cjs +157 -0
- package/dist/stacktrace/index.cjs +9 -1
- package/dist/stacktrace/index.mjs +1 -1
- package/package.json +7 -7
- package/dist/packem_shared/captureRawStackTrace-B7M10xhx.mjs +0 -1
- package/dist/packem_shared/captureRawStackTrace-Dle60tQN.cjs +0 -1
- package/dist/packem_shared/getErrorCauses--fuy5DYb.cjs +0 -1
- package/dist/packem_shared/getErrorCauses-D025FGyO.mjs +0 -1
- package/dist/packem_shared/indexToLineColumn-BUaHBIUg.cjs +0 -1
- package/dist/packem_shared/indexToLineColumn-BxCJ9Cey.mjs +0 -1
- package/dist/packem_shared/isVisulimaError-7lgjv56R.mjs +0 -1
- package/dist/packem_shared/isVisulimaError-DYPrVHSe.cjs +0 -1
- package/dist/packem_shared/parseStacktrace-CUC_6mhC.mjs +0 -2
- package/dist/packem_shared/parseStacktrace-DuzLAkHs.cjs +0 -2
- package/dist/packem_shared/renderError-Bul-oz45.mjs +0 -18
- package/dist/packem_shared/renderError-DAUdGdkA.cjs +0 -18
- package/dist/packem_shared/serializeError-BX2VPOX2.cjs +0 -1
- package/dist/packem_shared/serializeError-Ddx6s06r.mjs +0 -1
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { relative } from 'node:path';
|
|
3
|
+
import { cwd } from 'node:process';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { codeFrame } from '../code-frame/index.mjs';
|
|
6
|
+
import parse from './parseStacktrace-B-BUrkkI.mjs';
|
|
7
|
+
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
10
|
+
const getPrefix = /* @__PURE__ */ __name((prefix, indentation, deep) => {
|
|
11
|
+
if (deep === 0) {
|
|
12
|
+
return prefix + "";
|
|
13
|
+
}
|
|
14
|
+
if (indentation === " ") {
|
|
15
|
+
return prefix + " ".repeat(deep);
|
|
16
|
+
}
|
|
17
|
+
return prefix + " ".repeat(indentation * deep);
|
|
18
|
+
}, "getPrefix");
|
|
19
|
+
const getRelativePath = /* @__PURE__ */ __name((filePath, cwdPath) => {
|
|
20
|
+
const path = filePath.replace("async file:", "file:");
|
|
21
|
+
return relative(cwdPath, path.startsWith("file:") ? fileURLToPath(path) : path);
|
|
22
|
+
}, "getRelativePath");
|
|
23
|
+
const getMessage = /* @__PURE__ */ __name((error, { color, hideErrorTitle, indentation, prefix }, deep) => getPrefix(prefix, indentation, deep) + (hideErrorTitle ? color.title(error.message) : color.title(error.name + (error.message ? ": " + error.message : ""))) + "\n", "getMessage");
|
|
24
|
+
const getHint = /* @__PURE__ */ __name((error, { color, indentation, prefix }, deep) => {
|
|
25
|
+
if (error.hint === undefined) {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
const spaces = getPrefix(prefix, indentation, deep);
|
|
29
|
+
let message = "";
|
|
30
|
+
if (Array.isArray(error.hint)) {
|
|
31
|
+
for (const line of error.hint) {
|
|
32
|
+
message += spaces + line + "\n";
|
|
33
|
+
}
|
|
34
|
+
} else {
|
|
35
|
+
message += spaces + error.hint;
|
|
36
|
+
}
|
|
37
|
+
return color.hint(message);
|
|
38
|
+
}, "getHint");
|
|
39
|
+
const getMainFrame = /* @__PURE__ */ __name((trace, { color, cwd: cwdPath, displayShortPath, indentation, prefix }, deep = 0) => {
|
|
40
|
+
const filePath = displayShortPath ? getRelativePath(trace.file, cwdPath) : trace.file;
|
|
41
|
+
const { fileLine, method } = color;
|
|
42
|
+
return getPrefix(prefix, indentation, deep) + "at " + (trace.methodName ? method(trace.methodName) + " " : "") + fileLine(filePath) + ":" + // eslint-disable-next-line @typescript-eslint/restrict-plus-operands
|
|
43
|
+
fileLine(trace.line + "");
|
|
44
|
+
}, "getMainFrame");
|
|
45
|
+
const getCode = /* @__PURE__ */ __name((trace, { color, indentation, linesAbove, linesBelow, prefix, showGutter, showLineNumbers, tabWidth }, deep) => {
|
|
46
|
+
if (trace.file === undefined) {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
const filePath = trace.file.replace("file://", "");
|
|
50
|
+
if (!existsSync(filePath)) {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
const fileContent = readFileSync(filePath, "utf8");
|
|
54
|
+
return codeFrame(
|
|
55
|
+
fileContent,
|
|
56
|
+
{
|
|
57
|
+
start: { column: trace.column, line: trace.line }
|
|
58
|
+
},
|
|
59
|
+
{ color, linesAbove, linesBelow, prefix: getPrefix(prefix, indentation, deep), showGutter, showLineNumbers, tabWidth }
|
|
60
|
+
);
|
|
61
|
+
}, "getCode");
|
|
62
|
+
const getErrors = /* @__PURE__ */ __name((error, options, deep) => {
|
|
63
|
+
if (error.errors.length === 0) {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
let message = getPrefix(options.prefix, options.indentation, deep) + "Errors:\n\n";
|
|
67
|
+
let first = true;
|
|
68
|
+
for (const error_ of error.errors) {
|
|
69
|
+
if (first) {
|
|
70
|
+
first = false;
|
|
71
|
+
} else {
|
|
72
|
+
message += "\n\n";
|
|
73
|
+
}
|
|
74
|
+
message += internalRenderError(
|
|
75
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
76
|
+
error_,
|
|
77
|
+
{ ...options, framesMaxLimit: 1, hideErrorCodeView: options.hideErrorErrorsCodeView },
|
|
78
|
+
deep + 1
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
return "\n" + message;
|
|
82
|
+
}, "getErrors");
|
|
83
|
+
const getCause = /* @__PURE__ */ __name((error, options, deep) => {
|
|
84
|
+
let message = getPrefix(options.prefix, options.indentation, deep) + "Caused by:\n\n";
|
|
85
|
+
const cause = error.cause;
|
|
86
|
+
message += getMessage(cause, options, deep);
|
|
87
|
+
const stacktrace = parse(cause);
|
|
88
|
+
const mainFrame = stacktrace.shift();
|
|
89
|
+
const hint = getHint(cause, options, deep);
|
|
90
|
+
if (hint) {
|
|
91
|
+
message += hint + "\n";
|
|
92
|
+
}
|
|
93
|
+
message += getMainFrame(mainFrame, options, deep);
|
|
94
|
+
if (!options.hideErrorCauseCodeView) {
|
|
95
|
+
const code = getCode(mainFrame, options, deep);
|
|
96
|
+
if (code !== undefined) {
|
|
97
|
+
message += "\n" + code;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (cause.cause) {
|
|
101
|
+
message += "\n" + getCause(cause, options, deep + 1);
|
|
102
|
+
} else if (cause instanceof AggregateError) {
|
|
103
|
+
const errors = getErrors(cause, options, deep);
|
|
104
|
+
if (errors !== undefined) {
|
|
105
|
+
message += "\n" + errors;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return "\n" + message;
|
|
109
|
+
}, "getCause");
|
|
110
|
+
const getStacktrace = /* @__PURE__ */ __name((stack, options) => (stack.length > 0 ? "\n" : "") + stack.map((frame) => getMainFrame(frame, options)).join("\n"), "getStacktrace");
|
|
111
|
+
const internalRenderError = /* @__PURE__ */ __name((error, options, deep) => {
|
|
112
|
+
const config = {
|
|
113
|
+
cwd: cwd(),
|
|
114
|
+
displayShortPath: false,
|
|
115
|
+
filterStacktrace: undefined,
|
|
116
|
+
framesMaxLimit: Number.POSITIVE_INFINITY,
|
|
117
|
+
hideErrorCauseCodeView: false,
|
|
118
|
+
hideErrorCodeView: false,
|
|
119
|
+
hideErrorErrorsCodeView: false,
|
|
120
|
+
hideErrorTitle: false,
|
|
121
|
+
hideMessage: false,
|
|
122
|
+
indentation: 4,
|
|
123
|
+
linesAbove: 2,
|
|
124
|
+
linesBelow: 3,
|
|
125
|
+
prefix: "",
|
|
126
|
+
showGutter: true,
|
|
127
|
+
showLineNumbers: true,
|
|
128
|
+
tabWidth: 4,
|
|
129
|
+
...options,
|
|
130
|
+
color: {
|
|
131
|
+
fileLine: /* @__PURE__ */ __name((value) => value, "fileLine"),
|
|
132
|
+
gutter: /* @__PURE__ */ __name((value) => value, "gutter"),
|
|
133
|
+
hint: /* @__PURE__ */ __name((value) => value, "hint"),
|
|
134
|
+
marker: /* @__PURE__ */ __name((value) => value, "marker"),
|
|
135
|
+
message: /* @__PURE__ */ __name((value) => value, "message"),
|
|
136
|
+
method: /* @__PURE__ */ __name((value) => value, "method"),
|
|
137
|
+
title: /* @__PURE__ */ __name((value) => value, "title"),
|
|
138
|
+
...options.color
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
const stack = parse(error, {
|
|
142
|
+
filter: options.filterStacktrace,
|
|
143
|
+
frameLimit: config.framesMaxLimit
|
|
144
|
+
});
|
|
145
|
+
const mainFrame = stack.shift();
|
|
146
|
+
return [
|
|
147
|
+
options.hideMessage ? undefined : getMessage(error, config, deep),
|
|
148
|
+
getHint(error, config, deep),
|
|
149
|
+
mainFrame ? getMainFrame(mainFrame, config, deep) : undefined,
|
|
150
|
+
mainFrame && !config.hideErrorCodeView ? getCode(mainFrame, config, deep) : undefined,
|
|
151
|
+
error instanceof AggregateError ? getErrors(error, config, deep) : undefined,
|
|
152
|
+
error.cause === undefined ? undefined : getCause(error, config, deep),
|
|
153
|
+
stack.length > 0 ? getStacktrace(stack, config) : undefined
|
|
154
|
+
].filter(Boolean).join("\n").replaceAll("\\", "/");
|
|
155
|
+
}, "internalRenderError");
|
|
156
|
+
const renderError = /* @__PURE__ */ __name((error, options = {}) => {
|
|
157
|
+
if (options.framesMaxLimit !== undefined && options.framesMaxLimit <= 0) {
|
|
158
|
+
throw new RangeError("The 'framesMaxLimit' option must be a positive number");
|
|
159
|
+
}
|
|
160
|
+
return internalRenderError(error, options, 0);
|
|
161
|
+
}, "renderError");
|
|
162
|
+
|
|
163
|
+
export { renderError };
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
4
|
+
|
|
5
|
+
const node_fs = require('node:fs');
|
|
6
|
+
const node_path = require('node:path');
|
|
7
|
+
const node_process = require('node:process');
|
|
8
|
+
const node_url = require('node:url');
|
|
9
|
+
const codeFrame_index = require('../code-frame/index.cjs');
|
|
10
|
+
const parseStacktrace = require('./parseStacktrace-CPbfvO-n.cjs');
|
|
11
|
+
|
|
12
|
+
var __defProp = Object.defineProperty;
|
|
13
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
14
|
+
const getPrefix = /* @__PURE__ */ __name((prefix, indentation, deep) => {
|
|
15
|
+
if (deep === 0) {
|
|
16
|
+
return prefix + "";
|
|
17
|
+
}
|
|
18
|
+
if (indentation === " ") {
|
|
19
|
+
return prefix + " ".repeat(deep);
|
|
20
|
+
}
|
|
21
|
+
return prefix + " ".repeat(indentation * deep);
|
|
22
|
+
}, "getPrefix");
|
|
23
|
+
const getRelativePath = /* @__PURE__ */ __name((filePath, cwdPath) => {
|
|
24
|
+
const path = filePath.replace("async file:", "file:");
|
|
25
|
+
return node_path.relative(cwdPath, path.startsWith("file:") ? node_url.fileURLToPath(path) : path);
|
|
26
|
+
}, "getRelativePath");
|
|
27
|
+
const getMessage = /* @__PURE__ */ __name((error, { color, hideErrorTitle, indentation, prefix }, deep) => getPrefix(prefix, indentation, deep) + (hideErrorTitle ? color.title(error.message) : color.title(error.name + (error.message ? ": " + error.message : ""))) + "\n", "getMessage");
|
|
28
|
+
const getHint = /* @__PURE__ */ __name((error, { color, indentation, prefix }, deep) => {
|
|
29
|
+
if (error.hint === undefined) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
const spaces = getPrefix(prefix, indentation, deep);
|
|
33
|
+
let message = "";
|
|
34
|
+
if (Array.isArray(error.hint)) {
|
|
35
|
+
for (const line of error.hint) {
|
|
36
|
+
message += spaces + line + "\n";
|
|
37
|
+
}
|
|
38
|
+
} else {
|
|
39
|
+
message += spaces + error.hint;
|
|
40
|
+
}
|
|
41
|
+
return color.hint(message);
|
|
42
|
+
}, "getHint");
|
|
43
|
+
const getMainFrame = /* @__PURE__ */ __name((trace, { color, cwd: cwdPath, displayShortPath, indentation, prefix }, deep = 0) => {
|
|
44
|
+
const filePath = displayShortPath ? getRelativePath(trace.file, cwdPath) : trace.file;
|
|
45
|
+
const { fileLine, method } = color;
|
|
46
|
+
return getPrefix(prefix, indentation, deep) + "at " + (trace.methodName ? method(trace.methodName) + " " : "") + fileLine(filePath) + ":" + // eslint-disable-next-line @typescript-eslint/restrict-plus-operands
|
|
47
|
+
fileLine(trace.line + "");
|
|
48
|
+
}, "getMainFrame");
|
|
49
|
+
const getCode = /* @__PURE__ */ __name((trace, { color, indentation, linesAbove, linesBelow, prefix, showGutter, showLineNumbers, tabWidth }, deep) => {
|
|
50
|
+
if (trace.file === undefined) {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
const filePath = trace.file.replace("file://", "");
|
|
54
|
+
if (!node_fs.existsSync(filePath)) {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
const fileContent = node_fs.readFileSync(filePath, "utf8");
|
|
58
|
+
return codeFrame_index.codeFrame(
|
|
59
|
+
fileContent,
|
|
60
|
+
{
|
|
61
|
+
start: { column: trace.column, line: trace.line }
|
|
62
|
+
},
|
|
63
|
+
{ color, linesAbove, linesBelow, prefix: getPrefix(prefix, indentation, deep), showGutter, showLineNumbers, tabWidth }
|
|
64
|
+
);
|
|
65
|
+
}, "getCode");
|
|
66
|
+
const getErrors = /* @__PURE__ */ __name((error, options, deep) => {
|
|
67
|
+
if (error.errors.length === 0) {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
let message = getPrefix(options.prefix, options.indentation, deep) + "Errors:\n\n";
|
|
71
|
+
let first = true;
|
|
72
|
+
for (const error_ of error.errors) {
|
|
73
|
+
if (first) {
|
|
74
|
+
first = false;
|
|
75
|
+
} else {
|
|
76
|
+
message += "\n\n";
|
|
77
|
+
}
|
|
78
|
+
message += internalRenderError(
|
|
79
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
80
|
+
error_,
|
|
81
|
+
{ ...options, framesMaxLimit: 1, hideErrorCodeView: options.hideErrorErrorsCodeView },
|
|
82
|
+
deep + 1
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
return "\n" + message;
|
|
86
|
+
}, "getErrors");
|
|
87
|
+
const getCause = /* @__PURE__ */ __name((error, options, deep) => {
|
|
88
|
+
let message = getPrefix(options.prefix, options.indentation, deep) + "Caused by:\n\n";
|
|
89
|
+
const cause = error.cause;
|
|
90
|
+
message += getMessage(cause, options, deep);
|
|
91
|
+
const stacktrace = parseStacktrace(cause);
|
|
92
|
+
const mainFrame = stacktrace.shift();
|
|
93
|
+
const hint = getHint(cause, options, deep);
|
|
94
|
+
if (hint) {
|
|
95
|
+
message += hint + "\n";
|
|
96
|
+
}
|
|
97
|
+
message += getMainFrame(mainFrame, options, deep);
|
|
98
|
+
if (!options.hideErrorCauseCodeView) {
|
|
99
|
+
const code = getCode(mainFrame, options, deep);
|
|
100
|
+
if (code !== undefined) {
|
|
101
|
+
message += "\n" + code;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (cause.cause) {
|
|
105
|
+
message += "\n" + getCause(cause, options, deep + 1);
|
|
106
|
+
} else if (cause instanceof AggregateError) {
|
|
107
|
+
const errors = getErrors(cause, options, deep);
|
|
108
|
+
if (errors !== undefined) {
|
|
109
|
+
message += "\n" + errors;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return "\n" + message;
|
|
113
|
+
}, "getCause");
|
|
114
|
+
const getStacktrace = /* @__PURE__ */ __name((stack, options) => (stack.length > 0 ? "\n" : "") + stack.map((frame) => getMainFrame(frame, options)).join("\n"), "getStacktrace");
|
|
115
|
+
const internalRenderError = /* @__PURE__ */ __name((error, options, deep) => {
|
|
116
|
+
const config = {
|
|
117
|
+
cwd: node_process.cwd(),
|
|
118
|
+
displayShortPath: false,
|
|
119
|
+
filterStacktrace: undefined,
|
|
120
|
+
framesMaxLimit: Number.POSITIVE_INFINITY,
|
|
121
|
+
hideErrorCauseCodeView: false,
|
|
122
|
+
hideErrorCodeView: false,
|
|
123
|
+
hideErrorErrorsCodeView: false,
|
|
124
|
+
hideErrorTitle: false,
|
|
125
|
+
hideMessage: false,
|
|
126
|
+
indentation: 4,
|
|
127
|
+
linesAbove: 2,
|
|
128
|
+
linesBelow: 3,
|
|
129
|
+
prefix: "",
|
|
130
|
+
showGutter: true,
|
|
131
|
+
showLineNumbers: true,
|
|
132
|
+
tabWidth: 4,
|
|
133
|
+
...options,
|
|
134
|
+
color: {
|
|
135
|
+
fileLine: /* @__PURE__ */ __name((value) => value, "fileLine"),
|
|
136
|
+
gutter: /* @__PURE__ */ __name((value) => value, "gutter"),
|
|
137
|
+
hint: /* @__PURE__ */ __name((value) => value, "hint"),
|
|
138
|
+
marker: /* @__PURE__ */ __name((value) => value, "marker"),
|
|
139
|
+
message: /* @__PURE__ */ __name((value) => value, "message"),
|
|
140
|
+
method: /* @__PURE__ */ __name((value) => value, "method"),
|
|
141
|
+
title: /* @__PURE__ */ __name((value) => value, "title"),
|
|
142
|
+
...options.color
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
const stack = parseStacktrace(error, {
|
|
146
|
+
filter: options.filterStacktrace,
|
|
147
|
+
frameLimit: config.framesMaxLimit
|
|
148
|
+
});
|
|
149
|
+
const mainFrame = stack.shift();
|
|
150
|
+
return [
|
|
151
|
+
options.hideMessage ? undefined : getMessage(error, config, deep),
|
|
152
|
+
getHint(error, config, deep),
|
|
153
|
+
mainFrame ? getMainFrame(mainFrame, config, deep) : undefined,
|
|
154
|
+
mainFrame && !config.hideErrorCodeView ? getCode(mainFrame, config, deep) : undefined,
|
|
155
|
+
error instanceof AggregateError ? getErrors(error, config, deep) : undefined,
|
|
156
|
+
error.cause === undefined ? undefined : getCause(error, config, deep),
|
|
157
|
+
stack.length > 0 ? getStacktrace(stack, config) : undefined
|
|
158
|
+
].filter(Boolean).join("\n").replaceAll("\\", "/");
|
|
159
|
+
}, "internalRenderError");
|
|
160
|
+
const renderError = /* @__PURE__ */ __name((error, options = {}) => {
|
|
161
|
+
if (options.framesMaxLimit !== undefined && options.framesMaxLimit <= 0) {
|
|
162
|
+
throw new RangeError("The 'framesMaxLimit' option must be a positive number");
|
|
163
|
+
}
|
|
164
|
+
return internalRenderError(error, options, 0);
|
|
165
|
+
}, "renderError");
|
|
166
|
+
|
|
167
|
+
exports.renderError = renderError;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
var __defProp$1 = Object.defineProperty;
|
|
2
|
+
var __name$1 = (target, value) => __defProp$1(target, "name", { value, configurable: true });
|
|
3
|
+
function isPlainObject(value) {
|
|
4
|
+
if (typeof value !== "object" || value === null) {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
const prototype = Object.getPrototypeOf(value);
|
|
8
|
+
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
|
|
9
|
+
}
|
|
10
|
+
__name$1(isPlainObject, "isPlainObject");
|
|
11
|
+
|
|
12
|
+
const ErrorProto = Object.create(
|
|
13
|
+
{},
|
|
14
|
+
{
|
|
15
|
+
cause: {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
value: undefined,
|
|
18
|
+
writable: true
|
|
19
|
+
},
|
|
20
|
+
code: {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
value: undefined,
|
|
23
|
+
writable: true
|
|
24
|
+
},
|
|
25
|
+
errors: {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
value: undefined,
|
|
28
|
+
writable: true
|
|
29
|
+
},
|
|
30
|
+
message: {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
value: undefined,
|
|
33
|
+
writable: true
|
|
34
|
+
},
|
|
35
|
+
name: {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
value: undefined,
|
|
38
|
+
writable: true
|
|
39
|
+
},
|
|
40
|
+
stack: {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
value: undefined,
|
|
43
|
+
writable: true
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
var __defProp = Object.defineProperty;
|
|
49
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
50
|
+
const toJsonWasCalled = /* @__PURE__ */ new WeakSet();
|
|
51
|
+
const toJSON = /* @__PURE__ */ __name((from) => {
|
|
52
|
+
toJsonWasCalled.add(from);
|
|
53
|
+
const json = from.toJSON();
|
|
54
|
+
toJsonWasCalled.delete(from);
|
|
55
|
+
return json;
|
|
56
|
+
}, "toJSON");
|
|
57
|
+
const serializeValue = /* @__PURE__ */ __name((value, seen, depth, options) => {
|
|
58
|
+
if (value && value instanceof Uint8Array && value.constructor.name === "Buffer") {
|
|
59
|
+
return "[object Buffer]";
|
|
60
|
+
}
|
|
61
|
+
if (value !== null && typeof value === "object" && typeof value.pipe === "function") {
|
|
62
|
+
return "[object Stream]";
|
|
63
|
+
}
|
|
64
|
+
if (value instanceof Error) {
|
|
65
|
+
if (seen.includes(value)) {
|
|
66
|
+
return "[Circular]";
|
|
67
|
+
}
|
|
68
|
+
depth += 1;
|
|
69
|
+
return _serialize(value, options, seen, depth);
|
|
70
|
+
}
|
|
71
|
+
if (options.useToJSON && typeof value.toJSON === "function") {
|
|
72
|
+
return value.toJSON();
|
|
73
|
+
}
|
|
74
|
+
if (typeof value === "object" && value instanceof Date) {
|
|
75
|
+
return value.toISOString();
|
|
76
|
+
}
|
|
77
|
+
if (typeof value === "function") {
|
|
78
|
+
return "[Function: " + (value.name || "anonymous") + "]";
|
|
79
|
+
}
|
|
80
|
+
if (isPlainObject(value)) {
|
|
81
|
+
depth += 1;
|
|
82
|
+
if (options.maxDepth && depth >= options.maxDepth) {
|
|
83
|
+
return {};
|
|
84
|
+
}
|
|
85
|
+
const plainObject = {};
|
|
86
|
+
for (const key in value) {
|
|
87
|
+
plainObject[key] = serializeValue(value[key], seen, depth, options);
|
|
88
|
+
}
|
|
89
|
+
return plainObject;
|
|
90
|
+
}
|
|
91
|
+
try {
|
|
92
|
+
return value;
|
|
93
|
+
} catch {
|
|
94
|
+
return "[Not Available]";
|
|
95
|
+
}
|
|
96
|
+
}, "serializeValue");
|
|
97
|
+
const _serialize = /* @__PURE__ */ __name((error, options, seen, depth) => {
|
|
98
|
+
seen.push(error);
|
|
99
|
+
if (options.maxDepth === 0) {
|
|
100
|
+
return {};
|
|
101
|
+
}
|
|
102
|
+
if (options.useToJSON && typeof error.toJSON === "function" && !toJsonWasCalled.has(error)) {
|
|
103
|
+
return toJSON(error);
|
|
104
|
+
}
|
|
105
|
+
const protoError = Object.create(ErrorProto);
|
|
106
|
+
protoError.name = Object.prototype.toString.call(error.constructor) === "[object Function]" ? error.constructor.name : error.name;
|
|
107
|
+
protoError.message = error.message;
|
|
108
|
+
protoError.stack = error.stack;
|
|
109
|
+
if (Array.isArray(error.errors)) {
|
|
110
|
+
const aggregateErrors = [];
|
|
111
|
+
for (const aggregateError of error.errors) {
|
|
112
|
+
if (!(aggregateError instanceof Error)) {
|
|
113
|
+
throw new TypeError("All errors in the 'errors' property must be instances of Error");
|
|
114
|
+
}
|
|
115
|
+
if (seen.includes(aggregateError)) {
|
|
116
|
+
protoError.errors = [];
|
|
117
|
+
return protoError;
|
|
118
|
+
}
|
|
119
|
+
aggregateErrors.push(_serialize(aggregateError, options, seen, depth));
|
|
120
|
+
}
|
|
121
|
+
protoError.errors = aggregateErrors;
|
|
122
|
+
}
|
|
123
|
+
if (error.cause instanceof Error && !seen.includes(error.cause)) {
|
|
124
|
+
protoError.cause = _serialize(error.cause, options, seen, depth);
|
|
125
|
+
}
|
|
126
|
+
for (const key in error) {
|
|
127
|
+
if (protoError[key] === undefined) {
|
|
128
|
+
const value = error[key];
|
|
129
|
+
protoError[key] = serializeValue(value, seen, depth, options);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (Array.isArray(options.exclude) && options.exclude.length > 0) {
|
|
133
|
+
for (const key of options.exclude) {
|
|
134
|
+
try {
|
|
135
|
+
delete protoError[key];
|
|
136
|
+
} catch {
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return protoError;
|
|
141
|
+
}, "_serialize");
|
|
142
|
+
const serialize = /* @__PURE__ */ __name((error, options = {}) => _serialize(
|
|
143
|
+
error,
|
|
144
|
+
{
|
|
145
|
+
exclude: options.exclude ?? [],
|
|
146
|
+
maxDepth: options.maxDepth ?? Number.POSITIVE_INFINITY,
|
|
147
|
+
useToJSON: options.useToJSON ?? false
|
|
148
|
+
},
|
|
149
|
+
[],
|
|
150
|
+
0
|
|
151
|
+
), "serialize");
|
|
152
|
+
|
|
153
|
+
export { serialize };
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
4
|
+
|
|
5
|
+
var __defProp$1 = Object.defineProperty;
|
|
6
|
+
var __name$1 = (target, value) => __defProp$1(target, "name", { value, configurable: true });
|
|
7
|
+
function isPlainObject(value) {
|
|
8
|
+
if (typeof value !== "object" || value === null) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
const prototype = Object.getPrototypeOf(value);
|
|
12
|
+
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
|
|
13
|
+
}
|
|
14
|
+
__name$1(isPlainObject, "isPlainObject");
|
|
15
|
+
|
|
16
|
+
const ErrorProto = Object.create(
|
|
17
|
+
{},
|
|
18
|
+
{
|
|
19
|
+
cause: {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
value: undefined,
|
|
22
|
+
writable: true
|
|
23
|
+
},
|
|
24
|
+
code: {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
value: undefined,
|
|
27
|
+
writable: true
|
|
28
|
+
},
|
|
29
|
+
errors: {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
value: undefined,
|
|
32
|
+
writable: true
|
|
33
|
+
},
|
|
34
|
+
message: {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
value: undefined,
|
|
37
|
+
writable: true
|
|
38
|
+
},
|
|
39
|
+
name: {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
value: undefined,
|
|
42
|
+
writable: true
|
|
43
|
+
},
|
|
44
|
+
stack: {
|
|
45
|
+
enumerable: true,
|
|
46
|
+
value: undefined,
|
|
47
|
+
writable: true
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
var __defProp = Object.defineProperty;
|
|
53
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
54
|
+
const toJsonWasCalled = /* @__PURE__ */ new WeakSet();
|
|
55
|
+
const toJSON = /* @__PURE__ */ __name((from) => {
|
|
56
|
+
toJsonWasCalled.add(from);
|
|
57
|
+
const json = from.toJSON();
|
|
58
|
+
toJsonWasCalled.delete(from);
|
|
59
|
+
return json;
|
|
60
|
+
}, "toJSON");
|
|
61
|
+
const serializeValue = /* @__PURE__ */ __name((value, seen, depth, options) => {
|
|
62
|
+
if (value && value instanceof Uint8Array && value.constructor.name === "Buffer") {
|
|
63
|
+
return "[object Buffer]";
|
|
64
|
+
}
|
|
65
|
+
if (value !== null && typeof value === "object" && typeof value.pipe === "function") {
|
|
66
|
+
return "[object Stream]";
|
|
67
|
+
}
|
|
68
|
+
if (value instanceof Error) {
|
|
69
|
+
if (seen.includes(value)) {
|
|
70
|
+
return "[Circular]";
|
|
71
|
+
}
|
|
72
|
+
depth += 1;
|
|
73
|
+
return _serialize(value, options, seen, depth);
|
|
74
|
+
}
|
|
75
|
+
if (options.useToJSON && typeof value.toJSON === "function") {
|
|
76
|
+
return value.toJSON();
|
|
77
|
+
}
|
|
78
|
+
if (typeof value === "object" && value instanceof Date) {
|
|
79
|
+
return value.toISOString();
|
|
80
|
+
}
|
|
81
|
+
if (typeof value === "function") {
|
|
82
|
+
return "[Function: " + (value.name || "anonymous") + "]";
|
|
83
|
+
}
|
|
84
|
+
if (isPlainObject(value)) {
|
|
85
|
+
depth += 1;
|
|
86
|
+
if (options.maxDepth && depth >= options.maxDepth) {
|
|
87
|
+
return {};
|
|
88
|
+
}
|
|
89
|
+
const plainObject = {};
|
|
90
|
+
for (const key in value) {
|
|
91
|
+
plainObject[key] = serializeValue(value[key], seen, depth, options);
|
|
92
|
+
}
|
|
93
|
+
return plainObject;
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
return value;
|
|
97
|
+
} catch {
|
|
98
|
+
return "[Not Available]";
|
|
99
|
+
}
|
|
100
|
+
}, "serializeValue");
|
|
101
|
+
const _serialize = /* @__PURE__ */ __name((error, options, seen, depth) => {
|
|
102
|
+
seen.push(error);
|
|
103
|
+
if (options.maxDepth === 0) {
|
|
104
|
+
return {};
|
|
105
|
+
}
|
|
106
|
+
if (options.useToJSON && typeof error.toJSON === "function" && !toJsonWasCalled.has(error)) {
|
|
107
|
+
return toJSON(error);
|
|
108
|
+
}
|
|
109
|
+
const protoError = Object.create(ErrorProto);
|
|
110
|
+
protoError.name = Object.prototype.toString.call(error.constructor) === "[object Function]" ? error.constructor.name : error.name;
|
|
111
|
+
protoError.message = error.message;
|
|
112
|
+
protoError.stack = error.stack;
|
|
113
|
+
if (Array.isArray(error.errors)) {
|
|
114
|
+
const aggregateErrors = [];
|
|
115
|
+
for (const aggregateError of error.errors) {
|
|
116
|
+
if (!(aggregateError instanceof Error)) {
|
|
117
|
+
throw new TypeError("All errors in the 'errors' property must be instances of Error");
|
|
118
|
+
}
|
|
119
|
+
if (seen.includes(aggregateError)) {
|
|
120
|
+
protoError.errors = [];
|
|
121
|
+
return protoError;
|
|
122
|
+
}
|
|
123
|
+
aggregateErrors.push(_serialize(aggregateError, options, seen, depth));
|
|
124
|
+
}
|
|
125
|
+
protoError.errors = aggregateErrors;
|
|
126
|
+
}
|
|
127
|
+
if (error.cause instanceof Error && !seen.includes(error.cause)) {
|
|
128
|
+
protoError.cause = _serialize(error.cause, options, seen, depth);
|
|
129
|
+
}
|
|
130
|
+
for (const key in error) {
|
|
131
|
+
if (protoError[key] === undefined) {
|
|
132
|
+
const value = error[key];
|
|
133
|
+
protoError[key] = serializeValue(value, seen, depth, options);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (Array.isArray(options.exclude) && options.exclude.length > 0) {
|
|
137
|
+
for (const key of options.exclude) {
|
|
138
|
+
try {
|
|
139
|
+
delete protoError[key];
|
|
140
|
+
} catch {
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return protoError;
|
|
145
|
+
}, "_serialize");
|
|
146
|
+
const serialize = /* @__PURE__ */ __name((error, options = {}) => _serialize(
|
|
147
|
+
error,
|
|
148
|
+
{
|
|
149
|
+
exclude: options.exclude ?? [],
|
|
150
|
+
maxDepth: options.maxDepth ?? Number.POSITIVE_INFINITY,
|
|
151
|
+
useToJSON: options.useToJSON ?? false
|
|
152
|
+
},
|
|
153
|
+
[],
|
|
154
|
+
0
|
|
155
|
+
), "serialize");
|
|
156
|
+
|
|
157
|
+
exports.serialize = serialize;
|
|
@@ -1 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
4
|
+
|
|
5
|
+
const parseStacktrace = require('../packem_shared/parseStacktrace-CPbfvO-n.cjs');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
exports.parseStacktrace = parseStacktrace;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export { default as parseStacktrace } from '../packem_shared/parseStacktrace-B-BUrkkI.mjs';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visulima/error",
|
|
3
|
-
"version": "4.4.
|
|
3
|
+
"version": "4.4.12",
|
|
4
4
|
"description": "Error with more than just a message, stacktrace parsing.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"anolilab",
|
|
@@ -147,13 +147,13 @@
|
|
|
147
147
|
"@types/command-line-args": "^5.2.3",
|
|
148
148
|
"@types/node": "18.19.15",
|
|
149
149
|
"@visulima/nextra-theme-docs": "4.0.26",
|
|
150
|
-
"@visulima/packem": "1.
|
|
151
|
-
"@visulima/path": "1.3.
|
|
150
|
+
"@visulima/packem": "1.10.7",
|
|
151
|
+
"@visulima/path": "1.3.2",
|
|
152
152
|
"@vitest/coverage-v8": "^2.1.8",
|
|
153
153
|
"@vitest/ui": "^2.1.8",
|
|
154
154
|
"conventional-changelog-conventionalcommits": "8.0.0",
|
|
155
155
|
"cross-env": "^7.0.3",
|
|
156
|
-
"esbuild": "0.24.
|
|
156
|
+
"esbuild": "0.24.2",
|
|
157
157
|
"eslint": "8.57.0",
|
|
158
158
|
"eslint-plugin-deprecation": "^3.0.0",
|
|
159
159
|
"eslint-plugin-import": "npm:eslint-plugin-i@^2.29.1",
|
|
@@ -162,9 +162,9 @@
|
|
|
162
162
|
"eslint-plugin-vitest-globals": "^1.5.0",
|
|
163
163
|
"is-plain-obj": "^4.1.0",
|
|
164
164
|
"prettier": "^3.4.2",
|
|
165
|
-
"rimraf": "
|
|
166
|
-
"semantic-release": "24.
|
|
167
|
-
"typescript": "5.
|
|
165
|
+
"rimraf": "6.0.1",
|
|
166
|
+
"semantic-release": "24.2.1",
|
|
167
|
+
"typescript": "5.7.3",
|
|
168
168
|
"vitest": "^2.1.8"
|
|
169
169
|
},
|
|
170
170
|
"engines": {
|