@idlebox/common 1.4.0 → 1.4.2
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/lib/cjs/__create_index.generated.cjs +12 -4
- package/lib/cjs/__create_index.generated.cjs.map +1 -1
- package/lib/cjs/date/timeString.cjs +4 -4
- package/lib/cjs/date/timeString.cjs.map +1 -1
- package/lib/cjs/error/convertUnknown.cjs +2 -2
- package/lib/cjs/error/convertUnknown.cjs.map +1 -1
- package/lib/cjs/error/known.cjs +2 -2
- package/lib/cjs/error/known.cjs.map +1 -1
- package/lib/cjs/error/pretty.cjs +225 -154
- package/lib/cjs/error/pretty.cjs.map +1 -1
- package/lib/cjs/function/asyncCallbackList.cjs +2 -2
- package/lib/cjs/function/asyncCallbackList.cjs.map +1 -1
- package/lib/cjs/function/callbackList.cjs +2 -2
- package/lib/cjs/function/callbackList.cjs.map +1 -1
- package/lib/cjs/function/delayCallbackList.cjs +2 -2
- package/lib/cjs/function/delayCallbackList.cjs.map +1 -1
- package/lib/cjs/lifecycle/dispose/disposedError.cjs +7 -7
- package/lib/cjs/lifecycle/dispose/disposedError.cjs.map +1 -1
- package/lib/cjs/lifecycle/dispose/lifecycle.async.cjs +8 -8
- package/lib/cjs/lifecycle/dispose/lifecycle.async.cjs.map +1 -1
- package/lib/cjs/lifecycle/dispose/lifecycle.global.cjs +9 -9
- package/lib/cjs/lifecycle/dispose/lifecycle.global.cjs.map +1 -1
- package/lib/cjs/lifecycle/dispose/lifecycle.sync.cjs +7 -7
- package/lib/cjs/lifecycle/dispose/lifecycle.sync.cjs.map +1 -1
- package/lib/cjs/lifecycle/event/event.cjs +61 -6
- package/lib/cjs/lifecycle/event/event.cjs.map +1 -1
- package/lib/cjs/lifecycle/event/memorized.cjs +2 -2
- package/lib/cjs/lifecycle/event/memorized.cjs.map +1 -1
- package/lib/cjs/lifecycle/promise/cancellationToken/driver.common.cjs +2 -2
- package/lib/cjs/lifecycle/promise/cancellationToken/driver.common.cjs.map +1 -1
- package/lib/cjs/lifecycle/promise/cancellationToken/source.cjs +8 -8
- package/lib/cjs/lifecycle/promise/cancellationToken/source.cjs.map +1 -1
- package/lib/cjs/lifecycle/promise/deferredPromise.cjs +2 -2
- package/lib/cjs/lifecycle/promise/deferredPromise.cjs.map +1 -1
- package/lib/cjs/lifecycle/timeout/timeout.cjs +4 -4
- package/lib/cjs/lifecycle/timeout/timeout.cjs.map +1 -1
- package/lib/cjs/lifecycle/timeout/timeoutError.cjs +2 -2
- package/lib/cjs/lifecycle/timeout/timeoutError.cjs.map +1 -1
- package/lib/cjs/log/logger.cjs +6 -6
- package/lib/cjs/log/logger.cjs.map +1 -1
- package/lib/cjs/misc/package.json.cjs +22 -0
- package/lib/cjs/misc/package.json.cjs.map +1 -1
- package/lib/cjs/object/definePublicConstant.cjs +9 -3
- package/lib/cjs/object/definePublicConstant.cjs.map +1 -1
- package/lib/cjs/object/objectSame.cjs +4 -4
- package/lib/cjs/object/objectSame.cjs.map +1 -1
- package/lib/cjs/path/pathArray.cjs +9 -9
- package/lib/cjs/path/pathArray.cjs.map +1 -1
- package/lib/cjs/platform/globalSingleton.cjs +5 -5
- package/lib/cjs/platform/globalSingleton.cjs.map +1 -1
- package/lib/cjs/platform/globalSymbol.cjs +2 -2
- package/lib/cjs/platform/globalSymbol.cjs.map +1 -1
- package/lib/cjs/promise/promiseCollection.cjs +4 -4
- package/lib/cjs/promise/promiseCollection.cjs.map +1 -1
- package/lib/cjs/promise/timeoutPromiseCollection.cjs +4 -4
- package/lib/cjs/promise/timeoutPromiseCollection.cjs.map +1 -1
- package/lib/cjs/reflection/classes/singleton.cjs +2 -2
- package/lib/cjs/reflection/classes/singleton.cjs.map +1 -1
- package/lib/cjs/reflection/methods/initOnRead.cjs +2 -2
- package/lib/cjs/reflection/methods/initOnRead.cjs.map +1 -1
- package/lib/cjs/state/StateMachine.cjs +2 -2
- package/lib/cjs/state/StateMachine.cjs.map +1 -1
- package/lib/cjs/string/concatType.generated.cjs +0 -1
- package/lib/cjs/string/concatType.generated.cjs.map +1 -1
- package/lib/esm/__create_index.generated.d.ts +9 -0
- package/lib/esm/__create_index.generated.d.ts.map +1 -1
- package/lib/esm/__create_index.generated.js +4 -0
- package/lib/esm/__create_index.generated.js.map +1 -1
- package/lib/esm/__virtual_tsconfig.tsbuildinfo +1 -1
- package/lib/esm/array/arrayUnique.d.ts.map +1 -1
- package/lib/esm/date/timeString.js +1 -1
- package/lib/esm/date/timeString.js.map +1 -1
- package/lib/esm/error/convertUnknown.js +1 -1
- package/lib/esm/error/convertUnknown.js.map +1 -1
- package/lib/esm/error/known.js +1 -1
- package/lib/esm/error/known.js.map +1 -1
- package/lib/esm/error/pretty.d.ts +34 -1
- package/lib/esm/error/pretty.d.ts.map +1 -1
- package/lib/esm/error/pretty.js +219 -150
- package/lib/esm/error/pretty.js.map +1 -1
- package/lib/esm/function/asyncCallbackList.js +1 -1
- package/lib/esm/function/asyncCallbackList.js.map +1 -1
- package/lib/esm/function/callbackList.js +1 -1
- package/lib/esm/function/callbackList.js.map +1 -1
- package/lib/esm/function/delayCallbackList.js +1 -1
- package/lib/esm/function/delayCallbackList.js.map +1 -1
- package/lib/esm/lifecycle/dispose/disposableEvent.d.ts +1 -1
- package/lib/esm/lifecycle/dispose/disposableEvent.d.ts.map +1 -1
- package/lib/esm/lifecycle/dispose/disposedError.js +3 -3
- package/lib/esm/lifecycle/dispose/disposedError.js.map +1 -1
- package/lib/esm/lifecycle/dispose/lifecycle.async.d.ts +2 -2
- package/lib/esm/lifecycle/dispose/lifecycle.async.d.ts.map +1 -1
- package/lib/esm/lifecycle/dispose/lifecycle.async.js +3 -3
- package/lib/esm/lifecycle/dispose/lifecycle.async.js.map +1 -1
- package/lib/esm/lifecycle/dispose/lifecycle.d.ts +1 -1
- package/lib/esm/lifecycle/dispose/lifecycle.d.ts.map +1 -1
- package/lib/esm/lifecycle/dispose/lifecycle.global.d.ts +2 -2
- package/lib/esm/lifecycle/dispose/lifecycle.global.d.ts.map +1 -1
- package/lib/esm/lifecycle/dispose/lifecycle.global.js +3 -3
- package/lib/esm/lifecycle/dispose/lifecycle.global.js.map +1 -1
- package/lib/esm/lifecycle/dispose/lifecycle.sync.d.ts +2 -2
- package/lib/esm/lifecycle/dispose/lifecycle.sync.d.ts.map +1 -1
- package/lib/esm/lifecycle/dispose/lifecycle.sync.js +2 -2
- package/lib/esm/lifecycle/dispose/lifecycle.sync.js.map +1 -1
- package/lib/esm/lifecycle/event/event.d.ts +13 -1
- package/lib/esm/lifecycle/event/event.d.ts.map +1 -1
- package/lib/esm/lifecycle/event/event.js +61 -6
- package/lib/esm/lifecycle/event/event.js.map +1 -1
- package/lib/esm/lifecycle/event/memorized.d.ts +2 -2
- package/lib/esm/lifecycle/event/memorized.d.ts.map +1 -1
- package/lib/esm/lifecycle/event/memorized.js +1 -1
- package/lib/esm/lifecycle/event/memorized.js.map +1 -1
- package/lib/esm/lifecycle/promise/cancellationToken/driver.browser.d.ts +1 -1
- package/lib/esm/lifecycle/promise/cancellationToken/driver.browser.d.ts.map +1 -1
- package/lib/esm/lifecycle/promise/cancellationToken/driver.common.d.ts +1 -1
- package/lib/esm/lifecycle/promise/cancellationToken/driver.common.d.ts.map +1 -1
- package/lib/esm/lifecycle/promise/cancellationToken/driver.common.js +1 -1
- package/lib/esm/lifecycle/promise/cancellationToken/driver.common.js.map +1 -1
- package/lib/esm/lifecycle/promise/cancellationToken/source.d.ts +3 -3
- package/lib/esm/lifecycle/promise/cancellationToken/source.d.ts.map +1 -1
- package/lib/esm/lifecycle/promise/cancellationToken/source.js +4 -4
- package/lib/esm/lifecycle/promise/cancellationToken/source.js.map +1 -1
- package/lib/esm/lifecycle/promise/deferredPromise.js +1 -1
- package/lib/esm/lifecycle/promise/deferredPromise.js.map +1 -1
- package/lib/esm/lifecycle/timeout/timeout.d.ts +1 -1
- package/lib/esm/lifecycle/timeout/timeout.d.ts.map +1 -1
- package/lib/esm/lifecycle/timeout/timeout.js +2 -2
- package/lib/esm/lifecycle/timeout/timeout.js.map +1 -1
- package/lib/esm/lifecycle/timeout/timeoutError.js +1 -1
- package/lib/esm/lifecycle/timeout/timeoutError.js.map +1 -1
- package/lib/esm/log/logger.js +2 -2
- package/lib/esm/log/logger.js.map +1 -1
- package/lib/esm/misc/package.json.d.ts +19 -1
- package/lib/esm/misc/package.json.d.ts.map +1 -1
- package/lib/esm/misc/package.json.js +21 -1
- package/lib/esm/misc/package.json.js.map +1 -1
- package/lib/esm/object/definePublicConstant.d.ts +1 -0
- package/lib/esm/object/definePublicConstant.d.ts.map +1 -1
- package/lib/esm/object/definePublicConstant.js +8 -3
- package/lib/esm/object/definePublicConstant.js.map +1 -1
- package/lib/esm/object/objectSame.js +1 -1
- package/lib/esm/object/objectSame.js.map +1 -1
- package/lib/esm/path/pathArray.js +3 -3
- package/lib/esm/path/pathArray.js.map +1 -1
- package/lib/esm/platform/globalSingleton.js +2 -2
- package/lib/esm/platform/globalSingleton.js.map +1 -1
- package/lib/esm/platform/globalSymbol.js +1 -1
- package/lib/esm/platform/globalSymbol.js.map +1 -1
- package/lib/esm/promise/promiseCollection.d.ts +2 -2
- package/lib/esm/promise/promiseCollection.d.ts.map +1 -1
- package/lib/esm/promise/promiseCollection.js +2 -2
- package/lib/esm/promise/promiseCollection.js.map +1 -1
- package/lib/esm/promise/timeoutPromiseCollection.d.ts +2 -2
- package/lib/esm/promise/timeoutPromiseCollection.d.ts.map +1 -1
- package/lib/esm/promise/timeoutPromiseCollection.js +2 -2
- package/lib/esm/promise/timeoutPromiseCollection.js.map +1 -1
- package/lib/esm/reflection/classes/singleton.js +1 -1
- package/lib/esm/reflection/classes/singleton.js.map +1 -1
- package/lib/esm/reflection/methods/initOnRead.d.ts +1 -1
- package/lib/esm/reflection/methods/initOnRead.d.ts.map +1 -1
- package/lib/esm/reflection/methods/initOnRead.js +1 -1
- package/lib/esm/reflection/methods/initOnRead.js.map +1 -1
- package/lib/esm/state/StateMachine.d.ts +1 -1
- package/lib/esm/state/StateMachine.d.ts.map +1 -1
- package/lib/esm/state/StateMachine.js +1 -1
- package/lib/esm/state/StateMachine.js.map +1 -1
- package/lib/esm/string/concatType.generated.d.ts.map +1 -1
- package/lib/esm/string/concatType.generated.js +0 -1
- package/lib/esm/string/concatType.generated.js.map +1 -1
- package/lib/esm/typingHelper/deep.partial.d.ts +1 -1
- package/lib/esm/typingHelper/deep.partial.d.ts.map +1 -1
- package/lib/esm/typingHelper/deep.readonly.d.ts +1 -1
- package/lib/esm/typingHelper/deep.readonly.d.ts.map +1 -1
- package/lib/esm/typingHelper/deep.required.d.ts +1 -1
- package/lib/esm/typingHelper/deep.required.d.ts.map +1 -1
- package/lib/esm/typingHelper/deep.writable.d.ts +1 -1
- package/lib/esm/typingHelper/deep.writable.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/date/timeString.ts +1 -1
- package/src/error/convertUnknown.ts +1 -1
- package/src/error/known.ts +1 -1
- package/src/error/pretty.ts +269 -153
- package/src/function/asyncCallbackList.ts +1 -1
- package/src/function/callbackList.ts +1 -1
- package/src/function/delayCallbackList.ts +1 -1
- package/src/lifecycle/dispose/disposableEvent.ts +1 -1
- package/src/lifecycle/dispose/disposedError.ts +3 -3
- package/src/lifecycle/dispose/lifecycle.async.ts +4 -4
- package/src/lifecycle/dispose/lifecycle.global.ts +4 -4
- package/src/lifecycle/dispose/lifecycle.sync.ts +3 -3
- package/src/lifecycle/dispose/lifecycle.ts +1 -1
- package/src/lifecycle/event/event.ts +64 -7
- package/src/lifecycle/event/memorized.ts +2 -2
- package/src/lifecycle/promise/cancellationToken/driver.browser.ts +2 -2
- package/src/lifecycle/promise/cancellationToken/driver.common.ts +3 -3
- package/src/lifecycle/promise/cancellationToken/source.ts +6 -6
- package/src/lifecycle/promise/deferredPromise.ts +1 -1
- package/src/lifecycle/timeout/timeout.ts +2 -2
- package/src/lifecycle/timeout/timeoutError.ts +1 -1
- package/src/log/logger.ts +2 -2
- package/src/misc/package.json.ts +45 -1
- package/src/object/definePublicConstant.ts +9 -2
- package/src/object/objectSame.ts +1 -1
- package/src/path/pathArray.ts +3 -3
- package/src/platform/globalSingleton.ts +2 -2
- package/src/platform/globalSymbol.ts +1 -1
- package/src/promise/promiseCollection.ts +2 -2
- package/src/promise/timeoutPromiseCollection.ts +2 -2
- package/src/reflection/classes/singleton.ts +1 -1
- package/src/reflection/methods/initOnRead.ts +1 -1
- package/src/state/StateMachine.ts +1 -1
- package/src/string/concatType.generated.ts +0 -3
- package/src/string/concatType.generator.ts +3 -13
- package/src/typingHelper/deep.partial.ts +1 -1
- package/src/typingHelper/deep.readonly.ts +1 -1
- package/src/typingHelper/deep.required.ts +1 -1
- package/src/typingHelper/deep.writable.ts +1 -1
package/src/error/pretty.ts
CHANGED
|
@@ -1,57 +1,146 @@
|
|
|
1
|
-
import { isAbsolute } from '../path/isAbsolute';
|
|
2
|
-
import { relativePath } from '../path/normalizePath';
|
|
3
|
-
import { globalObject } from '../platform/globalObject';
|
|
4
|
-
import { isNative } from '../platform/os';
|
|
1
|
+
import { isAbsolute } from '../path/isAbsolute.js';
|
|
2
|
+
import { relativePath } from '../path/normalizePath.js';
|
|
3
|
+
import { globalObject } from '../platform/globalObject.js';
|
|
4
|
+
import { isNative } from '../platform/os.js';
|
|
5
5
|
|
|
6
|
-
const regNormal = /^\s+at ([^\/\s]+)(?: \[as ([^\]]+)])? \(((?:node|file):\/*)?([^:]+)(:\d+)?(:\d+)\)$/;
|
|
7
6
|
const process = globalObject.process;
|
|
8
7
|
const window = globalObject.window;
|
|
9
8
|
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
const padding = /^(?<padding>\s*)at /.source;
|
|
10
|
+
const func_call = /(?<func_name>(?:async )?[^\/\\\s]+) (?:\[as (?<func_alias>[^\]]+)] )?/.source;
|
|
11
|
+
// [xxxx.yyyyy] [as eval]
|
|
12
|
+
const line_column = /(?::(?<line>\d+))?(?::(?<column>\d+))?/.source;
|
|
13
|
+
const locationEsm = /(?<schema>node:|file:\/\/|https?:\/\/)?(?<path2>[^:]+)/.source;
|
|
14
|
+
// node:internal/modules/cjs/loader.js:883:14
|
|
15
|
+
const locationCjs = /(?<path1>(?:\/|[a-zA-Z]:)[^:]+)/.source;
|
|
16
|
+
// /data/to/file.js
|
|
17
|
+
const location = `(?:${locationCjs}|${locationEsm})${line_column}`;
|
|
18
18
|
|
|
19
|
-
const
|
|
19
|
+
const regNormal = new RegExp(`${padding}${func_call}\\(${location}\\)$`);
|
|
20
|
+
type TypeMatchNormal = 'padding' | TypeMatchNoFile | TypeMatchFileOnly;
|
|
20
21
|
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
22
|
+
const regNoFile = new RegExp(`${padding}${func_call}$`);
|
|
23
|
+
type TypeMatchNoFile = 'padding' | 'func_name' | 'func_alias';
|
|
24
|
+
|
|
25
|
+
const regFileOnly = new RegExp(`${padding}${location}$`);
|
|
26
|
+
type TypeMatchFileOnly = 'padding' | 'schema' | 'path1' | 'path2' | 'line' | 'column';
|
|
25
27
|
|
|
26
|
-
const
|
|
28
|
+
const regEvalItem = new RegExp(`\\(eval at ${func_call}`, 'g');
|
|
29
|
+
const eval_source = /, (?<eval_func>[\S]+):(?<eval_line>\d+):(?<eval_column>\d+)/.source;
|
|
30
|
+
const regEval = new RegExp(`${padding}${func_call}.*?\\(${location}\\)+${eval_source}`);
|
|
31
|
+
type TypeMatchEval = 'padding' | TypeMatchNoFile | TypeMatchFileOnly | 'eval_func' | 'eval_line' | 'eval_column';
|
|
27
32
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
column,
|
|
33
|
+
let root = process?.cwd?.() ?? window?.location?.domain ?? '/';
|
|
34
|
+
export function setErrorLogRoot(_root: string) {
|
|
35
|
+
root = _root;
|
|
32
36
|
}
|
|
33
37
|
|
|
34
|
-
|
|
38
|
+
interface IFunction {
|
|
39
|
+
name: string;
|
|
40
|
+
alias?: string;
|
|
41
|
+
}
|
|
42
|
+
interface IFileLocation {
|
|
43
|
+
path: string;
|
|
44
|
+
schema: string; // '' | 'node:' | 'file:' | 'http:' | 'https:';
|
|
45
|
+
line: number;
|
|
46
|
+
column: number;
|
|
47
|
+
isAbsolute: boolean;
|
|
48
|
+
}
|
|
49
|
+
interface IEvalDef {
|
|
50
|
+
eval_func: string;
|
|
51
|
+
eval_line: number;
|
|
52
|
+
eval_column: number;
|
|
53
|
+
funcs: string[];
|
|
54
|
+
}
|
|
35
55
|
|
|
36
|
-
|
|
37
|
-
|
|
56
|
+
export interface IStructreStackLine {
|
|
57
|
+
invalid?: boolean;
|
|
58
|
+
toString(): string;
|
|
59
|
+
padding?: string;
|
|
60
|
+
func?: IFunction;
|
|
61
|
+
location?: IFileLocation;
|
|
62
|
+
eval?: IEvalDef;
|
|
38
63
|
}
|
|
39
64
|
|
|
40
|
-
|
|
65
|
+
function matchLine<T extends string>(line: string, reg: RegExp): null | Record<T, string> {
|
|
66
|
+
const m = reg.exec(line);
|
|
67
|
+
if (!m) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
return m.groups as any;
|
|
71
|
+
}
|
|
72
|
+
function addLoc(ret: IStructreStackLine, m: Record<TypeMatchFileOnly, string>) {
|
|
73
|
+
const path = m.path1 || m.path2;
|
|
74
|
+
ret.location = {
|
|
75
|
+
schema: m.schema?.replace(/\/+$/, '') ?? '',
|
|
76
|
+
path: path,
|
|
77
|
+
line: parseInt(m.line),
|
|
78
|
+
column: parseInt(m.column),
|
|
79
|
+
isAbsolute: isAbsolute(path),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
41
82
|
|
|
42
|
-
|
|
43
|
-
|
|
83
|
+
function addFunc(ret: IStructreStackLine, m: Record<TypeMatchNoFile, string>) {
|
|
84
|
+
ret.func = {
|
|
85
|
+
name: m.func_name,
|
|
86
|
+
alias: m.func_alias,
|
|
87
|
+
};
|
|
44
88
|
}
|
|
45
89
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
90
|
+
export function parseStackLine(line: string): IStructreStackLine {
|
|
91
|
+
const __raw = line;
|
|
92
|
+
const ret: IStructreStackLine = {
|
|
93
|
+
invalid: false,
|
|
94
|
+
toString() {
|
|
95
|
+
return __raw;
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
Object.assign(ret, { __raw });
|
|
99
|
+
const mNormal = matchLine<TypeMatchNormal>(line, regNormal);
|
|
100
|
+
|
|
101
|
+
if (mNormal) {
|
|
102
|
+
ret.padding = mNormal.padding;
|
|
103
|
+
addFunc(ret, mNormal);
|
|
104
|
+
addLoc(ret, mNormal);
|
|
105
|
+
return ret;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const mFile = matchLine<TypeMatchFileOnly>(line, regFileOnly);
|
|
109
|
+
if (mFile) {
|
|
110
|
+
ret.padding = mFile.padding;
|
|
111
|
+
addLoc(ret, mFile);
|
|
112
|
+
return ret;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const mNoFile = matchLine<TypeMatchNoFile>(line, regNoFile);
|
|
116
|
+
if (mNoFile) {
|
|
117
|
+
ret.padding = mNoFile.padding;
|
|
118
|
+
addFunc(ret, mNoFile);
|
|
119
|
+
return ret;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const mEval = matchLine<TypeMatchEval>(line.replaceAll(regEvalItem, ''), regEval);
|
|
123
|
+
if (mEval) {
|
|
124
|
+
ret.padding = mEval.padding;
|
|
125
|
+
addFunc(ret, mEval);
|
|
126
|
+
addLoc(ret, mEval);
|
|
127
|
+
|
|
128
|
+
ret.eval = {
|
|
129
|
+
eval_column: parseInt(mEval.eval_column),
|
|
130
|
+
eval_func: mEval.eval_func,
|
|
131
|
+
eval_line: parseInt(mEval.eval_line),
|
|
132
|
+
funcs: [],
|
|
133
|
+
};
|
|
134
|
+
for (const item of line.matchAll(regEvalItem)) {
|
|
135
|
+
ret.eval.funcs.push(item.groups!.func_name);
|
|
136
|
+
}
|
|
137
|
+
ret.eval.funcs.push(mEval.eval_func);
|
|
138
|
+
|
|
139
|
+
return ret;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
ret.invalid = true;
|
|
143
|
+
return ret;
|
|
55
144
|
}
|
|
56
145
|
|
|
57
146
|
let notify_printed = false;
|
|
@@ -60,7 +149,7 @@ export function prettyPrintError(type: string, e: Error) {
|
|
|
60
149
|
return console.error(e.message);
|
|
61
150
|
}
|
|
62
151
|
|
|
63
|
-
if (globalObject.DISABLE_PRETTY_ERROR || process?.env?.DISABLE_PRETTY_ERROR) {
|
|
152
|
+
if (globalObject.DISABLE_PRETTY_ERROR || globalObject.process?.env?.DISABLE_PRETTY_ERROR) {
|
|
64
153
|
console.error('[%s] %s', type, e.stack || e.message);
|
|
65
154
|
return;
|
|
66
155
|
}
|
|
@@ -81,120 +170,125 @@ function red(s: string) {
|
|
|
81
170
|
return isNative ? `\x1B[38;5;9m${s}\x1B[0m` : s;
|
|
82
171
|
}
|
|
83
172
|
|
|
84
|
-
export function
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
if (!e.stack) {
|
|
90
|
-
return red(e.message + '\n No stack trace');
|
|
91
|
-
}
|
|
92
|
-
const stackStr = e.stack.replace(/(file|http|https):\/\//gi, '').split(/\n/g);
|
|
93
|
-
|
|
94
|
-
let first = stackStr.shift()!;
|
|
95
|
-
const stack: IInternalData[] = stackStr.map((line) => {
|
|
96
|
-
if (regNormal.test(line)) {
|
|
97
|
-
const m = regNormal.exec(line)!;
|
|
98
|
-
return {
|
|
99
|
-
fn: m[regNormalMatch.fn],
|
|
100
|
-
as: m[regNormalMatch.fnAlias],
|
|
101
|
-
fileSchema: m[regNormalMatch.fileSchema],
|
|
102
|
-
file: m[regNormalMatch.file],
|
|
103
|
-
line: parseInt(m[regNormalMatch.row].slice(1)),
|
|
104
|
-
col: parseInt(m[regNormalMatch.column].slice(1)),
|
|
105
|
-
abs: isAbsolute(m[regNormalMatch.file]),
|
|
106
|
-
};
|
|
107
|
-
} else if (regFunctionOnly.test(line)) {
|
|
108
|
-
const m = regFunctionOnly.exec(line)!;
|
|
109
|
-
return {
|
|
110
|
-
fn: m[regFunctionMatch.fn],
|
|
111
|
-
as: m[regFunctionMatch.fnAlias],
|
|
112
|
-
file: undefined,
|
|
113
|
-
line: undefined,
|
|
114
|
-
col: undefined,
|
|
115
|
-
abs: false,
|
|
116
|
-
};
|
|
117
|
-
} else if (regFileOnly.test(line)) {
|
|
118
|
-
const m = regFileOnly.exec(line)!;
|
|
119
|
-
return {
|
|
120
|
-
fn: undefined,
|
|
121
|
-
as: undefined,
|
|
122
|
-
file: m[regFileOnlyMatch.file],
|
|
123
|
-
line: parseInt(m[regFileOnlyMatch.row].slice(1)),
|
|
124
|
-
col: parseInt(m[regFileOnlyMatch.column].slice(1)),
|
|
125
|
-
abs: isAbsolute(m[regFileOnlyMatch.file]),
|
|
126
|
-
};
|
|
127
|
-
} else if (regSimpleFrame.test(line)) {
|
|
128
|
-
const m = regSimpleFrame.exec(line)!;
|
|
129
|
-
return {
|
|
130
|
-
fn: m[regSimpleFrameMatch.fn],
|
|
131
|
-
as: undefined,
|
|
132
|
-
file: '<anonymous>',
|
|
133
|
-
line: undefined,
|
|
134
|
-
col: undefined,
|
|
135
|
-
abs: false,
|
|
136
|
-
};
|
|
137
|
-
} else {
|
|
138
|
-
return { raw: line.replace(/^ /, '') };
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
const stackOutput = stack
|
|
142
|
-
.filter(ignoreSomeFiles)
|
|
173
|
+
export function prettyFormatStack(stackLines: readonly string[]) {
|
|
174
|
+
const structured: IStructreStackLine[] = stackLines.map(parseStackLine);
|
|
175
|
+
return structured
|
|
176
|
+
.filter(skipSomeFrame)
|
|
143
177
|
.map(translateFunction)
|
|
144
|
-
.map((
|
|
178
|
+
.map((line) => {
|
|
145
179
|
let ret;
|
|
146
|
-
if (
|
|
147
|
-
return
|
|
180
|
+
if (line.invalid) {
|
|
181
|
+
return line.toString();
|
|
148
182
|
}
|
|
183
|
+
const fn_name = line.func?.name;
|
|
149
184
|
|
|
150
|
-
if (
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
ret += formatFunctionName(fn, as);
|
|
158
|
-
}
|
|
159
|
-
ret += '\x1b[0m';
|
|
160
|
-
if (file) {
|
|
161
|
-
ret += ' (';
|
|
162
|
-
if (!isNodeModule) {
|
|
163
|
-
ret += '\x1b[38;5;2m';
|
|
185
|
+
if (!line.location?.isAbsolute || line.location.schema === 'node:') {
|
|
186
|
+
// no-path, relative path, node:
|
|
187
|
+
ret = ' at \x1B[2m';
|
|
188
|
+
if (line.func) {
|
|
189
|
+
ret += fn_name;
|
|
190
|
+
if (line.func.alias) {
|
|
191
|
+
ret += ` [${line.func.alias}]`;
|
|
164
192
|
}
|
|
165
|
-
ret += formatFileLine(fileSchema, file, line, col);
|
|
166
|
-
ret += '\x1B[0m)';
|
|
167
|
-
}
|
|
168
|
-
} else {
|
|
169
|
-
ret = '\x1B[2m at ';
|
|
170
|
-
if (fn) {
|
|
171
|
-
ret += fn;
|
|
172
193
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
194
|
+
|
|
195
|
+
if (line.location?.path === '<anonymous>') {
|
|
196
|
+
} else if (line.location?.path) {
|
|
197
|
+
if (fn_name) {
|
|
176
198
|
ret += ' (';
|
|
177
199
|
}
|
|
178
|
-
ret += formatFileLine(
|
|
179
|
-
|
|
200
|
+
ret += formatFileLine(
|
|
201
|
+
line.location.schema,
|
|
202
|
+
line.location.path,
|
|
203
|
+
line.location.line,
|
|
204
|
+
line.location.column,
|
|
205
|
+
);
|
|
206
|
+
if (fn_name) {
|
|
180
207
|
ret += ')';
|
|
181
208
|
}
|
|
182
209
|
}
|
|
183
210
|
ret += '\x1B[0m';
|
|
211
|
+
} else {
|
|
212
|
+
const path = line.location.path;
|
|
213
|
+
const isNodeModule = path.includes('/node_modules/');
|
|
214
|
+
const fn_alias = line.func?.alias;
|
|
215
|
+
|
|
216
|
+
const color = fn_name ? (isNodeModule ? '14;2' : '14') : '8';
|
|
217
|
+
ret = `\x1b[0m at \x1b[38;5;${color}m`;
|
|
218
|
+
if (fn_alias && fn_name && fn_name.startsWith('Object.')) {
|
|
219
|
+
ret += fn_alias + ' [export]';
|
|
220
|
+
} else {
|
|
221
|
+
ret += formatFunctionName(fn_name, fn_alias);
|
|
222
|
+
}
|
|
223
|
+
ret += '\x1b[0m';
|
|
224
|
+
if (line.eval) {
|
|
225
|
+
ret += `\x1b[2m(${line.eval.funcs.filter((e) => e !== '<anonymous>').join('->')})\x1b[0m`;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (path) {
|
|
229
|
+
let color;
|
|
230
|
+
if (isNodeModule) {
|
|
231
|
+
color = '\x1b[38;5;237m';
|
|
232
|
+
} else {
|
|
233
|
+
color = '\x1b[38;5;2m';
|
|
234
|
+
}
|
|
235
|
+
ret += ' (' + color;
|
|
236
|
+
const file = formatFileLine(line.location.schema, path, line.location.line, line.location.column);
|
|
237
|
+
const lastNmPos = file.lastIndexOf('/node_modules/');
|
|
238
|
+
if (lastNmPos >= 0) {
|
|
239
|
+
ret += file.slice(0, lastNmPos + 14);
|
|
240
|
+
|
|
241
|
+
let nextSlash = file.indexOf('/', lastNmPos + 15);
|
|
242
|
+
const scopePkg = file[lastNmPos + 14] === '@';
|
|
243
|
+
if (scopePkg) {
|
|
244
|
+
nextSlash = file.indexOf('/', nextSlash + 1);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
ret += '\x1B[0m';
|
|
248
|
+
ret += file.slice(lastNmPos + 14, nextSlash);
|
|
249
|
+
ret += color;
|
|
250
|
+
ret += file.slice(nextSlash);
|
|
251
|
+
} else {
|
|
252
|
+
ret += file;
|
|
253
|
+
}
|
|
254
|
+
ret += '\x1B[0m)';
|
|
255
|
+
}
|
|
184
256
|
}
|
|
185
257
|
return ret;
|
|
186
258
|
});
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
interface IError {
|
|
262
|
+
readonly code?: any;
|
|
263
|
+
readonly message?: any;
|
|
264
|
+
readonly stack?: string;
|
|
265
|
+
}
|
|
266
|
+
export function prettyFormatError(e: IError, withMessage = true) {
|
|
267
|
+
if (!e || !e.stack) {
|
|
268
|
+
if (withMessage) {
|
|
269
|
+
let msg = e?.message || 'Unknown Error';
|
|
270
|
+
|
|
271
|
+
return red(msg + '\n No stack trace');
|
|
272
|
+
} else {
|
|
273
|
+
return red(' No stack trace');
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
let stackLines = e.stack.split(/\n/g);
|
|
278
|
+
|
|
279
|
+
let first = 'Unknown Error';
|
|
280
|
+
if (/^\S/.test(stackLines[0])) {
|
|
281
|
+
first = stackLines.shift()!;
|
|
282
|
+
}
|
|
187
283
|
|
|
188
284
|
if (withMessage) {
|
|
189
|
-
if (
|
|
190
|
-
first = first.replace(/^(\S+):/, (
|
|
191
|
-
return `${name}(code ${(e as any).code}):`;
|
|
192
|
-
});
|
|
285
|
+
if (e.code) {
|
|
286
|
+
first = first.replace(/^(\S+):/, `$1(code ${e.code}):`);
|
|
193
287
|
}
|
|
194
288
|
|
|
195
|
-
return first + '\n' +
|
|
289
|
+
return first + '\n' + prettyFormatStack(stackLines).join('\n');
|
|
196
290
|
} else {
|
|
197
|
-
return
|
|
291
|
+
return prettyFormatStack(stackLines).join('\n');
|
|
198
292
|
}
|
|
199
293
|
}
|
|
200
294
|
|
|
@@ -205,10 +299,15 @@ function formatFileLine(schema: string | undefined, file: string, row?: number,
|
|
|
205
299
|
if (schema !== 'node:') {
|
|
206
300
|
try {
|
|
207
301
|
rel = relativePath(root, file);
|
|
208
|
-
if (rel.
|
|
209
|
-
rel = file;
|
|
210
|
-
} else if (!rel.startsWith('.')) {
|
|
302
|
+
if (rel[0] !== '.') {
|
|
211
303
|
rel = './' + rel;
|
|
304
|
+
} else if (rel[1] === '.') {
|
|
305
|
+
if (file.length < rel.length) {
|
|
306
|
+
rel = file;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
if (rel[0] === '.') {
|
|
310
|
+
schema = '';
|
|
212
311
|
}
|
|
213
312
|
} catch (e: any) {
|
|
214
313
|
if (!alert) {
|
|
@@ -236,36 +335,53 @@ function formatFunctionName(fn?: string, as?: string) {
|
|
|
236
335
|
return fn;
|
|
237
336
|
}
|
|
238
337
|
} else {
|
|
239
|
-
return '
|
|
338
|
+
return '<anonymous>';
|
|
240
339
|
}
|
|
241
340
|
}
|
|
242
341
|
|
|
243
|
-
function translateFunction(data:
|
|
244
|
-
if (!data.
|
|
342
|
+
function translateFunction(data: IStructreStackLine): IStructreStackLine {
|
|
343
|
+
if (!data.func?.name) {
|
|
245
344
|
return data;
|
|
246
345
|
}
|
|
247
|
-
if (data.
|
|
248
|
-
data.
|
|
346
|
+
if (data.func.name === 'Timeout._onTimeout') {
|
|
347
|
+
data.func.name = 'setTimeout';
|
|
348
|
+
}
|
|
349
|
+
if (data.func.name === 'Immediate._onImmediate') {
|
|
350
|
+
data.func.name = 'setImmediate';
|
|
249
351
|
}
|
|
250
|
-
if (data.
|
|
251
|
-
data.
|
|
252
|
-
|
|
352
|
+
if (data.func.name === 'process.processTicksAndRejections') {
|
|
353
|
+
data.func.name = 'process.nextTick';
|
|
354
|
+
}
|
|
355
|
+
if (data.func.name.startsWith('Timeout.') && data.func.alias === '_onTimeout') {
|
|
356
|
+
data.func.name = 'setTimeout->' + data.func.name.slice(8);
|
|
357
|
+
delete data.func.alias;
|
|
253
358
|
}
|
|
254
359
|
return data;
|
|
255
360
|
}
|
|
256
361
|
|
|
257
|
-
|
|
258
|
-
|
|
362
|
+
/**
|
|
363
|
+
*
|
|
364
|
+
*/
|
|
365
|
+
function skipSomeFrame({ location }: IStructreStackLine): boolean {
|
|
366
|
+
if (!location?.path) {
|
|
259
367
|
return true;
|
|
260
368
|
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
369
|
+
|
|
370
|
+
if (location.schema === 'node:') {
|
|
371
|
+
if (location.path.startsWith('internal/timers')) {
|
|
372
|
+
return false;
|
|
373
|
+
} else if (location.path === 'internal/modules/cjs/loader') {
|
|
374
|
+
return false;
|
|
375
|
+
} else if (location.path === 'internal/modules/esm/loader') {
|
|
376
|
+
return false;
|
|
377
|
+
} else if (location.path === 'internal/modules/run_main') {
|
|
378
|
+
return false;
|
|
379
|
+
} else if (location.path === 'internal/modules/esm/module_job') {
|
|
380
|
+
return false;
|
|
381
|
+
}
|
|
266
382
|
}
|
|
267
|
-
if (!
|
|
268
|
-
if (
|
|
383
|
+
if (!location.path.includes('/')) {
|
|
384
|
+
if (location.path.startsWith('_stream_')) {
|
|
269
385
|
return false;
|
|
270
386
|
}
|
|
271
387
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { tryInspect } from '../../debugging/tryInspect';
|
|
2
|
-
import { getErrorFrame } from '../../error/getFrame';
|
|
3
|
-
import { prettyFormatError } from '../../error/pretty';
|
|
1
|
+
import { tryInspect } from '../../debugging/tryInspect.js';
|
|
2
|
+
import { getErrorFrame } from '../../error/getFrame.js';
|
|
3
|
+
import { prettyFormatError } from '../../error/pretty.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Error when call dispose() twice
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { convertCatchedError } from '../../error/convertUnknown';
|
|
2
|
-
import { Emitter, EventRegister } from '../event/event';
|
|
3
|
-
import { DisposedError } from './disposedError';
|
|
4
|
-
import { IAsyncDisposable, IDisposableEvents } from './lifecycle';
|
|
1
|
+
import { convertCatchedError } from '../../error/convertUnknown.js';
|
|
2
|
+
import { Emitter, EventRegister } from '../event/event.js';
|
|
3
|
+
import { DisposedError } from './disposedError.js';
|
|
4
|
+
import { IAsyncDisposable, IDisposableEvents } from './lifecycle.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Async version of Disposable
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { globalSingletonStrong } from '../../platform/globalSingleton';
|
|
2
|
-
import { createSymbol } from '../../platform/globalSymbol';
|
|
3
|
-
import { IDisposable } from './lifecycle';
|
|
4
|
-
import { AsyncDisposable } from './lifecycle.async';
|
|
1
|
+
import { globalSingletonStrong } from '../../platform/globalSingleton.js';
|
|
2
|
+
import { createSymbol } from '../../platform/globalSymbol.js';
|
|
3
|
+
import { IDisposable } from './lifecycle.js';
|
|
4
|
+
import { AsyncDisposable } from './lifecycle.async.js';
|
|
5
5
|
|
|
6
6
|
const symbol = createSymbol('lifecycle', 'application');
|
|
7
7
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Emitter, EventRegister } from '../event/event';
|
|
2
|
-
import { DisposedError } from './disposedError';
|
|
3
|
-
import { IDisposable, IDisposableEvents } from './lifecycle';
|
|
1
|
+
import { Emitter, EventRegister } from '../event/event.js';
|
|
2
|
+
import { DisposedError } from './disposedError.js';
|
|
3
|
+
import { IDisposable, IDisposableEvents } from './lifecycle.js';
|
|
4
4
|
|
|
5
5
|
export abstract class DisposableOnce implements IDisposable {
|
|
6
6
|
private _disposed?: Error;
|