Change error message for missing keys in the context.

This commit is contained in:
Alex Root Junior 2017-12-22 05:35:31 +02:00
parent c567b77a00
commit 62d5dda84d
2 changed files with 6 additions and 5 deletions

View file

@ -7,7 +7,10 @@ from ..utils import context
def _get(key, default=None, no_error=False):
result = context.get_value(key, default)
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

View file

@ -138,10 +138,8 @@ class TelegramObject(metaclass=MetaTelegramObject):
@property
def bot(self):
bot = get_value('bot')
if bot is None:
raise RuntimeError('Can not found bot instance in current context!')
return bot
from ..dispatcher import ctx
return ctx.get_bot()
def to_python(self) -> typing.Dict:
"""