f43cc84725d0ea7bc0a6dedf2150ad8804fed46b.svn-base
1.98 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
'use strict'
const stack = require('./stack.js')
module.exports = (er, extra, options) => {
// the yaml module puts big stuff here, pluck it off
if (er.source && typeof er.source === 'object' && er.source.context)
er.source = { ...er.source, context: null }
extra = Object.keys(options || {}).reduce((set, k) => {
if (!(k in set) && !/^tapChild/.test(k))
set[k] = options[k]
return set
}, extra || {})
if (!er || typeof er !== 'object') {
extra.error = er
return extra
}
const message = er.message ? er.message
: er.stack ? er.stack.split('\n')[0]
: ''
const addName = er.message || !er.stack
if (er.message) {
try {
Object.defineProperty(er, 'message', {
value: '',
configurable: true
})
} catch (e) {}
}
const st = er.stack && er.stack.substr(
er._babel ? (message + er.codeFrame).length : 0)
if (st) {
const splitst = st.split('\n')
if (er._babel && er.loc) {
const msplit = message.split(': ')
const f = msplit[0].trim()
extra.message = msplit.slice(1).join(': ')
.replace(/ \([0-9]+:[0-9]+\)$/, '').trim()
const file = f.indexOf(process.cwd()) === 0
? f.substr(process.cwd().length + 1) : f
if (file !== 'unknown')
delete er.codeFrame
extra.at = {
file,
line: er.loc.line,
column: er.loc.column + 1,
}
} else {
// parse out the 'at' bit from the first line.
extra.at = stack.parseLine(splitst[1])
}
extra.stack = stack.clean(splitst)
}
if (message) {
try {
Object.defineProperty(er, 'message', {
value: message,
configurable: true
})
} catch (e) {}
}
if (er.name && er.name !== 'Error')
extra.type = er.name
Object.keys(er).forEach(k => {
if (k === 'message' ||
k === 'domainEmitter' ||
k === 'domainThrown' ||
k === 'domain' ||
k === 'domainBound')
return
extra[k] = er[k]
})
return extra
}