Skip to content

Commit 9d3e5b3

Browse files
committed
Improve error reporting
Primarily by also exposing the message that cause the error.
1 parent e71165c commit 9d3e5b3

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

bot.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'''Telegram bot that (primarily) attempts to perform url hacks to get around paywalls'''
22

33

4-
__version__ = '2.5.0'
4+
__version__ = '2.5.1'
55

66

77
import asyncio
@@ -42,16 +42,18 @@ async def error_handler(update: object, context: ContextTypes.DEFAULT_TYPE) -> N
4242
return
4343

4444
trace = "".join(traceback.format_exception(None, context.error, context.error.__traceback__))
45-
payload = ""
45+
user_info = ""
4646
if update.effective_user:
47-
payload += f' with the user {mention_html(update.effective_user.id, update.effective_user.first_name)}' # If it blows up here it's possibly because you've used python < 3.6
47+
user_info += f' when {mention_html(update.effective_user.id, update.effective_user.first_name)}' # If it blows up here it's possibly because you've used python < 3.6
4848
if update.effective_chat:
4949
if update.effective_chat.title:
50-
payload += f' within the chat <i>{html.escape(str(update.effective_chat.title))}</i>'
50+
user_info += f' in the chat <i>{html.escape(str(update.effective_chat.title))}</i>'
5151
if update.effective_chat.username:
52-
payload += f' (@{update.effective_chat.username})'
52+
user_info += f' (@{update.effective_chat.username})'
5353

54-
message = f"Hey.\n The error <code>{sys.exc_info()[0].__name__}: {html.escape(str(context.error))}</code> happened{payload}. The full traceback:\n\n<code>{html.escape(trace)}</code>"
54+
text = update.effective_message.text if update.effective_message else None
55+
56+
message = f"Hey.\n The error <code>{sys.exc_info()[0].__name__}: {html.escape(str(context.error))}</code> happened{user_info} said <code>{text}</code>.\n\n<pre><code class='language-python'>{html.escape(trace)}</code></pre>"
5557

5658
for admin_id in LIST_OF_ADMINS:
5759
await context.bot.send_message(chat_id=admin_id, text=message, parse_mode=ParseMode.HTML)

0 commit comments

Comments
 (0)