From e82fcd5d42c7218fc6e8b01f7af3e24c62caad66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Sun, 19 Sep 2021 11:30:17 +0200 Subject: [PATCH] error logging --- tgbot/kollagen-bot/main.py | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/tgbot/kollagen-bot/main.py b/tgbot/kollagen-bot/main.py index c30ce69..d0c3bed 100644 --- a/tgbot/kollagen-bot/main.py +++ b/tgbot/kollagen-bot/main.py @@ -86,29 +86,11 @@ class KollagenBot: msg="Exception while handling an update:", exc_info=context.error ) - # # traceback.format_exception returns the usual python message about an exception, but as a - # # list of strings rather than a single string, so we have to join them together. - # tb_list = traceback.format_exception( - # None, context.error, context.error.__traceback__ - # ) - # tb_string = "".join(tb_list) - - # # Build the message with some markup and additional information about what happened. - # # You might need to add some logic to deal with messages longer than the 4096 character limit. - # update_str = update.to_dict() if isinstance(update, Update) else str(update) - # message = ( - # f"An exception was raised while handling an update\n" - # f"
update = {html.escape(json.dumps(update_str, indent=2, ensure_ascii=False))}"
-        #     "
\n\n" - # f"
context.chat_data = {html.escape(str(context.chat_data))}
\n\n" - # f"
context.user_data = {html.escape(str(context.user_data))}
\n\n" - # f"
{html.escape(tb_string)}
" - # ) - - # # Finally, send the message - # context.bot.send_message( - # chat_id=DEVELOPER_CHAT_ID, text=message, parse_mode=ParseMode.HTML - # ) + if isinstance(update, Update): + if isinstance(context.error, subprocess.CalledProcessError): + update.message.reply_text(f"Something is fucked!\n{context.error.stderr.decode('utf-8')}") + else: + update.message.reply_text(f"Something is fucked!\n{context.error}") def start_idle(self): self.updater.start_polling()