Add inline error info
This commit is contained in:
@@ -1 +1,2 @@
|
||||
from .handler import on_error
|
||||
from .handler import on_error, Error
|
||||
from .pretty import PrettyException
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
from bot.common import console
|
||||
from aiogram.types.error_event import ErrorEvent
|
||||
from aiogram import Bot
|
||||
from aiogram.dispatcher import router as s_router
|
||||
|
||||
from rich.traceback import Traceback
|
||||
from .pretty import PrettyException
|
||||
|
||||
from bot.modules.database import db
|
||||
|
||||
@@ -11,6 +13,7 @@ from dataclasses import dataclass
|
||||
|
||||
@dataclass
|
||||
class Error:
|
||||
exception: PrettyException
|
||||
traceback: Traceback
|
||||
inline_message_id: str | None = None
|
||||
|
||||
@@ -26,12 +29,14 @@ async def on_error(event: ErrorEvent, bot: Bot):
|
||||
event.exception,
|
||||
event.exception.__traceback__,
|
||||
show_locals=True,
|
||||
max_frames=1,
|
||||
suppress=[s_router],
|
||||
)
|
||||
pretty_exception = PrettyException(event.exception)
|
||||
|
||||
if event.update.chosen_inline_result:
|
||||
db.errors[error_id] = Error(
|
||||
traceback=traceback,
|
||||
exception=pretty_exception,
|
||||
inline_message_id=event.update.chosen_inline_result.inline_message_id,
|
||||
)
|
||||
|
||||
@@ -45,9 +50,10 @@ async def on_error(event: ErrorEvent, bot: Bot):
|
||||
else:
|
||||
db.errors[error_id] = Error(
|
||||
traceback=traceback,
|
||||
exception=pretty_exception,
|
||||
)
|
||||
|
||||
console.print(f'[red]{error_id} occurred[/]')
|
||||
console.print(event)
|
||||
console.print(traceback)
|
||||
console.print(f'-{error_id}-')
|
||||
console.print(f'-{error_id} occurred-')
|
||||
|
||||
@@ -6,16 +6,18 @@ import re
|
||||
|
||||
class PrettyException:
|
||||
def __init__(self, e: Exception):
|
||||
self.pretty_exception = f"""
|
||||
❌ Error! Report it to admins:
|
||||
🐊 <code>{e.__traceback__.tb_frame.f_code.co_filename.replace(os.getcwd(), "")}\r
|
||||
</code>:{e.__traceback__.tb_frame.f_lineno}
|
||||
self.long = f"""
|
||||
😍 {e.__class__.__name__}
|
||||
👉 {"".join(traceback.format_exception_only(e)).strip()}
|
||||
|
||||
⬇️ Trace:
|
||||
{self.get_full_stack()}
|
||||
🐊 <code>{e.__traceback__.tb_frame.f_code.co_filename.replace(os.getcwd(), "")}\r
|
||||
</code>:{e.__traceback__.tb_frame.f_lineno}
|
||||
"""
|
||||
self.short = (f'{e.__class__.__name__}: '
|
||||
f'{"".join(traceback.format_exception_only(e)).strip()}')
|
||||
|
||||
self.pretty_exception = (f"{self.long}\n\n"
|
||||
f"⬇️ Trace:"
|
||||
f"{self.get_full_stack()}")
|
||||
|
||||
@staticmethod
|
||||
def get_full_stack():
|
||||
|
||||
Reference in New Issue
Block a user