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)
|
res = Wvalue(parent, j)
|
||||||
return res, [res]
|
return res, [res]
|
||||||
else:
|
else:
|
||||||
raise RuntimeError(str(j))
|
raise RuntimeError(f'Unexpected type: {type(j)} {j}')
|
||||||
|
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
|
|
||||||
class UnconsumedError(Exception):
|
class UnconsumedError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# TODO think about error policy later...
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def wrap(j):
|
def wrap(j, throw=True):
|
||||||
w, children = _wrap(j)
|
w, children = _wrap(j)
|
||||||
|
|
||||||
yield w
|
yield w
|
||||||
|
|
||||||
for c in children:
|
for c in children:
|
||||||
if not c.this_consumed(): # TODO hmm. how does it figure out if it's consumed???
|
if not c.this_consumed(): # TODO hmm. how does it figure out if it's consumed???
|
||||||
|
if throw:
|
||||||
raise UnconsumedError(str(c))
|
raise UnconsumedError(str(c))
|
||||||
|
else:
|
||||||
|
# TODO log?
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def test_unconsumed():
|
def test_unconsumed():
|
||||||
import pytest # type: ignore
|
import pytest # type: ignore
|
||||||
|
|
Loading…
Add table
Reference in a new issue