gringobot
gringobot copied to clipboard
Handle events that have no reply methods
Describe the bug
In some situations, such as an user being kicked, the Telegraf might not offer a reply command. Currently we check for the method, but that is not enough to avoid an unhandled error.
2021-06-26T12:50:53.562951998Z Unhandled error while processing {
2021-06-26T12:50:53.563009733Z update_id: 123123123,
2021-06-26T12:50:53.563018894Z my_chat_member: {
2021-06-26T12:50:53.563024756Z chat: {
2021-06-26T12:50:53.563030413Z id: 123123123,
2021-06-26T12:50:53.563036079Z first_name: 'xxx',
2021-06-26T12:50:53.563041836Z username: 'xxx',
2021-06-26T12:50:53.563047756Z type: 'private'
2021-06-26T12:50:53.563053455Z },
2021-06-26T12:50:53.563058913Z from: {
2021-06-26T12:50:53.563093910Z id: 123123123,
2021-06-26T12:50:53.563103325Z is_bot: false,
2021-06-26T12:50:53.563109439Z first_name: 'xxx',
2021-06-26T12:50:53.563115336Z username: 'xxx',
2021-06-26T12:50:53.563127054Z },
2021-06-26T12:50:53.563132867Z date: 1624711853,
2021-06-26T12:50:53.563138397Z old_chat_member: { user: [Object], status: 'member' },
2021-06-26T12:50:53.563143952Z new_chat_member: { user: [Object], status: 'kicked', until_date: 0 }
2021-06-26T12:50:53.563149705Z }
2021-06-26T12:50:53.563155505Z }
2021-06-26T12:50:53.671017986Z (node:1) UnhandledPromiseRejectionWarning: TypeError: Telegraf: "reply" isn't available for "undefined"
2021-06-26T12:50:53.671091073Z at Context.assert (/app/node_modules/telegraf/lib/context.js:110:19)
2021-06-26T12:50:53.671103377Z at Context.reply (/app/node_modules/telegraf/lib/context.js:166:14)
2021-06-26T12:50:53.671108968Z at /app/build/middlewares/createContextMiddleware.js:20:24
2021-06-26T12:50:53.671115031Z at Generator.next (<anonymous>)
2021-06-26T12:50:53.671121529Z at /app/node_modules/tslib/tslib.js:117:75
2021-06-26T12:50:53.671127704Z at new Promise (<anonymous>)
2021-06-26T12:50:53.671162993Z at Object.__awaiter (/app/node_modules/tslib/tslib.js:113:16)
2021-06-26T12:50:53.671168452Z at middleware (/app/build/middlewares/createContextMiddleware.js:12:47)
2021-06-26T12:50:53.671173216Z at execute (/app/node_modules/telegraf/lib/composer.js:457:23)
2021-06-26T12:50:53.671178188Z at /app/node_modules/telegraf/lib/composer.js:458:27
2021-06-26T12:50:53.671747182Z (node:1) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
2021-06-26T12:50:53.671787878Z (node:1) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
This then gets the server in an unhealthy state and it becomes unable to reply to any other messages afterwards.
To Reproduce Steps to reproduce the behavior:
- Trigger a kick member event
- See error
Expected behavior It should ignore the kick member event or other non-reply events and keep the process healthy.
in theory this got fixed in the last commit, where instead of checking if the reply is available at all, I just console.log it and cancel the event flow in case I can't.
I'm going to keep monitoring to see if this issue is going to happen again