puppet-wechat
puppet-wechat copied to clipboard
message.toFileBox() May Terminate Whole Process
Description
message.toFileBox() may throw the exception and terminate the whole process
Note that the problem does not always happen. To reproduce the problem, you may need to receive several files (or in a weak network environment).
The use of try-catch can not capture and conceal the error. The error may happen in wechaty / wechaty-puppet-puppeteer / file-box.
Environments
- Wechaty 0.40.10
- wechaty-puppet-puppeteer (default)
- Node.js v12.16.2
- Windows 10, 1909, 18363
Reproduce
robot.on('message', async (message) => {
try {
if (message.type() !== Message.Type.Text) {
const file = await message.toFileBox();
if (file) {
const base64 = await file.toBase64();
const name = file.name;
// do something
}
}
} catch (e) {
return;
}
});
Log
21:27:49 VERB Message static load(6940701186065382426)
21:27:49 SILL Accessory #9<Message> constructor()
21:27:49 VERB Message constructor(6940701186065382426) for class Message
21:27:49 VERB Message ready()
21:27:49 VERB Puppet messagePayload(6940701186065382426)
21:27:49 SILL Puppet messagePayloadCache(6940701186065382426) cache MISS
21:27:50 SILL Puppet messagePayload(6940701186065382426) cache SET
21:27:50 SILL Contact ready() @ Puppet#0<PuppetPuppeteer>(wechat-worker) with id="@8c39f94781237a1784b165aa13e54c62db258a1e15c6fb6ae48c459f398aa620"
21:27:50 SILL Contact ready() isReady() true
21:27:50 SILL Contact ready() @ Puppet#0<PuppetPuppeteer>(wechat-worker) with id="@203d5604d7b7be434c81ed4e32adc5bfce0dcff3600b2107929126792161d0a2"
21:27:50 SILL Contact ready() isReady() true
21:27:50 VERB Puppet selfId()
21:27:50 SILL Contact alias()
21:27:50 VERB Message toFileBox()
21:28:11 ERR Config ###########################
21:28:11 ERR Config uncaughtException: Error: connect ETIMEDOUT 203.205.254.252:80
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16) uncaughtException
21:28:11 ERR Config ###########################
Error: connect ETIMEDOUT 203.205.254.252:80
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
The same problem also happens in issue #61 .
same issue,two issues :
- Error connect ETIMEOUT
- PuppetWeChat uploadMedia(): upload fail https://github.com/wechaty/wechaty-puppet-wechat/blob/f9f1c71e56e461a31043a70d351f9f56ad11a334/src/puppet-wechat.ts#L1555
图片上传失败时会被迫退出 node.js 进程。
try catch 捕捉无效
That's wired if the try catch can not catch it...