Skip to content

Commit 1fe1a1b

Browse files
committed
error checking
1 parent c2ea0c4 commit 1fe1a1b

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

src/dfx/src/lib/models/canister.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -551,8 +551,22 @@ impl CanisterPool {
551551
id_set.insert(canister_id, graph.add_node(canister_id));
552552
}
553553

554+
// Verify the graph has no cycles.
555+
if let Err(err) = petgraph::algo::toposort(&graph, None) {
556+
let message = match graph.node_weight(err.node_id()) {
557+
Some(canister_id) => match self.get_canister_info(canister_id) {
558+
Some(info) => info.get_name().to_string(),
559+
None => format!("<{}>", canister_id.to_text()),
560+
},
561+
None => "<Unknown>".to_string(),
562+
};
563+
return Err(DfxError::new(BuildError::DependencyError(format!(
564+
"Found circular dependency: {}",
565+
message
566+
))))
567+
}
568+
554569
// Traverse the graph of dependencies starting from `real_canisters_to_build` set.
555-
// FIXME: This hangs if circular dependencies (see below).
556570
let mut current_canisters_to_build =
557571
HashMap::from_iter(real_canisters_to_build.iter().map(|c| (c.canister_id(), ())));
558572
loop {
@@ -579,22 +593,7 @@ impl CanisterPool {
579593
current_canisters_to_build = current_canisters_to_build2;
580594
}
581595

582-
// Verify the graph has no cycles.
583-
if let Err(err) = petgraph::algo::toposort(&graph, None) {
584-
let message = match graph.node_weight(err.node_id()) {
585-
Some(canister_id) => match self.get_canister_info(canister_id) {
586-
Some(info) => info.get_name().to_string(),
587-
None => format!("<{}>", canister_id.to_text()),
588-
},
589-
None => "<Unknown>".to_string(),
590-
};
591-
Err(DfxError::new(BuildError::DependencyError(format!(
592-
"Found circular dependency: {}",
593-
message
594-
))))
595-
} else {
596-
Ok(graph)
597-
}
596+
Ok(graph)
598597
}
599598

600599
#[context("Failed step_prebuild_all.")]

0 commit comments

Comments
 (0)