繁体   English   中英

如何启用错误以显示错误所在的行和文件

[英]How can I enable my errors to show the line and file the error is in

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

使用节点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)

例:

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

如果您尝试使用下面显示错误发生位置的代码记录错误,请使用console.trace(err)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM