Skip to content
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

Bot crashes upon logging transactions when username or user's name contains Markdown-like characters #6

Open
CrsiX opened this issue Sep 14, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@CrsiX
Copy link
Member

CrsiX commented Sep 14, 2021

When money is transferred from one to another user account, for whatever reason, the transaction is first announced in the log file, then performed in the database, then again accepted in the log file. Lastly, the bot sends confirmation messages to the chats defined in the config file. The last step may break the bot if the username or user's name contains special characters like underscore, since that transaction confirmation message is parsed as Markdown. Note that it only breaks when the number of tokens that can be interpreted as Markdown is odd, see below.

The above problem is not critical for single transactions, since logging of those is done after everything else. However, this is a critical problem for communisms where lots of transactions might be performed at once.

Sample traceback:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/telegram/ext/dispatcher.py", line 340, in process_update
    handler.handle_update(update, self, check, context)
  File "/usr/local/lib/python3.7/dist-packages/telegram/ext/handler.py", line 119, in handle_update
    return self.callback(update, context)
  File "/home/matebot/MateBot/mate_bot/commands/base.py", line 216, in __call__
    self.run(args, update)
  File "/home/matebot/MateBot/mate_bot/commands/consume.py", line 77, in run
    update.effective_message.bot
  File "/home/matebot/MateBot/mate_bot/state/transactions.py", line 214, in commit
  File "/home/matebot/MateBot/mate_bot/state/transactions.py", line 290, in log_message
    transaction_logging = [config["chats"]["transactions"]]
  File "<decorator-gen-2>", line 2, in send_message
  File "/usr/local/lib/python3.7/dist-packages/telegram/bot.py", line 67, in decorator
    result = func(*args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/telegram/bot.py", line 348, in send_message
    timeout=timeout, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/telegram/bot.py", line 175, in _message
    result = self._request.post(url, data, timeout=timeout)
  File "/usr/local/lib/python3.7/dist-packages/telegram/utils/request.py", line 333, in post
    **urlopen_kwargs)
  File "/usr/local/lib/python3.7/dist-packages/telegram/utils/request.py", line 244, in _request_wrapper
    raise BadRequest(message)
telegram.error.BadRequest: Can't parse entities: can't find end of the entity starting at byte offset 52
@CrsiX CrsiX added the bug Something isn't working label Sep 14, 2021
@CrsiX
Copy link
Member Author

CrsiX commented Oct 24, 2021

The exact same problem occurs when using any other command which replies with Markdown content and contains stuff like underscores. It could, for example, also happen for /balance @some_user if @some_user doesn't exist. To make it worse, the caller of that command wouldn't even get a response.

@CrsiX
Copy link
Member Author

CrsiX commented Jan 18, 2023

After the rewrite using the core API, this issue may be fixed. This has to be evaluated. For example, closing a communism triggers the transaction processing in the backend; therefore the critical bug of broken log messages doesn't exist anymore. Other bugs of this kind may still exist, though they only affect the representation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant