@visulima/error 4.4.11 → 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 +11 -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
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
## @visulima/error [4.4.12](https://github.com/visulima/visulima/compare/@visulima/error@4.4.11...@visulima/error@4.4.12) (2025-01-12)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
* updated @visulima/packem, and all other dev dependencies ([7797a1c](https://github.com/visulima/visulima/commit/7797a1c3e6f1fc532895247bd88285a8a9883c40))
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Dependencies
|
|
9
|
+
|
|
10
|
+
* **@visulima/path:** upgraded to 1.3.2
|
|
11
|
+
|
|
1
12
|
## @visulima/error [4.4.11](https://github.com/visulima/visulima/compare/@visulima/error@4.4.10...@visulima/error@4.4.11) (2025-01-08)
|
|
2
13
|
|
|
3
14
|
|
|
@@ -1,6 +1,136 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
4
|
+
|
|
5
|
+
var __defProp$2 = Object.defineProperty;
|
|
6
|
+
var __name$2 = (target, value) => __defProp$2(target, "name", { value, configurable: true });
|
|
7
|
+
const normalizeLF = /* @__PURE__ */ __name$2((code) => code.replaceAll(/\r\n|\r(?!\n)|\n/gu, "\n"), "normalizeLF");
|
|
8
|
+
|
|
9
|
+
const _process = globalThis.process || /* @__PURE__ */ Object.create(null);
|
|
10
|
+
const processShims = {
|
|
11
|
+
versions: {}
|
|
12
|
+
};
|
|
13
|
+
const process = new Proxy(_process, {
|
|
14
|
+
get(target, property) {
|
|
15
|
+
if (property in target) {
|
|
16
|
+
return target[property];
|
|
17
|
+
}
|
|
18
|
+
if (property in processShims) {
|
|
19
|
+
return processShims[property];
|
|
20
|
+
}
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
var __defProp$1 = Object.defineProperty;
|
|
26
|
+
var __name$1 = (target, value) => __defProp$1(target, "name", { value, configurable: true });
|
|
27
|
+
const getMarkerLines = /* @__PURE__ */ __name$1((loc, source, linesAbove, linesBelow) => {
|
|
28
|
+
const startLoc = {
|
|
29
|
+
column: 0,
|
|
30
|
+
// @ts-expect-error Can be overwritten
|
|
31
|
+
line: -1,
|
|
32
|
+
...loc.start
|
|
33
|
+
};
|
|
34
|
+
const endLoc = {
|
|
35
|
+
...startLoc,
|
|
36
|
+
...loc.end
|
|
37
|
+
};
|
|
38
|
+
const startLine = startLoc.line;
|
|
39
|
+
const startColumn = startLoc.column;
|
|
40
|
+
const endLine = endLoc.line;
|
|
41
|
+
const endColumn = endLoc.column;
|
|
42
|
+
let start = Math.max(startLine - (linesAbove + 1), 0);
|
|
43
|
+
let end = Math.min(source.length, endLine + linesBelow);
|
|
44
|
+
if (startLine === -1) {
|
|
45
|
+
start = 0;
|
|
46
|
+
}
|
|
47
|
+
if (endLine === -1) {
|
|
48
|
+
end = source.length;
|
|
49
|
+
}
|
|
50
|
+
const lineDiff = endLine - startLine;
|
|
51
|
+
const markerLines = {};
|
|
52
|
+
if (lineDiff) {
|
|
53
|
+
for (let index = 0; index <= lineDiff; index++) {
|
|
54
|
+
const lineNumber = index + startLine;
|
|
55
|
+
if (!startColumn) {
|
|
56
|
+
markerLines[lineNumber] = true;
|
|
57
|
+
} else if (index === 0) {
|
|
58
|
+
const sourceLength = source[lineNumber - 1]?.length;
|
|
59
|
+
markerLines[lineNumber] = [startColumn, (sourceLength ?? 0) - startColumn + 1];
|
|
60
|
+
} else if (index === lineDiff) {
|
|
61
|
+
markerLines[lineNumber] = [0, endColumn];
|
|
62
|
+
} else {
|
|
63
|
+
const sourceLength = source[lineNumber - index]?.length;
|
|
64
|
+
markerLines[lineNumber] = [0, sourceLength];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
} else if (startColumn === endColumn) {
|
|
68
|
+
markerLines[startLine] = startColumn ? [startColumn, 0] : true;
|
|
69
|
+
} else {
|
|
70
|
+
markerLines[startLine] = [startColumn, (endColumn ?? 0) - (startColumn ?? 0)];
|
|
71
|
+
}
|
|
72
|
+
return { end, markerLines, start };
|
|
73
|
+
}, "getMarkerLines");
|
|
74
|
+
|
|
75
|
+
var __defProp = Object.defineProperty;
|
|
76
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
77
|
+
const CODE_FRAME_POINTER = process.platform === "win32" && !process.env?.WT_SESSION ? ">" : "❯";
|
|
78
|
+
const codeFrame = /* @__PURE__ */ __name((source, loc, options) => {
|
|
79
|
+
const config = {
|
|
80
|
+
// grab 2 lines before, and 3 lines after focused line
|
|
81
|
+
linesAbove: 2,
|
|
82
|
+
linesBelow: 3,
|
|
83
|
+
prefix: "",
|
|
84
|
+
showGutter: true,
|
|
85
|
+
showLineNumbers: true,
|
|
86
|
+
tabWidth: 4,
|
|
87
|
+
...options,
|
|
88
|
+
color: {
|
|
89
|
+
gutter: /* @__PURE__ */ __name((value) => value, "gutter"),
|
|
90
|
+
marker: /* @__PURE__ */ __name((value) => value, "marker"),
|
|
91
|
+
message: /* @__PURE__ */ __name((value) => value, "message"),
|
|
92
|
+
...options?.color
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
const hasColumns = loc.start && typeof loc.start.column === "number";
|
|
96
|
+
let lines = normalizeLF(source).split("\n");
|
|
97
|
+
if (typeof config?.tabWidth === "number") {
|
|
98
|
+
lines = lines.map((ln) => ln.replaceAll(" ", " ".repeat(config.tabWidth)));
|
|
99
|
+
}
|
|
100
|
+
const { end, markerLines, start } = getMarkerLines(loc, lines, config.linesAbove, config.linesBelow);
|
|
101
|
+
const numberMaxWidth = String(end).length;
|
|
102
|
+
const { gutter: colorizeGutter, marker: colorizeMarker, message: colorizeMessage } = config.color;
|
|
103
|
+
let frame = lines.slice(start, end).map((line, index) => {
|
|
104
|
+
const number = start + 1 + index;
|
|
105
|
+
const hasMarker = markerLines[number];
|
|
106
|
+
const paddedNumber = (" " + number).slice(-numberMaxWidth);
|
|
107
|
+
const lastMarkerLine = !markerLines[number + 1];
|
|
108
|
+
const gutter = " " + paddedNumber + (config.showGutter ? " |" : "");
|
|
109
|
+
if (hasMarker) {
|
|
110
|
+
let markerLine = "";
|
|
111
|
+
if (Array.isArray(hasMarker)) {
|
|
112
|
+
const markerSpacing = line.replaceAll(/[^\t]/g, " ").slice(0, Math.max(hasMarker[0] - 1, 0));
|
|
113
|
+
const numberOfMarkers = hasMarker[1] || 1;
|
|
114
|
+
markerLine = [
|
|
115
|
+
"\n ",
|
|
116
|
+
config.prefix + colorizeGutter(gutter.replaceAll(/\d/g, " ")),
|
|
117
|
+
" ",
|
|
118
|
+
markerSpacing,
|
|
119
|
+
colorizeMarker("^").repeat(numberOfMarkers)
|
|
120
|
+
].join("");
|
|
121
|
+
if (lastMarkerLine && config.message) {
|
|
122
|
+
markerLine += ` ${colorizeMessage(config.message)}`;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return [config.prefix + colorizeMarker(CODE_FRAME_POINTER), colorizeGutter(gutter), line.length > 0 ? " " + line : "", markerLine].join("");
|
|
126
|
+
}
|
|
127
|
+
return config.prefix + " " + colorizeGutter(gutter) + (line.length > 0 ? " " + line : "");
|
|
128
|
+
}).join("\n");
|
|
129
|
+
if (config.message && !hasColumns) {
|
|
130
|
+
frame = config.prefix + " ".repeat(numberMaxWidth + 1) + config.message + "\n" + frame;
|
|
131
|
+
}
|
|
132
|
+
return frame;
|
|
133
|
+
}, "codeFrame");
|
|
134
|
+
|
|
135
|
+
exports.CODE_FRAME_POINTER = CODE_FRAME_POINTER;
|
|
136
|
+
exports.codeFrame = codeFrame;
|
|
@@ -1,6 +1,131 @@
|
|
|
1
|
-
var
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
var __defProp$2 = Object.defineProperty;
|
|
2
|
+
var __name$2 = (target, value) => __defProp$2(target, "name", { value, configurable: true });
|
|
3
|
+
const normalizeLF = /* @__PURE__ */ __name$2((code) => code.replaceAll(/\r\n|\r(?!\n)|\n/gu, "\n"), "normalizeLF");
|
|
4
|
+
|
|
5
|
+
const _process = globalThis.process || /* @__PURE__ */ Object.create(null);
|
|
6
|
+
const processShims = {
|
|
7
|
+
versions: {}
|
|
8
|
+
};
|
|
9
|
+
const process = new Proxy(_process, {
|
|
10
|
+
get(target, property) {
|
|
11
|
+
if (property in target) {
|
|
12
|
+
return target[property];
|
|
13
|
+
}
|
|
14
|
+
if (property in processShims) {
|
|
15
|
+
return processShims[property];
|
|
16
|
+
}
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
var __defProp$1 = Object.defineProperty;
|
|
22
|
+
var __name$1 = (target, value) => __defProp$1(target, "name", { value, configurable: true });
|
|
23
|
+
const getMarkerLines = /* @__PURE__ */ __name$1((loc, source, linesAbove, linesBelow) => {
|
|
24
|
+
const startLoc = {
|
|
25
|
+
column: 0,
|
|
26
|
+
// @ts-expect-error Can be overwritten
|
|
27
|
+
line: -1,
|
|
28
|
+
...loc.start
|
|
29
|
+
};
|
|
30
|
+
const endLoc = {
|
|
31
|
+
...startLoc,
|
|
32
|
+
...loc.end
|
|
33
|
+
};
|
|
34
|
+
const startLine = startLoc.line;
|
|
35
|
+
const startColumn = startLoc.column;
|
|
36
|
+
const endLine = endLoc.line;
|
|
37
|
+
const endColumn = endLoc.column;
|
|
38
|
+
let start = Math.max(startLine - (linesAbove + 1), 0);
|
|
39
|
+
let end = Math.min(source.length, endLine + linesBelow);
|
|
40
|
+
if (startLine === -1) {
|
|
41
|
+
start = 0;
|
|
42
|
+
}
|
|
43
|
+
if (endLine === -1) {
|
|
44
|
+
end = source.length;
|
|
45
|
+
}
|
|
46
|
+
const lineDiff = endLine - startLine;
|
|
47
|
+
const markerLines = {};
|
|
48
|
+
if (lineDiff) {
|
|
49
|
+
for (let index = 0; index <= lineDiff; index++) {
|
|
50
|
+
const lineNumber = index + startLine;
|
|
51
|
+
if (!startColumn) {
|
|
52
|
+
markerLines[lineNumber] = true;
|
|
53
|
+
} else if (index === 0) {
|
|
54
|
+
const sourceLength = source[lineNumber - 1]?.length;
|
|
55
|
+
markerLines[lineNumber] = [startColumn, (sourceLength ?? 0) - startColumn + 1];
|
|
56
|
+
} else if (index === lineDiff) {
|
|
57
|
+
markerLines[lineNumber] = [0, endColumn];
|
|
58
|
+
} else {
|
|
59
|
+
const sourceLength = source[lineNumber - index]?.length;
|
|
60
|
+
markerLines[lineNumber] = [0, sourceLength];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
} else if (startColumn === endColumn) {
|
|
64
|
+
markerLines[startLine] = startColumn ? [startColumn, 0] : true;
|
|
65
|
+
} else {
|
|
66
|
+
markerLines[startLine] = [startColumn, (endColumn ?? 0) - (startColumn ?? 0)];
|
|
67
|
+
}
|
|
68
|
+
return { end, markerLines, start };
|
|
69
|
+
}, "getMarkerLines");
|
|
70
|
+
|
|
71
|
+
var __defProp = Object.defineProperty;
|
|
72
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
73
|
+
const CODE_FRAME_POINTER = process.platform === "win32" && !process.env?.WT_SESSION ? ">" : "❯";
|
|
74
|
+
const codeFrame = /* @__PURE__ */ __name((source, loc, options) => {
|
|
75
|
+
const config = {
|
|
76
|
+
// grab 2 lines before, and 3 lines after focused line
|
|
77
|
+
linesAbove: 2,
|
|
78
|
+
linesBelow: 3,
|
|
79
|
+
prefix: "",
|
|
80
|
+
showGutter: true,
|
|
81
|
+
showLineNumbers: true,
|
|
82
|
+
tabWidth: 4,
|
|
83
|
+
...options,
|
|
84
|
+
color: {
|
|
85
|
+
gutter: /* @__PURE__ */ __name((value) => value, "gutter"),
|
|
86
|
+
marker: /* @__PURE__ */ __name((value) => value, "marker"),
|
|
87
|
+
message: /* @__PURE__ */ __name((value) => value, "message"),
|
|
88
|
+
...options?.color
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
const hasColumns = loc.start && typeof loc.start.column === "number";
|
|
92
|
+
let lines = normalizeLF(source).split("\n");
|
|
93
|
+
if (typeof config?.tabWidth === "number") {
|
|
94
|
+
lines = lines.map((ln) => ln.replaceAll(" ", " ".repeat(config.tabWidth)));
|
|
95
|
+
}
|
|
96
|
+
const { end, markerLines, start } = getMarkerLines(loc, lines, config.linesAbove, config.linesBelow);
|
|
97
|
+
const numberMaxWidth = String(end).length;
|
|
98
|
+
const { gutter: colorizeGutter, marker: colorizeMarker, message: colorizeMessage } = config.color;
|
|
99
|
+
let frame = lines.slice(start, end).map((line, index) => {
|
|
100
|
+
const number = start + 1 + index;
|
|
101
|
+
const hasMarker = markerLines[number];
|
|
102
|
+
const paddedNumber = (" " + number).slice(-numberMaxWidth);
|
|
103
|
+
const lastMarkerLine = !markerLines[number + 1];
|
|
104
|
+
const gutter = " " + paddedNumber + (config.showGutter ? " |" : "");
|
|
105
|
+
if (hasMarker) {
|
|
106
|
+
let markerLine = "";
|
|
107
|
+
if (Array.isArray(hasMarker)) {
|
|
108
|
+
const markerSpacing = line.replaceAll(/[^\t]/g, " ").slice(0, Math.max(hasMarker[0] - 1, 0));
|
|
109
|
+
const numberOfMarkers = hasMarker[1] || 1;
|
|
110
|
+
markerLine = [
|
|
111
|
+
"\n ",
|
|
112
|
+
config.prefix + colorizeGutter(gutter.replaceAll(/\d/g, " ")),
|
|
113
|
+
" ",
|
|
114
|
+
markerSpacing,
|
|
115
|
+
colorizeMarker("^").repeat(numberOfMarkers)
|
|
116
|
+
].join("");
|
|
117
|
+
if (lastMarkerLine && config.message) {
|
|
118
|
+
markerLine += ` ${colorizeMessage(config.message)}`;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return [config.prefix + colorizeMarker(CODE_FRAME_POINTER), colorizeGutter(gutter), line.length > 0 ? " " + line : "", markerLine].join("");
|
|
122
|
+
}
|
|
123
|
+
return config.prefix + " " + colorizeGutter(gutter) + (line.length > 0 ? " " + line : "");
|
|
124
|
+
}).join("\n");
|
|
125
|
+
if (config.message && !hasColumns) {
|
|
126
|
+
frame = config.prefix + " ".repeat(numberMaxWidth + 1) + config.message + "\n" + frame;
|
|
127
|
+
}
|
|
128
|
+
return frame;
|
|
129
|
+
}, "codeFrame");
|
|
130
|
+
|
|
131
|
+
export { CODE_FRAME_POINTER, codeFrame };
|
package/dist/error/index.cjs
CHANGED
|
@@ -1 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
4
|
+
|
|
5
|
+
const captureRawStackTrace = require('../packem_shared/captureRawStackTrace-DjD7FUtZ.cjs');
|
|
6
|
+
const getErrorCauses = require('../packem_shared/getErrorCauses-miTeYJEG.cjs');
|
|
7
|
+
const renderError = require('../packem_shared/renderError-NCKbKLok.cjs');
|
|
8
|
+
const serializeError = require('../packem_shared/serializeError-C3BTAUm5.cjs');
|
|
9
|
+
const isVisulimaError = require('../packem_shared/isVisulimaError-BVLWvREw.cjs');
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
exports.captureRawStackTrace = captureRawStackTrace;
|
|
14
|
+
exports.getErrorCauses = getErrorCauses;
|
|
15
|
+
exports.renderError = renderError.renderError;
|
|
16
|
+
exports.serializeError = serializeError.serialize;
|
|
17
|
+
exports.VisulimaError = isVisulimaError.VisulimaError;
|
|
18
|
+
exports.isVisulimaError = isVisulimaError.isVisulimaError;
|
package/dist/error/index.d.cts
CHANGED
|
@@ -2,8 +2,6 @@ import { b as CodeFrameOptions, c as ColorizeMethod } from '../packem_shared/typ
|
|
|
2
2
|
|
|
3
3
|
declare const captureRawStackTrace: () => string | undefined;
|
|
4
4
|
|
|
5
|
-
declare const getErrorCauses: <E = unknown>(error: E) => E[];
|
|
6
|
-
|
|
7
5
|
interface ErrorProperties {
|
|
8
6
|
cause?: Error | unknown;
|
|
9
7
|
hint?: ErrorHint;
|
|
@@ -33,6 +31,8 @@ declare class VisulimaError extends Error {
|
|
|
33
31
|
setHint(hint: ErrorHint): void;
|
|
34
32
|
}
|
|
35
33
|
|
|
34
|
+
declare const getErrorCauses: <E = unknown>(error: E) => E[];
|
|
35
|
+
|
|
36
36
|
type Options$1 = Omit<CodeFrameOptions, "message | prefix"> & {
|
|
37
37
|
color: CodeFrameOptions["color"] & {
|
|
38
38
|
fileLine: ColorizeMethod;
|
package/dist/error/index.d.mts
CHANGED
|
@@ -2,8 +2,6 @@ import { b as CodeFrameOptions, c as ColorizeMethod } from '../packem_shared/typ
|
|
|
2
2
|
|
|
3
3
|
declare const captureRawStackTrace: () => string | undefined;
|
|
4
4
|
|
|
5
|
-
declare const getErrorCauses: <E = unknown>(error: E) => E[];
|
|
6
|
-
|
|
7
5
|
interface ErrorProperties {
|
|
8
6
|
cause?: Error | unknown;
|
|
9
7
|
hint?: ErrorHint;
|
|
@@ -33,6 +31,8 @@ declare class VisulimaError extends Error {
|
|
|
33
31
|
setHint(hint: ErrorHint): void;
|
|
34
32
|
}
|
|
35
33
|
|
|
34
|
+
declare const getErrorCauses: <E = unknown>(error: E) => E[];
|
|
35
|
+
|
|
36
36
|
type Options$1 = Omit<CodeFrameOptions, "message | prefix"> & {
|
|
37
37
|
color: CodeFrameOptions["color"] & {
|
|
38
38
|
fileLine: ColorizeMethod;
|
package/dist/error/index.d.ts
CHANGED
|
@@ -2,8 +2,6 @@ import { b as CodeFrameOptions, c as ColorizeMethod } from '../packem_shared/typ
|
|
|
2
2
|
|
|
3
3
|
declare const captureRawStackTrace: () => string | undefined;
|
|
4
4
|
|
|
5
|
-
declare const getErrorCauses: <E = unknown>(error: E) => E[];
|
|
6
|
-
|
|
7
5
|
interface ErrorProperties {
|
|
8
6
|
cause?: Error | unknown;
|
|
9
7
|
hint?: ErrorHint;
|
|
@@ -33,6 +31,8 @@ declare class VisulimaError extends Error {
|
|
|
33
31
|
setHint(hint: ErrorHint): void;
|
|
34
32
|
}
|
|
35
33
|
|
|
34
|
+
declare const getErrorCauses: <E = unknown>(error: E) => E[];
|
|
35
|
+
|
|
36
36
|
type Options$1 = Omit<CodeFrameOptions, "message | prefix"> & {
|
|
37
37
|
color: CodeFrameOptions["color"] & {
|
|
38
38
|
fileLine: ColorizeMethod;
|
package/dist/error/index.mjs
CHANGED
|
@@ -1 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
export { default as captureRawStackTrace } from '../packem_shared/captureRawStackTrace-CAQrHENg.mjs';
|
|
2
|
+
export { default as getErrorCauses } from '../packem_shared/getErrorCauses-CG_JRE6j.mjs';
|
|
3
|
+
export { renderError } from '../packem_shared/renderError-DV9rZ4rp.mjs';
|
|
4
|
+
export { serialize as serializeError } from '../packem_shared/serializeError-BNAsxuJ_.mjs';
|
|
5
|
+
export { VisulimaError, isVisulimaError } from '../packem_shared/isVisulimaError-H6TqEA42.mjs';
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
4
|
+
|
|
5
|
+
const codeFrame_index = require('./code-frame/index.cjs');
|
|
6
|
+
const indexToLineColumn = require('./packem_shared/indexToLineColumn-DjmjeiIY.cjs');
|
|
7
|
+
const captureRawStackTrace = require('./packem_shared/captureRawStackTrace-DjD7FUtZ.cjs');
|
|
8
|
+
const getErrorCauses = require('./packem_shared/getErrorCauses-miTeYJEG.cjs');
|
|
9
|
+
const parseStacktrace = require('./packem_shared/parseStacktrace-CPbfvO-n.cjs');
|
|
10
|
+
const isVisulimaError = require('./packem_shared/isVisulimaError-BVLWvREw.cjs');
|
|
11
|
+
const renderError = require('./packem_shared/renderError-NCKbKLok.cjs');
|
|
12
|
+
const serializeError = require('./packem_shared/serializeError-C3BTAUm5.cjs');
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
exports.CODE_FRAME_POINTER = codeFrame_index.CODE_FRAME_POINTER;
|
|
17
|
+
exports.codeFrame = codeFrame_index.codeFrame;
|
|
18
|
+
exports.indexToLineColumn = indexToLineColumn;
|
|
19
|
+
exports.captureRawStackTrace = captureRawStackTrace;
|
|
20
|
+
exports.getErrorCauses = getErrorCauses;
|
|
21
|
+
exports.parseStacktrace = parseStacktrace;
|
|
22
|
+
exports.VisulimaError = isVisulimaError.VisulimaError;
|
|
23
|
+
exports.isVisulimaError = isVisulimaError.isVisulimaError;
|
|
24
|
+
exports.renderError = renderError.renderError;
|
|
25
|
+
exports.serializeError = serializeError.serialize;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
export { CODE_FRAME_POINTER, codeFrame } from './code-frame/index.mjs';
|
|
2
|
+
export { default as indexToLineColumn } from './packem_shared/indexToLineColumn-Dx91YDU1.mjs';
|
|
3
|
+
export { default as captureRawStackTrace } from './packem_shared/captureRawStackTrace-CAQrHENg.mjs';
|
|
4
|
+
export { default as getErrorCauses } from './packem_shared/getErrorCauses-CG_JRE6j.mjs';
|
|
5
|
+
export { default as parseStacktrace } from './packem_shared/parseStacktrace-B-BUrkkI.mjs';
|
|
6
|
+
export { VisulimaError, isVisulimaError } from './packem_shared/isVisulimaError-H6TqEA42.mjs';
|
|
7
|
+
export { renderError } from './packem_shared/renderError-DV9rZ4rp.mjs';
|
|
8
|
+
export { serialize as serializeError } from './packem_shared/serializeError-BNAsxuJ_.mjs';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
const captureRawStackTrace = /* @__PURE__ */ __name(() => {
|
|
4
|
+
if (!Error.captureStackTrace) {
|
|
5
|
+
return undefined;
|
|
6
|
+
}
|
|
7
|
+
const stack = new Error();
|
|
8
|
+
Error.captureStackTrace(stack);
|
|
9
|
+
return stack.stack;
|
|
10
|
+
}, "captureRawStackTrace");
|
|
11
|
+
|
|
12
|
+
export { captureRawStackTrace as default };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
const captureRawStackTrace = /* @__PURE__ */ __name(() => {
|
|
6
|
+
if (!Error.captureStackTrace) {
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
const stack = new Error();
|
|
10
|
+
Error.captureStackTrace(stack);
|
|
11
|
+
return stack.stack;
|
|
12
|
+
}, "captureRawStackTrace");
|
|
13
|
+
|
|
14
|
+
module.exports = captureRawStackTrace;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { inspect } from 'node:util';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
const getErrorCauses = /* @__PURE__ */ __name((error) => {
|
|
6
|
+
const seen = /* @__PURE__ */ new Set();
|
|
7
|
+
const causes = [];
|
|
8
|
+
let currentError = error;
|
|
9
|
+
while (currentError) {
|
|
10
|
+
if (seen.has(currentError)) {
|
|
11
|
+
console.error(`Circular reference detected in error causes: ${inspect(error)}`);
|
|
12
|
+
break;
|
|
13
|
+
}
|
|
14
|
+
causes.push(currentError);
|
|
15
|
+
seen.add(currentError);
|
|
16
|
+
if (!currentError.cause) {
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
currentError = currentError.cause;
|
|
20
|
+
}
|
|
21
|
+
return causes;
|
|
22
|
+
}, "getErrorCauses");
|
|
23
|
+
|
|
24
|
+
export { getErrorCauses as default };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const node_util = require('node:util');
|
|
4
|
+
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
const getErrorCauses = /* @__PURE__ */ __name((error) => {
|
|
8
|
+
const seen = /* @__PURE__ */ new Set();
|
|
9
|
+
const causes = [];
|
|
10
|
+
let currentError = error;
|
|
11
|
+
while (currentError) {
|
|
12
|
+
if (seen.has(currentError)) {
|
|
13
|
+
console.error(`Circular reference detected in error causes: ${node_util.inspect(error)}`);
|
|
14
|
+
break;
|
|
15
|
+
}
|
|
16
|
+
causes.push(currentError);
|
|
17
|
+
seen.add(currentError);
|
|
18
|
+
if (!currentError.cause) {
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
currentError = currentError.cause;
|
|
22
|
+
}
|
|
23
|
+
return causes;
|
|
24
|
+
}, "getErrorCauses");
|
|
25
|
+
|
|
26
|
+
module.exports = getErrorCauses;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
const binarySearch = /* @__PURE__ */ __name((element, array) => {
|
|
6
|
+
let m = 0;
|
|
7
|
+
let n = array.length - 2;
|
|
8
|
+
while (m < n) {
|
|
9
|
+
const key = m + (n - m >> 1);
|
|
10
|
+
if (element < array[key]) {
|
|
11
|
+
n = key - 1;
|
|
12
|
+
} else if (element >= array[key + 1]) {
|
|
13
|
+
m = key + 1;
|
|
14
|
+
} else {
|
|
15
|
+
m = key;
|
|
16
|
+
break;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return m;
|
|
20
|
+
}, "binarySearch");
|
|
21
|
+
const getLineStartIndexes = /* @__PURE__ */ __name((string_) => (
|
|
22
|
+
// eslint-disable-next-line unicorn/no-array-reduce
|
|
23
|
+
string_.split(/\n|\r(?!\n)/).reduce(
|
|
24
|
+
(accumulator, current) => {
|
|
25
|
+
accumulator.push(accumulator.at(-1) + current.length + 1);
|
|
26
|
+
return accumulator;
|
|
27
|
+
},
|
|
28
|
+
[0]
|
|
29
|
+
)
|
|
30
|
+
), "getLineStartIndexes");
|
|
31
|
+
const indexToLineColumn = /* @__PURE__ */ __name((input, index, options) => {
|
|
32
|
+
const skipChecks = options?.skipChecks ?? false;
|
|
33
|
+
if (!skipChecks && (!Array.isArray(input) && typeof input !== "string" || (typeof input === "string" || Array.isArray(input)) && input.length === 0)) {
|
|
34
|
+
return { column: 0, line: 0 };
|
|
35
|
+
}
|
|
36
|
+
if (!skipChecks && (typeof index !== "number" || typeof input === "string" && index >= input.length || Array.isArray(input) && index + 1 >= input.at(-1))) {
|
|
37
|
+
return { column: 0, line: 0 };
|
|
38
|
+
}
|
|
39
|
+
if (typeof input === "string") {
|
|
40
|
+
const startIndexesOfEachLine = getLineStartIndexes(input);
|
|
41
|
+
const line2 = binarySearch(index, startIndexesOfEachLine);
|
|
42
|
+
return {
|
|
43
|
+
// eslint-disable-next-line security/detect-object-injection
|
|
44
|
+
column: index - startIndexesOfEachLine[line2] + 1,
|
|
45
|
+
line: line2 + 1
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const line = binarySearch(index, input);
|
|
49
|
+
return {
|
|
50
|
+
// eslint-disable-next-line security/detect-object-injection
|
|
51
|
+
column: index - input[line] + 1,
|
|
52
|
+
line: line + 1
|
|
53
|
+
};
|
|
54
|
+
}, "indexToLineColumn");
|
|
55
|
+
|
|
56
|
+
module.exports = indexToLineColumn;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
const binarySearch = /* @__PURE__ */ __name((element, array) => {
|
|
4
|
+
let m = 0;
|
|
5
|
+
let n = array.length - 2;
|
|
6
|
+
while (m < n) {
|
|
7
|
+
const key = m + (n - m >> 1);
|
|
8
|
+
if (element < array[key]) {
|
|
9
|
+
n = key - 1;
|
|
10
|
+
} else if (element >= array[key + 1]) {
|
|
11
|
+
m = key + 1;
|
|
12
|
+
} else {
|
|
13
|
+
m = key;
|
|
14
|
+
break;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return m;
|
|
18
|
+
}, "binarySearch");
|
|
19
|
+
const getLineStartIndexes = /* @__PURE__ */ __name((string_) => (
|
|
20
|
+
// eslint-disable-next-line unicorn/no-array-reduce
|
|
21
|
+
string_.split(/\n|\r(?!\n)/).reduce(
|
|
22
|
+
(accumulator, current) => {
|
|
23
|
+
accumulator.push(accumulator.at(-1) + current.length + 1);
|
|
24
|
+
return accumulator;
|
|
25
|
+
},
|
|
26
|
+
[0]
|
|
27
|
+
)
|
|
28
|
+
), "getLineStartIndexes");
|
|
29
|
+
const indexToLineColumn = /* @__PURE__ */ __name((input, index, options) => {
|
|
30
|
+
const skipChecks = options?.skipChecks ?? false;
|
|
31
|
+
if (!skipChecks && (!Array.isArray(input) && typeof input !== "string" || (typeof input === "string" || Array.isArray(input)) && input.length === 0)) {
|
|
32
|
+
return { column: 0, line: 0 };
|
|
33
|
+
}
|
|
34
|
+
if (!skipChecks && (typeof index !== "number" || typeof input === "string" && index >= input.length || Array.isArray(input) && index + 1 >= input.at(-1))) {
|
|
35
|
+
return { column: 0, line: 0 };
|
|
36
|
+
}
|
|
37
|
+
if (typeof input === "string") {
|
|
38
|
+
const startIndexesOfEachLine = getLineStartIndexes(input);
|
|
39
|
+
const line2 = binarySearch(index, startIndexesOfEachLine);
|
|
40
|
+
return {
|
|
41
|
+
// eslint-disable-next-line security/detect-object-injection
|
|
42
|
+
column: index - startIndexesOfEachLine[line2] + 1,
|
|
43
|
+
line: line2 + 1
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
const line = binarySearch(index, input);
|
|
47
|
+
return {
|
|
48
|
+
// eslint-disable-next-line security/detect-object-injection
|
|
49
|
+
column: index - input[line] + 1,
|
|
50
|
+
line: line + 1
|
|
51
|
+
};
|
|
52
|
+
}, "indexToLineColumn");
|
|
53
|
+
|
|
54
|
+
export { indexToLineColumn as default };
|