Partially configured object: shows what is missing instead of cryptic error only

This commit is contained in:
Romain Dorgueil
2018-07-11 15:46:23 +02:00
parent 9b55e211db
commit 4c2287ebf0
3 changed files with 18 additions and 10 deletions

View File

@ -77,7 +77,6 @@ except:
PartiallyConfigured = functools.partial PartiallyConfigured = functools.partial
else: else:
class PartiallyConfigured(_functools.partial): class PartiallyConfigured(_functools.partial):
@property # TODO XXX cache this @property # TODO XXX cache this
def _options_values(self): def _options_values(self):

View File

@ -3,10 +3,9 @@ import sys
from contextlib import contextmanager from contextlib import contextmanager
from logging import ERROR from logging import ERROR
from mondrian import term
from bonobo.util import deprecated from bonobo.util import deprecated
from bonobo.util.objects import Wrapper, get_name from bonobo.util.objects import Wrapper, get_name
from mondrian import term
@contextmanager @contextmanager
@ -23,7 +22,7 @@ def unrecoverable(error_handler):
yield yield
except Exception as exc: # pylint: disable=broad-except except Exception as exc: # pylint: disable=broad-except
error_handler(*sys.exc_info(), level=ERROR) error_handler(*sys.exc_info(), level=ERROR)
raise # raise unrecoverableerror from x ? raise # raise unrecoverableerror from exc ?
class Lifecycle: class Lifecycle:
@ -60,7 +59,10 @@ class Lifecycle:
@property @property
def status(self): def status(self):
"""One character status for this node. """ """
One character status for this node.
"""
if self._defunct: if self._defunct:
return '!' return '!'
if not self.started: if not self.started:

View File

@ -77,8 +77,15 @@ class NodeExecutionContext(BaseContext, WithStatistics):
initial = self._get_initial_context() initial = self._get_initial_context()
self._stack = ContextCurrifier(self.wrapped, *initial.args, **initial.kwargs) self._stack = ContextCurrifier(self.wrapped, *initial.args, **initial.kwargs)
if isconfigurabletype(self.wrapped): if isconfigurabletype(self.wrapped):
try:
self.wrapped = self.wrapped(_final=True)
except Exception as exc:
# Not normal to have a partially configured object here, so let's warn the user instead of having get into # Not normal to have a partially configured object here, so let's warn the user instead of having get into
# the hard trouble of understanding that by himself. # the hard trouble of understanding that by himself.
raise TypeError(
'Configurables should be instanciated before execution starts.\nGot {!r}.\n'.format(self.wrapped)
) from exc
else:
raise TypeError( raise TypeError(
'Configurables should be instanciated before execution starts.\nGot {!r}.\n'.format(self.wrapped) 'Configurables should be instanciated before execution starts.\nGot {!r}.\n'.format(self.wrapped)
) )