LoginSignup
132
77

More than 5 years have passed since last update.

Node.jsで捕捉されなかったPromise内の例外をスタックトレースで表示する

Last updated at Posted at 2017-01-18

現在のNode.js(9.x)においてデフォルトでは、Promise内の捕捉されなかった例外については次のように警告を出してくれますが詳細なスタックトレースは見せてくれません。

(node:5212) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 3): TypeError: Cannot read property '_id' of null
(node:5212) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

どこかしらに次のハンドラを書くことで...

process.on('unhandledRejection', console.dir);

詳細な情報が見れます:

TypeError: Cannot read property '_id' of null
    at _callee2$ (C:/Users/syuilo/Desktop/misskey/built/api/serializers/post.js:98:34)
    at tryCatch (C:\Users\syuilo\Desktop\misskey\node_modules\regenerator-runtime\runtime.js:64:40)
    at Generator.invoke [as _invoke] (C:\Users\syuilo\Desktop\misskey\node_modules\regenerator-runtime\runtime.js:355:22)
    at fulfilled (C:/Users/syuilo/Desktop/misskey/built/api/serializers/post.js:7:32)
    at process._tickCallback (internal/process/next_tick.js:103:7)

もしくは、loud-rejectionライブラリを利用するのも良い手だと思います。

132
77
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
132
77