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 error handler doesn't redirect arguments #772

Open
3 tasks done
Inv1x opened this issue Jul 26, 2023 · 2 comments
Open
3 tasks done

Bot error handler doesn't redirect arguments #772

Inv1x opened this issue Jul 26, 2023 · 2 comments
Assignees
Labels
feature-request New feature or request

Comments

@Inv1x
Copy link

Inv1x commented Jul 26, 2023

Checklist

  • Я уверен, что это баг фреймворка
  • Я искал похожие баги в issues
  • Я установил последнюю версию (pip3 install -U https://github.com/vkbottle/vkbottle/archive/dev.zip) и проблема осталась

Описание

Когда я добавляю ErrorHandler в бота с параметром redirect_arguments=True, а затем ловлю ошибки с помощью @bot.error_handler.register_error_handler, то в функцию с отловом не проходят аргументы функции, из которой вызвана ошибка

Пример кода

from vkbottle import Bot, ErrorHandler
bot = Bot(token=TOKEN, error_handler=ErrorHandler(redirect_arguments=True))


@bot.on.message(command=("игрок", 1))
async def player_handler(message: Message, args: Tuple[str], language: str):
    raise ValueError


@bot.error_handler.register_error_handler(ValueError)
async def value_not_found_handler(e: ValueError, *args):
    pass  # args пустой

Логи

No response

@Inv1x Inv1x added the bug Something isn't working label Jul 26, 2023
@Inv1x
Copy link
Author

Inv1x commented Jul 26, 2023

Предварительно я вижу проблему в файле с роутером, так как именно роутер не пробрасывает никакие дополнительные параметры

Screenshot 2023-07-27 at 00 22 13

@timoniq
Copy link
Member

timoniq commented Jul 27, 2023

привет! спасибо за вопрос

у роутера уже нет ответственности в получении контекстных переменных из хендлера
пока можно сделать так:

@bot.on.message(command=("игрок", 1))
@bot.error_handler.catch
async def player_handler(message: Message, args: Tuple[str], language: str):
    raise ValueError

но это, конечно, не полное решение проблемы, так как потребуется везде вешать catch

дело в том что с глобальным error_handler'ом сложно гарантировать консистентность того, что будет приходить в args. возможно, стоит сделать возможность установки локального error_handler'а для каждого view.

я перенесу этот issue в блок feature request и возможно кто-то сможет предложить решение лучше

@timoniq timoniq added feature-request New feature or request and removed bug Something isn't working labels Jul 27, 2023
@timoniq timoniq pinned this issue Jul 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants