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): 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

View file

@ -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:
""" """