简体   繁体   English

使用pm2重新启动/重新加载时如何捕获错误

[英]How to catch errors when using pm2 restart / reload

For tests purposes, even though I voluntarily inject javascript syntax errors in my nodejs project, pm2 still manage to start the app I have created. 出于测试目的,即使我在自己的nodejs项目中自愿注入了javascript语法错误,pm2仍然可以启动我创建的应用程序。

Syntax errors are properly logged, I can see them, but the command pm2 list still returns the app with a status set to "online" 语法错误已正确记录,我可以看到它们,但是命令pm2 list仍然返回状态设置为“在线”的应用程序

Does it make sense that pm2 can start an app even though there are syntax errors in it? 即使其中有语法错误,pm2仍可以启动应用程序是否有意义?

What are the cases when pm2 returns an app status as "errored" when using pm2 list ? 在使用pm2 list时pm2返回应用程序状态为“错误”的情况是什么?

If you catch the error it will be logged by PM2, but the service itself won't stop / restart. 如果发现错误,它将由PM2记录,但服务本身不会停止/重新启动。

These uncaughtExceptions are not Syntax Errors, but are errors which are only detected at runtime, for example accessing a method on an object which is not present, or trying to access a variable which has not been declared. 这些uncaughtExceptions不是语法错误,而是仅在运行时检测到的错误,例如,访问不存在的对象上的方法,或尝试访问未声明的变量。

 process.on('uncaughtException', (err) => { console.log('uncaughtException'); console.log(err); }); 

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

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