allow for defensive behaviour in konsume
This commit is contained in:
parent
f3288f7cf0
commit
697c3bb851
1 changed files with 9 additions and 3 deletions
|
@ -106,22 +106,28 @@ def _wrap(j, parent=None):
|
|||
res = Wvalue(parent, j)
|
||||
return res, [res]
|
||||
else:
|
||||
raise RuntimeError(str(j))
|
||||
raise RuntimeError(f'Unexpected type: {type(j)} {j}')
|
||||
|
||||
from contextlib import contextmanager
|
||||
|
||||
class UnconsumedError(Exception):
|
||||
pass
|
||||
|
||||
# TODO think about error policy later...
|
||||
@contextmanager
|
||||
def wrap(j):
|
||||
def wrap(j, throw=True):
|
||||
w, children = _wrap(j)
|
||||
|
||||
yield w
|
||||
|
||||
for c in children:
|
||||
if not c.this_consumed(): # TODO hmm. how does it figure out if it's consumed???
|
||||
raise UnconsumedError(str(c))
|
||||
if throw:
|
||||
raise UnconsumedError(str(c))
|
||||
else:
|
||||
# TODO log?
|
||||
pass
|
||||
|
||||
|
||||
def test_unconsumed():
|
||||
import pytest # type: ignore
|
||||
|
|
Loading…
Add table
Reference in a new issue