Skip to content

Commit cd6aa79

Browse files
committed
fix: replace impossible fallbacks with expect/unreachable
1 parent 0392c28 commit cd6aa79

File tree

2 files changed

+14
-17
lines changed
  • crates

2 files changed

+14
-17
lines changed

crates/vite_task/src/session/reporter/mod.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,12 @@ impl LeafExecutionPath {
153153
current_graph = nested_graph;
154154
}
155155
ExecutionItemKind::Leaf(_) => {
156-
// A Leaf in the middle of the path is a bug in path construction.
157-
// This should never happen if the execution engine builds paths correctly.
158-
debug_assert!(
159-
false,
160-
"LeafExecutionPath: intermediate element is a Leaf, expected Expanded"
161-
);
162-
return None;
156+
// A Leaf in the middle of the path means the execution engine
157+
// pushed a Leaf node as an intermediate step, which is a bug —
158+
// only Expanded items can contain nested graphs to descend into.
159+
unreachable!(
160+
"LeafExecutionPath: intermediate element at depth {depth} is a Leaf, expected Expanded"
161+
)
163162
}
164163
}
165164
}

crates/vite_task_plan/src/plan.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -548,21 +548,19 @@ pub async fn plan_query_request(
548548
// it returns `CycleError` identifying one node in the cycle.
549549
ExecutionGraph::try_from_graph(inner_graph).map_err(|cycle| {
550550
// Look up the human-readable task display for the node involved in the cycle.
551-
let task_display =
552-
execution_node_indices_by_task_index.iter().find_map(|(task_idx, &exec_idx)| {
551+
// Every node in `inner_graph` was added via `inner_graph.add_node()` above,
552+
// with a corresponding entry inserted into `execution_node_indices_by_task_index`.
553+
// The cycle error's node_id comes from the same graph, so the lookup always succeeds.
554+
let display = execution_node_indices_by_task_index
555+
.iter()
556+
.find_map(|(task_idx, &exec_idx)| {
553557
if exec_idx == cycle.node_id() {
554558
Some(context.indexed_task_graph().display_task(*task_idx))
555559
} else {
556560
None
557561
}
558-
});
559-
// If for some reason the node wasn't found in our map (shouldn't happen),
560-
// fall back to a placeholder display.
561-
let display = task_display.unwrap_or_else(|| vite_task_graph::display::TaskDisplay {
562-
package_name: "unknown".into(),
563-
task_name: "unknown".into(),
564-
package_path: Arc::clone(context.workspace_path()),
565-
});
562+
})
563+
.expect("cycle node must exist in execution_node_indices_by_task_index");
566564
Error::CycleDependencyDetected(display)
567565
})
568566
}

0 commit comments

Comments
 (0)