Add inline error info
This commit is contained in:
@@ -3,6 +3,7 @@ from . import (
|
|||||||
initialize,
|
initialize,
|
||||||
inline_song,
|
inline_song,
|
||||||
inline_url,
|
inline_url,
|
||||||
|
inline_error,
|
||||||
inline_default,
|
inline_default,
|
||||||
inline_empty,
|
inline_empty,
|
||||||
on_chosen,
|
on_chosen,
|
||||||
@@ -18,6 +19,7 @@ router.include_routers(
|
|||||||
initialize.router,
|
initialize.router,
|
||||||
inline_song.router,
|
inline_song.router,
|
||||||
inline_url.router,
|
inline_url.router,
|
||||||
|
inline_error.router,
|
||||||
inline_default.router,
|
inline_default.router,
|
||||||
inline_empty.router,
|
inline_empty.router,
|
||||||
on_chosen.router,
|
on_chosen.router,
|
||||||
|
|||||||
1
bot/handlers/inline_error/__init__.py
Normal file
1
bot/handlers/inline_error/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from .on_inline_error_info import router
|
||||||
17
bot/handlers/inline_error/on_inline_error_info.py
Normal file
17
bot/handlers/inline_error/on_inline_error_info.py
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
from aiogram import Router
|
||||||
|
|
||||||
|
from aiogram.types import InlineQuery
|
||||||
|
|
||||||
|
from bot.results.error import get_error_search_results
|
||||||
|
from bot.filters import ServiceSearchFilter
|
||||||
|
|
||||||
|
router = Router()
|
||||||
|
|
||||||
|
|
||||||
|
@router.inline_query(ServiceSearchFilter('error'))
|
||||||
|
async def search_spotify_inline_query(inline_query: InlineQuery):
|
||||||
|
await inline_query.answer(
|
||||||
|
await get_error_search_results(inline_query.query.removeprefix('error:')),
|
||||||
|
cache_time=0,
|
||||||
|
is_personal=True
|
||||||
|
)
|
||||||
@@ -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 bot.common import console
|
||||||
from aiogram.types.error_event import ErrorEvent
|
from aiogram.types.error_event import ErrorEvent
|
||||||
from aiogram import Bot
|
from aiogram import Bot
|
||||||
|
from aiogram.dispatcher import router as s_router
|
||||||
|
|
||||||
from rich.traceback import Traceback
|
from rich.traceback import Traceback
|
||||||
|
from .pretty import PrettyException
|
||||||
|
|
||||||
from bot.modules.database import db
|
from bot.modules.database import db
|
||||||
|
|
||||||
@@ -11,6 +13,7 @@ from dataclasses import dataclass
|
|||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Error:
|
class Error:
|
||||||
|
exception: PrettyException
|
||||||
traceback: Traceback
|
traceback: Traceback
|
||||||
inline_message_id: str | None = None
|
inline_message_id: str | None = None
|
||||||
|
|
||||||
@@ -26,12 +29,14 @@ async def on_error(event: ErrorEvent, bot: Bot):
|
|||||||
event.exception,
|
event.exception,
|
||||||
event.exception.__traceback__,
|
event.exception.__traceback__,
|
||||||
show_locals=True,
|
show_locals=True,
|
||||||
max_frames=1,
|
suppress=[s_router],
|
||||||
)
|
)
|
||||||
|
pretty_exception = PrettyException(event.exception)
|
||||||
|
|
||||||
if event.update.chosen_inline_result:
|
if event.update.chosen_inline_result:
|
||||||
db.errors[error_id] = Error(
|
db.errors[error_id] = Error(
|
||||||
traceback=traceback,
|
traceback=traceback,
|
||||||
|
exception=pretty_exception,
|
||||||
inline_message_id=event.update.chosen_inline_result.inline_message_id,
|
inline_message_id=event.update.chosen_inline_result.inline_message_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -45,9 +50,10 @@ async def on_error(event: ErrorEvent, bot: Bot):
|
|||||||
else:
|
else:
|
||||||
db.errors[error_id] = Error(
|
db.errors[error_id] = Error(
|
||||||
traceback=traceback,
|
traceback=traceback,
|
||||||
|
exception=pretty_exception,
|
||||||
)
|
)
|
||||||
|
|
||||||
console.print(f'[red]{error_id} occurred[/]')
|
console.print(f'[red]{error_id} occurred[/]')
|
||||||
console.print(event)
|
console.print(event)
|
||||||
console.print(traceback)
|
console.print(traceback)
|
||||||
console.print(f'-{error_id}-')
|
console.print(f'-{error_id} occurred-')
|
||||||
|
|||||||
@@ -6,16 +6,18 @@ import re
|
|||||||
|
|
||||||
class PrettyException:
|
class PrettyException:
|
||||||
def __init__(self, e: Exception):
|
def __init__(self, e: Exception):
|
||||||
self.pretty_exception = f"""
|
self.long = 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}
|
|
||||||
😍 {e.__class__.__name__}
|
😍 {e.__class__.__name__}
|
||||||
👉 {"".join(traceback.format_exception_only(e)).strip()}
|
👉 {"".join(traceback.format_exception_only(e)).strip()}
|
||||||
|
🐊 <code>{e.__traceback__.tb_frame.f_code.co_filename.replace(os.getcwd(), "")}\r
|
||||||
⬇️ Trace:
|
</code>:{e.__traceback__.tb_frame.f_lineno}
|
||||||
{self.get_full_stack()}
|
|
||||||
"""
|
"""
|
||||||
|
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
|
@staticmethod
|
||||||
def get_full_stack():
|
def get_full_stack():
|
||||||
|
|||||||
1
bot/results/error/__init__.py
Normal file
1
bot/results/error/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from .error import get_error_search_results
|
||||||
31
bot/results/error/error.py
Normal file
31
bot/results/error/error.py
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
from aiogram.types import (
|
||||||
|
InlineQueryResultArticle, InputTextMessageContent,
|
||||||
|
)
|
||||||
|
|
||||||
|
from bot.modules.database import db
|
||||||
|
from bot.modules.error import Error
|
||||||
|
|
||||||
|
from bot.common import console
|
||||||
|
|
||||||
|
|
||||||
|
async def get_error_search_results(error_id: str) -> (list[InlineQueryResultArticle]
|
||||||
|
| None):
|
||||||
|
error: Error = db.errors.get(error_id)
|
||||||
|
if error is None:
|
||||||
|
return []
|
||||||
|
|
||||||
|
console.print(f'{error_id} requested')
|
||||||
|
console.print(error.traceback)
|
||||||
|
console.print(f'-{error_id} requested-')
|
||||||
|
|
||||||
|
return [(
|
||||||
|
InlineQueryResultArticle(
|
||||||
|
id=error_id,
|
||||||
|
title=f'Error {error_id}',
|
||||||
|
description=error.exception.short,
|
||||||
|
input_message_content=InputTextMessageContent(
|
||||||
|
message_text=error.exception.long,
|
||||||
|
parse_mode='HTML',
|
||||||
|
),
|
||||||
|
)
|
||||||
|
)]
|
||||||
Reference in New Issue
Block a user