Skip to content

Commit 03308a9

Browse files
committed
raise ProcessGraphVisitException from resolve_from_node
1 parent cd40631 commit 03308a9

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2525
([#233](https://github.com/Open-EO/openeo-python-client/pull/233)).
2626
- Update documentation/examples/tests: EPSG CRS in `filter_bbox` should be integer code, not string
2727
([#233](https://github.com/Open-EO/openeo-python-client/pull/233)).
28+
- Raise `ProcessGraphVisitException` from `ProcessGraphVisitor.resolve_from_node()` (instead of generic `ValueError`)
2829

2930

3031
### Removed

openeo/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.8.3a1'
1+
__version__ = '0.8.3a2'

openeo/internal/process_graph_visitor.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,21 @@ def dereference_from_node_arguments(cls, process_graph: dict) -> str:
2929
:return: name of the "result" node of the graph
3030
"""
3131

32-
# TODO avoid manipulating process graph in place? make it more explicit? work on a copy? Where is this functionality used anyway?
32+
# TODO avoid manipulating process graph in place? make it more explicit? work on a copy?
3333
# TODO call it more something like "unflatten"?. Split this off of ProcessGraphVisitor?
3434
# TODO implement this through `ProcessGraphUnflattener` ?
3535

3636
def resolve_from_node(process_graph, node, from_node):
3737
if from_node not in process_graph:
38-
raise ValueError('from_node {f!r} (referenced by {n!r}) not in process graph.'.format(
38+
raise ProcessGraphVisitException('from_node {f!r} (referenced by {n!r}) not in process graph.'.format(
3939
f=from_node, n=node))
4040
return process_graph[from_node]
4141

4242
result_node = None
4343
for node, node_dict in process_graph.items():
4444
if node_dict.get("result", False):
4545
if result_node:
46-
raise ValueError("Multiple result nodes: {a}, {b}".format(a=result_node, b=node))
46+
raise ProcessGraphVisitException("Multiple result nodes: {a}, {b}".format(a=result_node, b=node))
4747
result_node = node
4848
arguments = node_dict.get("arguments", {})
4949
for arg in arguments.values():
@@ -60,7 +60,8 @@ def resolve_from_node(process_graph, node, from_node):
6060
arg[i] = resolve_from_node(process_graph, node, element['from_node'])
6161

6262
if result_node is None:
63-
raise ValueError("The provided process graph does not contain a result node. Received this graph: " + json.dumps(process_graph, indent=2))
63+
dump = json.dumps(process_graph, indent=2)
64+
raise ProcessGraphVisitException("No result node in process graph: " + dump[:1000])
6465
return result_node
6566

6667
def accept_process_graph(self, graph: dict) -> 'ProcessGraphVisitor':

tests/internal/test_process_graph_visitor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,15 +292,15 @@ def test_dereference_dict_arg():
292292

293293

294294
def test_dereference_no_result_node():
295-
with pytest.raises(ValueError, match="does not contain a result node"):
295+
with pytest.raises(ProcessGraphVisitException, match="No result node in process graph"):
296296
ProcessGraphVisitor.dereference_from_node_arguments({
297297
"node1": {},
298298
"node2": {}
299299
})
300300

301301

302302
def test_dereference_multiple_result_node():
303-
with pytest.raises(ValueError, match="Multiple result nodes"):
303+
with pytest.raises(ProcessGraphVisitException, match="Multiple result nodes"):
304304
ProcessGraphVisitor.dereference_from_node_arguments({
305305
"node1": {"result": True},
306306
"node2": {"result": True}
@@ -319,7 +319,7 @@ def test_dereference_invalid_node():
319319
"result": True
320320
}
321321
}
322-
with pytest.raises(ValueError, match="not in process graph"):
322+
with pytest.raises(ProcessGraphVisitException, match="not in process graph"):
323323
ProcessGraphVisitor.dereference_from_node_arguments(graph)
324324

325325

0 commit comments

Comments
 (0)