graphkit icon indicating copy to clipboard operation
graphkit copied to clipboard

Improve error message when the graph contains cyclic dependencies

Open JeremyIV opened this issue 4 years ago • 5 comments

Creates a more helpful exception when trying to compose a graph with cyclic dependencies.

Example message: (helpful part at the bottom)

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'op3' is not defined
>>> graph = compose(name="graph")(op1, op2, op4)
Traceback (most recent call last):
  File "/home/jeremyiv/Documents/graphkit-1/graphkit/network.py", line 119, in compile
    ordered_nodes = list(nx.dag.topological_sort(self.graph))
  File "/home/jeremyiv/anaconda3/lib/python3.8/site-packages/networkx/algorithms/dag.py", line 210, in topological_sort
    raise nx.NetworkXUnfeasible("Graph contains a cycle or graph changed "
networkx.exception.NetworkXUnfeasible: Graph contains a cycle or graph changed during iteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/jeremyiv/Documents/graphkit-1/graphkit/functional.py", line 209, in __call__
    net.compile()
  File "/home/jeremyiv/Documents/graphkit-1/graphkit/network.py", line 126, in compile
    raise Exception(f"Cyclic dependency in graph:\n{_format_cycle(cycle)}")
Exception: Cyclic dependency in graph:
op1 needs "a" from op4.
op4 needs "c" from op1.

I confirm that this contribution is made under the terms of the license found in the root directory of this repository's source tree and that I have the authority necessary to make this contribution on behalf of its copyright owner.

JeremyIV avatar Jun 10 '21 02:06 JeremyIV

Great!

I would raise the same exception type `networkx.exception.NetworkXUnfeasible.

ankostis avatar Jun 10 '21 05:06 ankostis

Ok, made the change. It throws the same NetworkXUnfeasible exception now.

JeremyIV avatar Jun 15 '21 22:06 JeremyIV

Just to be lcear, have no saying i this project.

ankostis avatar Jun 17 '21 15:06 ankostis

Ah... Is this project maintained anymore? Are there better maintained alternatives?

JeremyIV avatar Jun 17 '21 20:06 JeremyIV

I submitted a lot of fixes and enhancements in #22 (and other issues) a couple of years ago, that were not addressed. Eentually i forked it into https://graphtik.readthedocs.io/.

ankostis avatar Jun 19 '21 17:06 ankostis