Skip to content

[BUG] Promise ignores exceptions #3201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
elebur opened this issue Aug 20, 2022 · 5 comments
Closed

[BUG] Promise ignores exceptions #3201

elebur opened this issue Aug 20, 2022 · 5 comments

Comments

@elebur
Copy link

elebur commented Aug 20, 2022

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

@Poolitzer
Copy link
Member

Hey, thanks for the issue and providing an example. I can confirm that the error doesn't show up.

V13 however is basically on a bot api updates only version, on top of message queue being depreciated. We actually took a lot of time and implemented #3148 for the V20 update, so I do not think we will fix this.

@elebur
Copy link
Author

elebur commented Aug 21, 2022

Hi.
I think this issue is worth mentioning here - #2139
Because V20 isn't stable yet and a lot of people use V13, and I suppose many of them use MessageQueue. So at least they would be aware of this bug.

@Poolitzer
Copy link
Member

Oh, you mean edit it into the first line if known bugs?

@elebur
Copy link
Author

elebur commented Aug 21, 2022

Yes:)

@Poolitzer
Copy link
Member

Cool, updated it. I will close this as the others as wont fix I guess.

@Poolitzer Poolitzer closed this as not planned Won't fix, can't repro, duplicate, stale Aug 21, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Aug 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants