pengrad / java-telegram-bot-api

Telegram Bot API for Java
https://core.telegram.org/bots
Apache License 2.0
1.79k stars 372 forks source link

Exceptions cause update loop #161

Closed itsTyrion closed 5 years ago

itsTyrion commented 5 years ago

Code that throws an exception in the update listener, in my case msg.newChatMembers().length without checking makes the api jump into the onFailure block without throwing an exception or printing a stack trace, leading to an infinite update loop.

How to reproduce? update.message().newChatMembers().length without a null check on newChatMembers() and send a text or voice message

pengrad commented 5 years ago

Ideas how it can be properly handled? Additional ErrorListener as a 2nd lambda param? Still not sure how to skip or mark this update as processed.

itsTyrion commented 5 years ago

maybe. or print the stacktrace. or make the 2nd parameter optional and just print it by default^^

pengrad commented 5 years ago

New behavior:

  1. Exception in UpdateListener will fail and stop update handler
  2. Network failure or exception in library will be logged and updates continue
  3. Bad response from API will be logged and updates continue

Will release with next major version, but you can always try master snapshot with jitpack https://jitpack.io/#pengrad/java-telegram-bot-api/master-SNAPSHOT