【问题标题】:How can I enable my errors to show the line and file the error is in如何启用我的错误以显示错误所在的行和文件
【发布时间】:2018-11-23 21:52:13
【问题描述】:

如何使用文件名和行记录错误?

使用节点 11.2.0

(node:208) UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot send messages to this user
  at item.request.gen.end (/rbd/pnpm-volume/09ff3c4a-1318-4254-9aec-024d6a83c316/node_modules/.registry.npmjs.org/discord.js/11.4.2/node_modules/discord.js/src/client/rest/RequestHandlers/Sequential.js:79:15)
  at then (/rbd/pnpm-volume/09ff3c4a-1318-4254-9aec-024d6a83c316/node_modules/.registry.npmjs.org/snekfetch/3.6.4/node_modules/snekfetch/src/index.js:215:21
  at process.internalTickCallback (internal/process/next_tick.js:77:7)

(node:208) UnhandledPromiseRejectionWarning: Unhandled promise 
rejection. This error originated either by throwing inside of an async 
function without a catch block, or by rejecting a promise which was not 
handled with .catch(). (rejection id: 478)

【问题讨论】:

  • internal/process/next_tick.js:77:7 你在这个文件的第 77 行查看了吗? 7是线上的位置
  • 我从未访问过该文件,而且我很确定我以前从未见过它。

标签: javascript node.js discord.js


【解决方案1】:

如果您尝试使用下面显示错误发生位置的部分记录错误,只需使用console.trace(err)

【讨论】:

    【解决方案2】:

    例子:

    if (message.content === 'hi') {
      message.channel.send(text)
        .catch(function(err) {
          if (err) {
            console.log(`error:`, err);
          }
        });
    }
    

    结果:

    (node:9683) UnhandledPromiseRejectionWarning: ReferenceError: text is not defined
    

    【讨论】:

    • 是的,我知道,我需要知道错误在哪里,因为我有一个非常大的项目
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-27
    • 1970-01-01
    相关资源
    最近更新 更多