-
Notifications
You must be signed in to change notification settings - Fork 16
/
stack-utils.node.txt
63 lines (46 loc) · 3.97 KB
/
stack-utils.node.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
STACK-UTILS
ALTERNATIVES (PARSING) ==> #See stacktrace.js
ALTERNATIVES (BEAUTIFYING) ==> #See pretty-error
VERSION ==> #2.0.6
#Node and Chrome only (V8-specific)
/=+===============================+=\
/ : : \
)==: PARSING :==(
\ :_______________________________: /
\=+===============================+=/
new STACK-UTILS([OPTS]) #
STACK-UTILS #Singleton with default OPTS
SCALL #Normalized CALL
SCALL.file #'PATH': strip OPTS.cwd (def: process.cwd())
SCALL.function #'[CLASS.]FUNC'
SCALL.method #'FUNC' (only if different from function)
SCALL.type #'TYPE'
SCALL.line|column #NUM
SCALL.constructor|native #BOOL
SCALL.evalOrigin #'FILENAME'
SCALL.evalFile|Line|Column #
UTILS.capture([NUM, ][FUNC]) #Retrieves current stack trace as CALL_ARR (see Node doc)
->CALL_ARR #Do it by using Error.prepareStackTrace() (only temporarily overriden)
#If NUM, temporarily sets Error.stackTraceLimit
#Can specify a mapping function OPTS.wrapCallSite(CALL)->CALL
UTILS.at([FUNC])->SCALL #Retrieve last CALL normalized as SCALL
UTILS.captureString([NUM, ][FUNC])#Similar to capture() but return stack trace STR
->STR #Also apply UTILS.clean()
UTILS.parseLine(STR)->SCALL|null #Parse single stack trace line into SCALL
#Do it by using REGEXPs
/=+===============================+=\
/ : : \
)==: CLEANING :==(
\ :_______________________________: /
\=+===============================+=/
UTILS.clean(STR[, NUM])->STR #STR is ERROR.stack
#Normalize it by:
# - removing lines matching any OPTS.internals REGEXP_ARR
# - def: STACK-UTILS.nodeInternals(), i.e. Node core internals
# - can add package names with OPTS.ignoredPackages 'PACKAGE'_ARR
# - stripping OPTS.cwd (def: process.cwd())
# - triming whitespaces
# - normalizing Windows \ delimiters to /
#NUM is indent (def: 0)