通过 child_process 运行的代码, 错误信息不够具体
我用 node-dev 调试脚本, 用的是没有 source map 的语言, 错误信息:
TypeError: Cannot read property 'get' of undefined
at /Users/chen/repo/Cumulo/immutable-chat/src/backend/differ.cirru:26:17
at /Users/chen/repo/Cumulo/immutable-chat/node_modules/immutable/dist/immutable.js:1915:16
at ArrayMapNode.iterate.HashCollisionNode.iterate [as iterate] (/Users/chen/repo/Cumulo/immutable-chat/node_modules/immutable/dist/immutable.js:2264:11)
at src_Map__Map.__iterate (/Users/chen/repo/Cumulo/immutable-chat/node_modules/immutable/dist/immutable.js:1913:32)
at src_Map__Map.mixin.forEach (/Users/chen/repo/Cumulo/immutable-chat/node_modules/immutable/dist/immutable.js:4327:19)
at /Users/chen/repo/Cumulo/immutable-chat/src/backend/differ.cirru:23:15
at /Users/chen/repo/Cumulo/immutable-chat/src/util/pipeline.cirru:14:5
at Array.forEach (native)
at Object.Pipeline.send (/Users/chen/repo/Cumulo/immutable-chat/src/util/pipeline.cirru:13:22)
at /Users/chen/repo/Cumulo/immutable-chat/src/util/pipeline.cirru:24:14
可是如果是直接用进程跑, 错误是很具体的:
/Users/chen/repo/Cumulo/immutable-chat/src/backend/differ.cirru:26
if (theCache.get("db") !== db || theCache.get("state") !== state) {
^
TypeError: Cannot read property 'get' of undefined
at /Users/chen/repo/Cumulo/immutable-chat/src/backend/differ.cirru:26:17
at /Users/chen/repo/Cumulo/immutable-chat/node_modules/immutable/dist/immutable.js:1915:16
at ArrayMapNode.iterate.HashCollisionNode.iterate [as iterate] (/Users/chen/repo/Cumulo/immutable-chat/node_modules/immutable/dist/immutable.js:2264:11)
at src_Map__Map.__iterate (/Users/chen/repo/Cumulo/immutable-chat/node_modules/immutable/dist/immutable.js:1913:32)
at src_Map__Map.mixin.forEach (/Users/chen/repo/Cumulo/immutable-chat/node_modules/immutable/dist/immutable.js:4327:19)
at /Users/chen/repo/Cumulo/immutable-chat/src/backend/differ.cirru:23:15
at /Users/chen/repo/Cumulo/immutable-chat/src/util/pipeline.cirru:14:5
at Array.forEach (native)
at Object.Pipeline.send (/Users/chen/repo/Cumulo/immutable-chat/src/util/pipeline.cirru:13:22)
at /Users/chen/repo/Cumulo/immutable-chat/src/util/pipeline.cirru:24:14
at /Users/chen/repo/Cumulo/immutable-chat/src/util/pipeline.cirru:14:5
at Array.forEach (native)
at Object.Pipeline.send (/Users/chen/repo/Cumulo/immutable-chat/src/util/pipeline.cirru:13:22)
at /Users/chen/repo/Cumulo/immutable-chat/src/util/pipeline.cirru:40:14
at /Users/chen/repo/Cumulo/immutable-chat/src/util/pipeline.cirru:14:5
at Array.forEach (native)
at Object.Pipeline.send (/Users/chen/repo/Cumulo/immutable-chat/src/util/pipeline.cirru:13:22)
翻了一下代码, 发现代码里边的 stack 信息就是很少的…
// Error handler that displays a notification and logs the stack to stderr:
process.on('uncaughtException', function(err) {
console.error(err.stack || err)
ipc.send({ error: err.name || 'Error' , message: err.message })
})
有没有办法, 即便用 node-dev 也能打印更多的错误信息啊? …除了让我加 sourcemap…
1 回复