NodeJS错误堆栈未定义 [英] NodeJS Error Stack Undefined

查看:149
本文介绍了NodeJS错误堆栈未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用节点检查器,我注意到 new Error()有未定义的堆栈。

I am using node inspector and I noticed new Error() had undefined stacks.

如果我已分配这个值变量,该变量将显示堆栈未定义。

If I assigned this value to a variable, that variable would show that the stack is undefined.

有趣的是,运行 new Error()。stack 生成一个包含正确堆栈的消息。

Interestingly enough, running new Error().stack produces a message with the proper stack.

理想情况下,这些错误默认会有堆栈,所以当我记录时我可以知道在哪里看。

Ideally these errors would have stacks by default so when I log I can know where to look.

我不明白为什么会发生这种情况,无法找到相关信息。我在这里缺少什么?

I do not understand why this is happening and cannot find information on it. Is there something I'm missing here?

推荐答案

因为 当访问error.stack属性时,表示堆栈跟踪的字符串 lazily

一个小例子:

function newError() {

  var error = new Error('ohhh')

  // See the contents of a _stack variable using the Inspector
  var _stack = '' + error.stack

}

newError()

这篇关于NodeJS错误堆栈未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆