Skip to content

Commit 6e13766

Browse files
committed
Do not print warnings about unhandled rejection
1 parent 548b760 commit 6e13766

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/handle/common.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { isLimited } from '../limit.js'
22
import { isRepeated } from '../repeat.js'
3+
import { isRejectionWarning } from '../warnings.js'
34
import { getLevel } from '../level.js'
45
import { getError, addErrorPrint } from '../error/main.js'
56
import { exitProcess } from '../exit.js'
@@ -33,6 +34,10 @@ export const handleEvent = async function({
3334
return
3435
}
3536

37+
if (isRejectionWarning(name, event)) {
38+
return
39+
}
40+
3641
await logEvent({ opts, name, event })
3742

3843
await exitProcess({ name, opts })

src/warnings.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,14 @@ const getWarningListeners = function() {
4646
}
4747

4848
const warningListener = getWarningListener()
49+
50+
// Unhandled rejected promises emit a warning by default (unless
51+
// --unhandled-rejections is used). This warning is not useful, so we remove it.
52+
export const isRejectionWarning = function(name, { value }) {
53+
return (
54+
name === 'warning' &&
55+
value instanceof Error &&
56+
value.name === 'DeprecationWarning' &&
57+
value.code === 'DEP0018'
58+
)
59+
}

0 commit comments

Comments
 (0)