76
Help us understand the problem. What are the problem?

More than 3 years have passed since last update.

posted at

updated at

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

現在の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ライブラリを利用するのも良い手だと思います。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Sign upLogin
76
Help us understand the problem. What are the problem?