Skip to content

Commit

Permalink
Fix DagHasCycle error to match previous type
Browse files Browse the repository at this point in the history
  • Loading branch information
ElePT committed May 29, 2024
1 parent 22821fd commit b77b269
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions rustworkx-core/src/dag_algo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ where
/// Define custom error classes for collect_bicolor_runs
#[derive(Debug)]
pub enum CollectBicolorError<E: Error> {
DAGWouldCycle,
DAGHasCycle,
CallableError(E)
}

Expand All @@ -328,14 +328,14 @@ impl<E: Error> Error for CollectBicolorError<E> {}
impl<E: Error> Display for CollectBicolorError<E> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
CollectBicolorError::DAGWouldCycle => fmt_dag_would_cycle(f),
CollectBicolorError::DAGHasCycle => fmt_dag_has_cycle(f),
CollectBicolorError::CallableError(ref e) => fmt_callable_error(f, e),
}
}
}

fn fmt_dag_would_cycle(f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "The operation would introduce a cycle.")
fn fmt_dag_has_cycle(f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "Sort encountered a cycle")
}

fn fmt_callable_error<E: Error>(f: &mut Formatter<'_>, inner: &E) -> std::fmt::Result {
Expand Down Expand Up @@ -400,7 +400,7 @@ where

let nodes = match algo::toposort(&graph, None) {
Ok(nodes) => nodes,
Err(_err) => return Err(CollectBicolorError::DAGWouldCycle),
Err(_err) => return Err(CollectBicolorError::DAGHasCycle),
};

// Utility for ensuring pending_list has the color index
Expand Down
2 changes: 1 addition & 1 deletion src/dag_algo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ fn convert_error(err: CollectBicolorError<PyErr>) -> PyErr {
// because nor PyErr nor CollectBicolorError are defined in this crate,
// so we use .map_err(convert_error) to convert a CollectBicolorError to PyErr instead.
match err {
CollectBicolorError::DAGWouldCycle => PyErr::new::<PyValueError, _>("DAG would cycle"),
CollectBicolorError::DAGHasCycle => PyErr::new::<DAGHasCycle, _>("Sort encountered a cycle"),
CollectBicolorError::CallableError(err) => err,
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/digraph/test_collect_bicolor_runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class TestCollectBicolorRuns(unittest.TestCase):
def test_cycle(self):
dag = rustworkx.PyDiGraph()
dag.extend_from_edge_list([(0, 1), (1, 2), (2, 0)])
with self.assertRaises(ValueError):
with self.assertRaises(rustworkx.DAGHasCycle):
rustworkx.collect_bicolor_runs(dag, lambda _: True, lambda _: None)

def test_filter_function_inner_exception(self):
Expand Down

0 comments on commit b77b269

Please sign in to comment.