Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PyDiGraph.add_edge() and PyGraph.add_edge panic if an endpoint doesn't exist #855

Closed
mtreinish opened this issue Apr 4, 2023 · 0 comments · Fixed by #862
Closed

PyDiGraph.add_edge() and PyGraph.add_edge panic if an endpoint doesn't exist #855

mtreinish opened this issue Apr 4, 2023 · 0 comments · Fixed by #862
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@mtreinish
Copy link
Member

Information

  • rustworkx version: 0.12.1
  • Python version: 3.11
  • Rust version: 1.68.2
  • Operating system: Linux

What is the current behavior?

If you try to add an edge to a graph object with endpoints that aren't present in the graph petgraph panics and that causes an catchable exception to be raised from rustworkx without a user actionable message.
For example:

pyo3_runtime.PanicException: StableGraph::add_edge: node index 3 is not a node in the graph

What is the expected behavior?

I think it would be better to raise an IndexError or a custom rustworkx exception class. The issue is a PanicException isn't something users can catch easily (as it doesn't inherit from Exception) and is supposed to be treated as irrecoverable. Also the error message isn't something a python end user will understand. We should do checks that the indices are present in the graph before calling petgraph and return an appropriate error instead.

Steps to reproduce the problem

g = rx.PyDiGraph()
g.add_edge(2, 3)

or

g = rx.PyGraph()
g.add_edge(2, 3)
@mtreinish mtreinish added bug Something isn't working good first issue Good for newcomers labels Apr 4, 2023
@mergify mergify bot closed this as completed in #862 May 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant