Skip to content

[BUG] Promise ignores exceptions #3201

@elebur

Description

@elebur

Steps to Reproduce

This bug has already been catched and fixed - #2542
But it still exists.

Here is the code. Run it and send /bug command to the bot and you will see nothing in console, but I expect traceback to appear.

#!/usr/bin/env python3
# encoding=utf-8

'''
MessageQueue usage example with @queuedmessage decorator.
Provide your bot token with `TOKEN` environment variable or list it in
file `token.txt`
'''

import telegram.bot
from telegram.ext import messagequeue as mq


class MQBot(telegram.bot.Bot):
    '''A subclass of Bot which delegates send method handling to MQ'''
    def __init__(self, *args, is_queued_def=True, mqueue=None, **kwargs):
        super(MQBot, self).__init__(*args, **kwargs)
        # below 2 attributes should be provided for decorator usage
        self._is_messages_queued_default = is_queued_def
        self._msg_queue = mqueue or mq.MessageQueue()

    def __del__(self):
        try:
            self._msg_queue.stop()
        except:
            pass

    @mq.queuedmessage
    def send_message(self, *args, **kwargs):
        '''Wrapped method would accept new `queued` and `isgroup`
        OPTIONAL arguments'''
        return super(MQBot, self).send_message(*args, **kwargs)


if __name__ == '__main__':
    from telegram import ParseMode
    from telegram.ext import MessageHandler, Filters, CommandHandler
    from telegram.utils.request import Request
    import os
    token = os.environ.get('TOKEN') or open('token.txt').read().strip()
    # for test purposes limit global throughput to 3 messages per 3 seconds
    q = mq.MessageQueue(all_burst_limit=3, all_time_limit_ms=3000)
    # set connection pool size for bot 
    request = Request(con_pool_size=8)
    testbot = MQBot(token, request=request, mqueue=q)
    upd = telegram.ext.updater.Updater(bot=testbot, use_context=True)


    def show_bug(update, context):
        """
        The dot in "Hello, World." should raise an exception
        because it is unescaped.
        """
        context.bot.send_message(
            chat_id=update.effective_chat.id,
            text="Hello, World.",
            parse_mode=ParseMode.MARKDOWN_V2
        )

    def start(update, context):
        context.bot.send_message(
            chat_id=update.effective_chat.id,
            text=r"Hello, World\.",
            parse_mode=ParseMode.MARKDOWN_V2
        )

    upd.dispatcher.add_handler(CommandHandler("start", start))

    upd.dispatcher.add_handler(CommandHandler("bug", show_bug))
    upd.start_polling()

Expected behaviour

Exception is catched.

Actual behaviour

Exception is eaten up by Promise and never show up.

Operating System

Windows 10

Version of Python, python-telegram-bot & dependencies

python-telegram-bot 13.13
Bot API 6.1
certifi2021.10.08
Python 3.9.5 (tags/v3.9.5:0a7dcbd, May  3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)]

Relevant log output

No response

Additional Context

I'm using Promises within MessageQueue. I know that it is deprecated, but I think that at least this issue is worth mentioning here #2139

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy