Skip to content

Commit bed4d47

Browse files
committed
Fix error.name
1 parent cd17527 commit bed4d47

File tree

3 files changed

+28
-22
lines changed

3 files changed

+28
-22
lines changed

src/error/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,14 @@ const getError = function({ name, event }) {
1919

2020
const buildError = function({ name, message, stack }) {
2121
const error = new Error(message)
22-
// eslint-disable-next-line fp/no-mutation
23-
error.name = capitalize(name)
22+
// `error.name` should not be enumerable, to ensure it is correctly printed.
23+
// eslint-disable-next-line fp/no-mutating-methods
24+
Object.defineProperty(error, 'name', {
25+
value: capitalize(name),
26+
enumerable: false,
27+
writable: true,
28+
configurable: true,
29+
})
2430
// We removed the first line of `stack`, now we substitute it
2531
// eslint-disable-next-line fp/no-mutation
2632
error.stack = `${error}\n${stack}`

test/options/snapshots/testing.js.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ Generated by [AVA](https://ava.li).
973973
code: 1,
974974
stderr: `RejectionHandled: a promise was rejected and handled too late: Error: message␊
975975
at STACK TRACE␊
976-
{ name: 'RejectionHandled',␊
976+
{ name: 'TAP',␊
977977
type: 'RejectionHandled',␊
978978
tapCaught: 'uncaughtException',␊
979979
test: 'TAP' }`,
@@ -997,7 +997,7 @@ Generated by [AVA](https://ava.li).
997997
code: 1,
998998
stderr: `RejectionHandled: a promise was rejected and handled too late: Error: message␊
999999
at STACK TRACE␊
1000-
{ name: 'RejectionHandled',␊
1000+
{ name: 'TAP',␊
10011001
type: 'RejectionHandled',␊
10021002
tapCaught: 'uncaughtException',␊
10031003
test: 'TAP' }`,
@@ -1348,7 +1348,7 @@ Generated by [AVA](https://ava.li).
13481348
code: 1,
13491349
stderr: `RejectionHandled: a promise was rejected and handled too late: Error: message␊
13501350
at STACK TRACE␊
1351-
{ name: 'RejectionHandled',␊
1351+
{ name: 'TAP',␊
13521352
type: 'RejectionHandled',␊
13531353
tapCaught: 'uncaughtException',␊
13541354
test: 'TAP' }`,
@@ -1395,7 +1395,7 @@ Generated by [AVA](https://ava.li).
13951395
code: 1,
13961396
stderr: `RejectionHandled: a promise was rejected and handled too late: Error: message␊
13971397
at STACK TRACE␊
1398-
{ name: 'RejectionHandled',␊
1398+
{ name: 'TAP',␊
13991399
type: 'RejectionHandled',␊
14001400
tapCaught: 'uncaughtException',␊
14011401
test: 'TAP' }`,
@@ -1843,9 +1843,9 @@ Generated by [AVA](https://ava.li).
18431843
expected: |-␊
18441844
undefined␊
18451845
actual: |-␊
1846-
{ [MultipleResolves: a promise was multiple times:␊
1846+
[MultipleResolves: a promise was multiple times:␊
18471847
Initially resolved with: { success: true }␊
1848-
Then rejected with: Error: message] name: 'MultipleResolves' }
1848+
Then rejected with: Error: message]␊
18491849
stack: |-␊
18501850
MultipleResolves: a promise was multiple times:␊
18511851
Initially resolved with: { success: true }␊
@@ -1878,9 +1878,9 @@ Generated by [AVA](https://ava.li).
18781878
expected: |-␊
18791879
undefined␊
18801880
actual: |-␊
1881-
{ [MultipleResolves: a promise was multiple times:␊
1881+
[MultipleResolves: a promise was multiple times:␊
18821882
Initially resolved with: { success: true }␊
1883-
Then rejected with: Error: message] name: 'MultipleResolves' }
1883+
Then rejected with: Error: message]␊
18841884
stack: |-␊
18851885
MultipleResolves: a promise was multiple times:␊
18861886
Initially resolved with: { success: true }␊
@@ -1929,7 +1929,7 @@ Generated by [AVA](https://ava.li).
19291929
expected: |-␊
19301930
undefined␊
19311931
actual: |-␊
1932-
{ [UnhandledRejection: a promise was rejected but not handled: Error: message] name: 'UnhandledRejection' }
1932+
[UnhandledRejection: a promise was rejected but not handled: Error: message]␊
19331933
stack: |-␊
19341934
UnhandledRejection: a promise was rejected but not handled: Error: message␊
19351935
at STACK TRACE␊
@@ -1941,7 +1941,7 @@ Generated by [AVA](https://ava.li).
19411941
expected: |-␊
19421942
undefined␊
19431943
actual: |-␊
1944-
{ [RejectionHandled: a promise was rejected and handled too late: Error: message] name: 'RejectionHandled' }
1944+
[RejectionHandled: a promise was rejected and handled too late: Error: message]␊
19451945
stack: |-␊
19461946
RejectionHandled: a promise was rejected and handled too late: Error: message␊
19471947
at STACK TRACE␊
@@ -1970,7 +1970,7 @@ Generated by [AVA](https://ava.li).
19701970
expected: |-␊
19711971
undefined␊
19721972
actual: |-␊
1973-
{ [UnhandledRejection: a promise was rejected but not handled: Error: message] name: 'UnhandledRejection' }
1973+
[UnhandledRejection: a promise was rejected but not handled: Error: message]␊
19741974
stack: |-␊
19751975
UnhandledRejection: a promise was rejected but not handled: Error: message␊
19761976
at STACK TRACE␊
@@ -1982,7 +1982,7 @@ Generated by [AVA](https://ava.li).
19821982
expected: |-␊
19831983
undefined␊
19841984
actual: |-␊
1985-
{ [RejectionHandled: a promise was rejected and handled too late: Error: message] name: 'RejectionHandled' }
1985+
[RejectionHandled: a promise was rejected and handled too late: Error: message]␊
19861986
stack: |-␊
19871987
RejectionHandled: a promise was rejected and handled too late: Error: message␊
19881988
at STACK TRACE␊
@@ -2029,7 +2029,7 @@ Generated by [AVA](https://ava.li).
20292029
expected: |-␊
20302030
undefined␊
20312031
actual: |-␊
2032-
{ [UncaughtException: an exception was thrown but not caught: Error: message] name: 'UncaughtException' }
2032+
[UncaughtException: an exception was thrown but not caught: Error: message]␊
20332033
stack: |-␊
20342034
UncaughtException: an exception was thrown but not caught: Error: message␊
20352035
at STACK TRACE␊
@@ -2058,7 +2058,7 @@ Generated by [AVA](https://ava.li).
20582058
expected: |-␊
20592059
undefined␊
20602060
actual: |-␊
2061-
{ [UncaughtException: an exception was thrown but not caught: Error: message] name: 'UncaughtException' }
2061+
[UncaughtException: an exception was thrown but not caught: Error: message]␊
20622062
stack: |-␊
20632063
UncaughtException: an exception was thrown but not caught: Error: message␊
20642064
at STACK TRACE␊
@@ -2105,7 +2105,7 @@ Generated by [AVA](https://ava.li).
21052105
expected: |-␊
21062106
undefined␊
21072107
actual: |-␊
2108-
{ [UnhandledRejection: a promise was rejected but not handled: Error: message] name: 'UnhandledRejection' }
2108+
[UnhandledRejection: a promise was rejected but not handled: Error: message]␊
21092109
stack: |-␊
21102110
UnhandledRejection: a promise was rejected but not handled: Error: message␊
21112111
at STACK TRACE␊
@@ -2134,7 +2134,7 @@ Generated by [AVA](https://ava.li).
21342134
expected: |-␊
21352135
undefined␊
21362136
actual: |-␊
2137-
{ [UnhandledRejection: a promise was rejected but not handled: Error: message] name: 'UnhandledRejection' }
2137+
[UnhandledRejection: a promise was rejected but not handled: Error: message]␊
21382138
stack: |-␊
21392139
UnhandledRejection: a promise was rejected but not handled: Error: message␊
21402140
at STACK TRACE␊
@@ -2182,8 +2182,8 @@ Generated by [AVA](https://ava.li).
21822182
expected: |-␊
21832183
undefined␊
21842184
actual: |-␊
2185-
{ [Warning: WarningType: message␊
2186-
[500] Detail] name: 'Warning' }
2185+
[Warning: WarningType: message␊
2186+
[500] Detail]␊
21872187
stack: |-␊
21882188
Warning: WarningType: message␊
21892189
[500] Detail␊
@@ -2214,8 +2214,8 @@ Generated by [AVA](https://ava.li).
22142214
expected: |-␊
22152215
undefined␊
22162216
actual: |-␊
2217-
{ [Warning: WarningType: message␊
2218-
[500] Detail] name: 'Warning' }
2217+
[Warning: WarningType: message␊
2218+
[500] Detail]␊
22192219
stack: |-␊
22202220
Warning: WarningType: message␊
22212221
[500] Detail␊
-31 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)