nodejs / nodejs/node

Expose the "enhanced" stack trace from uncaught exceptions to the `uncaughtException` and `uncaughtExceptionMonitor` handlers on `process`

未关闭
#55,838 9 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

events feature request
主要语言
JavaScript
星标
122k
派生
37.4k
平均合并
4 天 2 小时
30 天内合并 PR
283

描述

What is the problem this feature will solve?

In my app, I have a logging system which writes entries to files and/or the network in a machine-parsable form. I use the uncaughtException handler on process in order to get uncaught exceptions written out to this logging system. I noticed that if there's no uncaughtException handler, Node will print out an extra stack trace to the console indicating the call site of the <emitter>.emit('error', ...) call which emitted the ultimately-uncaught exception. However, it seems like there's no programmatic way for me to get that extra trace in my own handler.

This feature will solve the problem of being able to programmatically extract this extra — and quite useful! — information in a way that works well with a system that eschews the console.

What is the feature you are proposing to solve the problem?

I don't know what tactic would work best within the larger Node ecosystem, but as a straw-man suggestion:

Add a third argument to the uncaughtException and uncaughtExceptionMonitor callbacks when an "enhanced" error is available, containing information corresponding to the site and target of the emit() call. It could, for example, be a plain object containing an Error representing the call site and an object reference to the emitter itself. But if that's too dangerous, it might instead have strings representing that info. For example (in the former case), the following would nearly duplicate what the current default uncaughtException handler prints out to the console:

process.on('uncaughtException', (err, origin, emitInfo) => {
  console.log('%s', err.stack);
  if (emitInfo) {
    const { emitter, emitSite } = emitInfo;
    console.log(`Emitted 'error' event of ${emitter.constructor.name} instance at:\n%s`,
      emitSite.stack);
  }
});
What alternatives have you considered?

Having a separate process to scrape console output to find things that look like uncaught exceptions, so I can push them into the structured logging system. (Oof.)

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

issue 中没有指定文件或测试。首先沿着报告中描述的增强 trace 路径,追踪 Node 现有的 process uncaughtException 和 uncaughtExceptionMonitor 处理流程。完成的标准是:在相关信息可用时,handler 能够以编程方式接收额外的 emit-site 和 target 信息,并且该行为有测试覆盖。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript, nodejs
领域
backend
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
活跃
描述清晰度
需要澄清
新手友好度
38/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。