Skip to content

Commit 3900858

Browse files
committed
DROP(fnop) MultiValueError hindered debug
1 parent 89c2913 commit 3900858

File tree

5 files changed

+20
-51
lines changed

5 files changed

+20
-51
lines changed

graphtik/base.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@
3333
log = logging.getLogger(__name__)
3434

3535

36-
class MultiValueError(ValueError):
37-
def __str__(self):
38-
"""Assuming it has been called with ``MultiValueError(msg, ex1, ...) #"""
39-
return str(self.args[0]) # pylint: disable=unsubscriptable-object
40-
41-
4236
class AbortedException(Exception):
4337
"""
4438
Raised from Network when :func:`.abort_run()` is called, and contains the solution ...

graphtik/config.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ def _tristate_armed(context_var: ContextVar, enabled):
8888
8989
.. debug-behavior-start
9090
91-
+ :meth:`FnOp.compute()` raise any matching-needs errors immediately;
9291
+ :meth:`FnOp.compute()` prints out full given-inputs (not just their keys);
9392
+ net objects print details recursively;
9493
+ plotted SVG diagrams include style-provenance as tooltips;

graphtik/fnop.py

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
from .base import (
3030
UNSET,
3131
Items,
32-
MultiValueError,
3332
Operation,
3433
Plottable,
3534
PlotArgs,
@@ -587,20 +586,12 @@ def validate_fn_name(self):
587586
)
588587

589588
def _prepare_match_inputs_error(
590-
self,
591-
exceptions: List[Tuple[Any, Exception]],
592-
missing: List,
593-
varargs_bad: List,
594-
named_inputs: Mapping,
589+
self, missing: List, varargs_bad: List, named_inputs: Mapping,
595590
) -> ValueError:
596591
from .config import is_debug
597592

598-
errors = [
599-
f"{i}. Need({n!r}) failed due to: {type(nex).__name__}({nex})"
600-
for i, (n, nex) in enumerate(exceptions, 1)
601-
]
602-
ner = len(exceptions) + 1
603-
593+
ner = 1
594+
errors = []
604595
if missing:
605596
errors.append(f"{ner}. Missing compulsory needs{list(missing)}!")
606597
ner += 1
@@ -611,20 +602,18 @@ def _prepare_match_inputs_error(
611602
inputs = dict(named_inputs) if is_debug() else list(named_inputs)
612603
errors.append(f"+++inputs: {inputs}")
613604
errors.append(f"+++{self}")
614-
errors.append(
615-
"(tip: set GRAPHTIK_DEBUG envvar to raise immediately and/or enable DEBUG-logging)"
616-
)
617605

618606
msg = textwrap.indent("\n".join(errors), " " * 4)
619-
raise MultiValueError(f"Failed preparing needs: \n{msg}", *exceptions)
607+
raise ValueError(f"Failed preparing needs: \n{msg}")
620608

621609
def _match_inputs_with_fn_needs(self, named_inputs) -> Tuple[list, list, dict]:
622610
positional, vararg_vals = [], []
623611
kwargs = {}
624-
errors, missing, varargs_bad = [], [], []
612+
missing, varargs_bad = [], []
625613
for n in self._fn_needs:
626-
assert not is_sfx(n), locals()
627614
try:
615+
ok = False
616+
assert not is_sfx(n), locals()
628617
if n not in named_inputs:
629618
if not is_optional(n) or is_sfx(n):
630619
# It means `inputs` < compulsory `needs`.
@@ -653,25 +642,15 @@ def _match_inputs_with_fn_needs(self, named_inputs) -> Tuple[list, list, dict]:
653642

654643
else:
655644
positional.append(inp_value)
645+
ok = True
646+
finally:
647+
if not ok:
648+
log.error(
649+
"Failed while preparing op(%s) need(%s)!", self.name, n,
650+
)
656651

657-
except Exception as nex:
658-
from .config import is_debug
659-
660-
if is_debug():
661-
raise
662-
log.debug(
663-
"Cannot prepare op(%s) need(%s) due to: %s",
664-
self.name,
665-
n,
666-
nex,
667-
exc_info=nex,
668-
)
669-
errors.append((n, nex))
670-
671-
if errors or missing or varargs_bad:
672-
raise self._prepare_match_inputs_error(
673-
errors, missing, varargs_bad, named_inputs
674-
)
652+
if missing or varargs_bad:
653+
raise self._prepare_match_inputs_error(missing, varargs_bad, named_inputs)
675654

676655
return positional, vararg_vals, kwargs
677656

graphtik/modifier.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -595,14 +595,13 @@ def jsonp(name: str, jsonp=None) -> _Modifier:
595595
596596
>>> results = copy_values.compute({"inputs": {"a": 1, "b": 2}})
597597
Traceback (most recent call last):
598-
graphtik.base.MultiValueError: Failed preparing needs:
598+
ValueError: Failed preparing needs:
599599
1. Missing compulsory needs['inputs/a'($), 'inputs/b'($)]!
600600
+++inputs: ['inputs']
601601
+++FnOp(name='copy a+b-->A+BB',
602602
needs=['inputs/a'($), 'inputs/b'($)],
603603
provides=['RESULTS/A'($), 'RESULTS/BB'($)],
604604
fn='identity_fn')
605-
(tip: set GRAPHTIK_DEBUG envvar to raise immediately and/or enable DEBUG-logging)
606605
607606
>>> results = copy_values.compute({"inputs/a": 1, "inputs/b": 2})
608607
>>> results
@@ -747,11 +746,10 @@ def varargs(name: str, accessor: Accessor = None, jsonp=None) -> _Modifier:
747746
>>> graph(a=5, b=0xBAD)
748747
Traceback (most recent call last):
749748
...
750-
graphtik.base.MultiValueError: Failed preparing needs:
749+
ValueError: Failed preparing needs:
751750
1. Expected needs['b'(+)] to be non-str iterables!
752751
+++inputs: ['a', 'b']
753752
+++FnOp(name='enlist', needs=['a', 'b'(+)], provides=['sum'], fn='enlist')
754-
(tip: set GRAPHTIK_DEBUG envvar to raise immediately and/or enable DEBUG-logging)
755753
756754
.. varargs-mistake-start
757755
.. Attention::
@@ -761,14 +759,13 @@ def varargs(name: str, accessor: Accessor = None, jsonp=None) -> _Modifier:
761759
>>> graph(a=5, b="mistake")
762760
Traceback (most recent call last):
763761
...
764-
graphtik.base.MultiValueError: Failed preparing needs:
762+
ValueError: Failed preparing needs:
765763
1. Expected needs['b'(+)] to be non-str iterables!
766764
+++inputs: ['a', 'b']
767765
+++FnOp(name='enlist',
768766
needs=['a', 'b'(+)],
769767
provides=['sum'],
770768
fn='enlist')
771-
(tip: set GRAPHTIK_DEBUG envvar to raise immediately and/or enable DEBUG-logging)
772769
773770
.. varargs-mistake-end
774771

test/test_hierarchical.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import pytest
1010

11-
from graphtik import NO_RESULT, MultiValueError, compose, operation, sfxed, vararg
11+
from graphtik import NO_RESULT, compose, operation, sfxed, vararg
1212
from graphtik.base import RenArgs
1313
from graphtik.config import solution_layered
1414
from graphtik.execution import task_context
@@ -60,7 +60,7 @@ def test_jsonp_and_conveyor_fn_simple():
6060

6161
## Ops are unaware of subdocs, Solution does.
6262
#
63-
with pytest.raises(MultiValueError, match="Missing compulsory needs"):
63+
with pytest.raises(ValueError, match="Missing compulsory needs"):
6464
copy_values.compute({"inputs": {"a": 1, "b": 2}})
6565
results = copy_values.compute({"inputs/a": 1, "inputs/b": 2})
6666
assert results == {"RESULTS/A": 1, "RESULTS/BB": 2}

0 commit comments

Comments
 (0)