Skip to content

Commit 1e8cc74

Browse files
committed
Rename info.error to info.value
1 parent d8a32f8 commit 1e8cc74

File tree

8 files changed

+28
-41
lines changed

8 files changed

+28
-41
lines changed

src/events.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
const { handleEvent } = require('./handle')
44

55
// List of all handled events
6-
// Each event must pass its related `error` or `promise` to the generic
7-
// `handleEvent()`
8-
const uncaughtException = function(context, error) {
9-
handleEvent({ ...context, error })
6+
// Each event must pass its related `value` to the generic `handleEvent()`
7+
const uncaughtException = function(context, value) {
8+
handleEvent({ ...context, value })
109
}
1110

12-
const warning = function(context, error) {
13-
handleEvent({ ...context, error })
11+
const warning = function(context, value) {
12+
handleEvent({ ...context, value })
1413
}
1514

1615
const unhandledRejection = function(context, value, promise) {

src/handle.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,17 @@ const handleEvent = async function({
1414
eventName,
1515
previousEvents,
1616
mEmitLimitedWarning,
17-
error,
1817
promise,
1918
value,
2019
nextRejected,
2120
nextValue,
2221
}) {
23-
if (isLimited({ previousEvents, mEmitLimitedWarning, eventName, error })) {
22+
if (isLimited({ previousEvents, mEmitLimitedWarning, eventName, value })) {
2423
return
2524
}
2625

2726
const info = await getInfo({
2827
eventName,
29-
error,
3028
promise,
3129
value,
3230
nextRejected,

src/info.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
const { pickBy } = require('./utils')
44

5-
// Retrieve `info` object representing the current error information
5+
// Retrieve `info` object representing the current event information
66
const getInfo = async function({
77
eventName,
8-
error,
98
promise,
109
value,
1110
nextRejected,
@@ -17,24 +16,17 @@ const getInfo = async function({
1716
value,
1817
})
1918

20-
const info = {
21-
eventName,
22-
error,
23-
rejected,
24-
value: valueA,
25-
nextRejected,
26-
nextValue,
27-
}
19+
const info = { eventName, rejected, value: valueA, nextRejected, nextValue }
2820

29-
const infoA = pickBy(info, value => value !== undefined)
21+
const infoA = pickBy(info, infoVal => infoVal !== undefined)
3022
return infoA
3123
}
3224

3325
// Retrieve promise's resolved/rejected state and value.
3426
const parsePromise = async function({ eventName, promise, value }) {
35-
// `uncaughtException` and `warning` events do not have `promise`.
27+
// `uncaughtException` and `warning` events do not have `rejected`.
3628
if (promise === undefined) {
37-
return {}
29+
return { value }
3830
}
3931

4032
// `unhandledRejection` should not use the following code because:

src/limit.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ const isLimited = function({
1919
previousEvents,
2020
mEmitLimitedWarning,
2121
eventName,
22-
error,
22+
value,
2323
}) {
24-
if (isLimitedWarning({ eventName, error })) {
24+
if (isLimitedWarning({ eventName, value })) {
2525
return false
2626
}
2727

@@ -46,7 +46,7 @@ const emitLimitedWarning = function(eventName) {
4646
}
4747

4848
// The `warning` itself should not be skipped
49-
const isLimitedWarning = function({ eventName, error: { name, code } = {} }) {
49+
const isLimitedWarning = function({ eventName, value: { name, code } = {} }) {
5050
return eventName === 'warning' && name === ERROR_NAME && code === ERROR_CODE
5151
}
5252

src/message.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ const defaultMessage = function({
1919
value,
2020
nextRejected,
2121
nextValue,
22-
error,
2322
level,
2423
colors,
2524
}) {
@@ -28,23 +27,22 @@ const defaultMessage = function({
2827
value,
2928
nextRejected,
3029
nextValue,
31-
error,
3230
})
3331

3432
const messageA = prettify({ message, eventName, level, colors })
3533
return messageA
3634
}
3735

38-
const uncaughtException = function({ error }) {
36+
const uncaughtException = function({ value }) {
3937
return ` (an exception was thrown but not caught)
40-
${serialize(error)}`
38+
${serialize(value)}`
4139
}
4240

43-
const warning = function({ error, error: { code, detail } }) {
41+
const warning = function({ value, value: { code, detail } }) {
4442
const codeMessage = code === undefined ? '' : `(${code}) `
4543
const detailMessage = detail === undefined ? '' : `${detail}\n`
4644
return `
47-
${codeMessage}${detailMessage}${serialize(error)}`
45+
${codeMessage}${detailMessage}${serialize(value)}`
4846
}
4947

5048
const unhandledRejection = function({ value }) {
@@ -57,8 +55,8 @@ const rejectionHandled = function({ value }) {
5755
${serialize(value)}`
5856
}
5957

60-
// The default level is `info` because it does not always indicate an
61-
// error: https://github.com/nodejs/node/issues/24321
58+
// The default level is `info` because it does not always indicate an error:
59+
// https://github.com/nodejs/node/issues/24321
6260
const multipleResolves = function({
6361
rejected,
6462
value,

src/repeat.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const getFingerprint = function({ info }) {
3939
// We do not serialize `info.eventName` since this is already `eventName-wise`
4040
// Key order matters since fingerprint might be truncated: we serialize short
4141
// and non-dynamic values first.
42-
const INFO_PROPS = ['nextRejected', 'rejected', 'error', 'nextValue', 'value']
42+
const INFO_PROPS = ['nextRejected', 'rejected', 'nextValue', 'value']
4343

4444
const FINGERPRINT_MAX_LENGTH = 1e4
4545

@@ -56,7 +56,7 @@ const serializeEntry = function({ info, propName }) {
5656

5757
const serializeValue = function({ value }) {
5858
if (value instanceof Error) {
59-
return serializeError({ error: value })
59+
return serializeError(value)
6060
}
6161

6262
return stableSerialize(value)
@@ -66,7 +66,7 @@ const serializeValue = function({ value }) {
6666
// timestamps. This means errors are only `error.name` + `error.stack`, which
6767
// should be a good fingerprint.
6868
// Also we only keep first 10 callsites in case of infinitely recursive stack.
69-
const serializeError = function({ error: { name, stack } }) {
69+
const serializeError = function({ name, stack }) {
7070
const stackA = filterErrorStack({ stack })
7171
return `${name}\n${stackA}`
7272
}

test/info.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const INFOS = [
88
{
99
name: 'uncaughtException',
1010
arg: () => true,
11-
expected: { error: true },
11+
expected: { value: true },
1212
},
1313
{
1414
name: 'warning',
@@ -18,12 +18,12 @@ const INFOS = [
1818
code: '500',
1919
detail: 'Detail',
2020
},
21-
getInfo: ({ error, error: { message } = {}, ...info }) => ({
21+
getInfo: ({ value, value: { message } = {}, ...info }) => ({
2222
...info,
23-
error: { ...error, message },
23+
value: { ...value, message },
2424
}),
2525
expected: {
26-
error: {
26+
value: {
2727
message: 'message',
2828
name: 'WarningType',
2929
code: '500',

test/limit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,6 @@ const onlyNotLimitedWarning = function(eventName, info) {
9696
}
9797
}
9898

99-
const isLimitedWarning = function({ eventName, error: { name } = {} }) {
99+
const isLimitedWarning = function({ eventName, value: { name } = {} }) {
100100
return eventName === 'warning' && name === 'LogProcessErrors'
101101
}

0 commit comments

Comments
 (0)