mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-11 01:54:53 +00:00
Change error message for missing keys in the context.
This commit is contained in:
parent
c567b77a00
commit
62d5dda84d
2 changed files with 6 additions and 5 deletions
|
|
@ -7,7 +7,10 @@ from ..utils import context
|
||||||
def _get(key, default=None, no_error=False):
|
def _get(key, default=None, no_error=False):
|
||||||
result = context.get_value(key, default)
|
result = context.get_value(key, default)
|
||||||
if not no_error and result is None:
|
if not no_error and result is None:
|
||||||
raise RuntimeError(f"Context is not configured for '{key}'")
|
raise RuntimeError(f"Key '{key}' does not exist in the current execution context!\n"
|
||||||
|
f"Maybe asyncio task factory is not configured!\n"
|
||||||
|
f"\t>>> from aiogram.utils import context\n"
|
||||||
|
f"\t>>> loop.set_task_factory(context.task_factory)")
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -138,10 +138,8 @@ class TelegramObject(metaclass=MetaTelegramObject):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def bot(self):
|
def bot(self):
|
||||||
bot = get_value('bot')
|
from ..dispatcher import ctx
|
||||||
if bot is None:
|
return ctx.get_bot()
|
||||||
raise RuntimeError('Can not found bot instance in current context!')
|
|
||||||
return bot
|
|
||||||
|
|
||||||
def to_python(self) -> typing.Dict:
|
def to_python(self) -> typing.Dict:
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue