Skip to content

Commit 4c671c0

Browse files
eumiroIvanIsCoding
andauthored
Add docstrings to exceptions and sort their list alphabetically (#1422)
Co-authored-by: Ivan Carvalho <[email protected]>
1 parent ee5e2ce commit 4c671c0

File tree

2 files changed

+90
-34
lines changed

2 files changed

+90
-34
lines changed

docs/source/api/exceptions.rst

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@ Exceptions
44
.. autosummary::
55
:toctree: ../apiref
66

7-
rustworkx.InvalidNode
8-
rustworkx.DAGWouldCycle
9-
rustworkx.NoEdgeBetweenNodes
107
rustworkx.DAGHasCycle
8+
rustworkx.DAGWouldCycle
9+
rustworkx.FailedToConverge
10+
rustworkx.GraphNotBipartite
11+
rustworkx.InvalidMapping
12+
rustworkx.InvalidNode
13+
rustworkx.JSONDeserializationError
14+
rustworkx.JSONSerializationError
1115
rustworkx.NegativeCycle
12-
rustworkx.NoSuitableNeighbors
16+
rustworkx.NoEdgeBetweenNodes
1317
rustworkx.NoPathFound
18+
rustworkx.NoSuitableNeighbors
1419
rustworkx.NullGraph
15-
rustworkx.visit.StopSearch
1620
rustworkx.visit.PruneSearch
17-
rustworkx.JSONSerializationError
18-
rustworkx.InvalidMapping
19-
rustworkx.GraphNotBipartite
21+
rustworkx.visit.StopSearch

src/lib.rs

Lines changed: 80 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -371,36 +371,90 @@ fn find_node_by_weight<Ty: EdgeType>(
371371
Ok(index)
372372
}
373373

374-
// The provided node is invalid.
375-
create_exception!(rustworkx, InvalidNode, PyException);
376-
// Performing this operation would result in trying to add a cycle to a DAG.
377-
create_exception!(rustworkx, DAGWouldCycle, PyException);
378-
// There is no edge present between the provided nodes.
379-
create_exception!(rustworkx, NoEdgeBetweenNodes, PyException);
380-
// The specified Directed Graph has a cycle and can't be treated as a DAG.
381-
create_exception!(rustworkx, DAGHasCycle, PyException);
382-
// No neighbors found matching the provided predicate.
383-
create_exception!(rustworkx, NoSuitableNeighbors, PyException);
384-
// Invalid operation on a null graph
385-
create_exception!(rustworkx, NullGraph, PyException);
386-
// No path was found between the specified nodes.
387-
create_exception!(rustworkx, NoPathFound, PyException);
388-
// No mapping was found for the request swapping
389-
create_exception!(rustworkx, InvalidMapping, PyException);
374+
create_exception!(
375+
rustworkx,
376+
InvalidNode,
377+
PyException,
378+
"The provided node is invalid."
379+
);
380+
create_exception!(
381+
rustworkx,
382+
DAGWouldCycle,
383+
PyException,
384+
"Performing this operation would result in trying to add a cycle to a DAG."
385+
);
386+
create_exception!(
387+
rustworkx,
388+
NoEdgeBetweenNodes,
389+
PyException,
390+
"There is no edge present between the provided nodes."
391+
);
392+
create_exception!(
393+
rustworkx,
394+
DAGHasCycle,
395+
PyException,
396+
"The specified Directed Graph has a cycle and can't be treated as a DAG."
397+
);
398+
create_exception!(
399+
rustworkx,
400+
NoSuitableNeighbors,
401+
PyException,
402+
"No neighbors found matching the provided predicate."
403+
);
404+
create_exception!(
405+
rustworkx,
406+
NullGraph,
407+
PyException,
408+
"Invalid operation on a null graph"
409+
);
410+
create_exception!(
411+
rustworkx,
412+
NoPathFound,
413+
PyException,
414+
"No path was found between the specified nodes."
415+
);
416+
create_exception!(
417+
rustworkx,
418+
InvalidMapping,
419+
PyException,
420+
"No mapping was found for the request swapping"
421+
);
422+
390423
// Prune part of the search tree while traversing a graph.
391424
import_exception!(rustworkx.visit, PruneSearch);
392425
// Stop graph traversal.
393426
import_exception!(rustworkx.visit, StopSearch);
394-
// JSON Error
395-
create_exception!(rustworkx, JSONSerializationError, PyException);
396-
// JSON Error
397-
create_exception!(rustworkx, JSONDeserializationError, PyException);
398-
// Negative Cycle found on shortest-path algorithm
399-
create_exception!(rustworkx, NegativeCycle, PyException);
400-
// Failed to Converge on a solution
401-
create_exception!(rustworkx, FailedToConverge, PyException);
402-
// Graph is not bipartite
403-
create_exception!(rustworkx, GraphNotBipartite, PyException);
427+
428+
create_exception!(
429+
rustworkx,
430+
JSONSerializationError,
431+
PyException,
432+
"JSON Serialization Error"
433+
);
434+
create_exception!(
435+
rustworkx,
436+
JSONDeserializationError,
437+
PyException,
438+
"JSON Deserialization Error"
439+
);
440+
create_exception!(
441+
rustworkx,
442+
NegativeCycle,
443+
PyException,
444+
"Negative Cycle found on shortest-path algorithm"
445+
);
446+
create_exception!(
447+
rustworkx,
448+
FailedToConverge,
449+
PyException,
450+
"Failed to Converge on a solution"
451+
);
452+
create_exception!(
453+
rustworkx,
454+
GraphNotBipartite,
455+
PyException,
456+
"Graph is not bipartite"
457+
);
404458

405459
#[pymodule]
406460
fn rustworkx(py: Python<'_>, m: &Bound<PyModule>) -> PyResult<()> {

0 commit comments

Comments
 (0)