Skip to content

Commit 0fb47d2

Browse files
committed
refactor: detect empty plan instead of erroring in query_tasks when no tasks match
1 parent f437b0a commit 0fb47d2

4 files changed

Lines changed: 21 additions & 20 deletions

File tree

crates/vite_task/src/session/mod.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,22 @@ impl<'a> Session<'a> {
232232
let is_interactive =
233233
std::io::stdin().is_terminal() && std::io::stdout().is_terminal();
234234

235-
// Copy flags before consuming run_command
235+
// Save task name and flags before consuming run_command
236+
let task_name = run_command.task_specifier.as_ref().map(|s| s.task_name.clone());
236237
let flags = run_command.flags;
237238
let additional_args = run_command.additional_args.clone();
238239

239240
match self.plan_from_cli(cwd, run_command).await {
241+
Ok(plan) if plan.is_empty() => {
242+
// No tasks matched the query — show task selector / "did you mean"
243+
self.handle_no_task(
244+
is_interactive,
245+
task_name.as_deref(),
246+
flags,
247+
additional_args,
248+
)
249+
.await
250+
}
240251
Ok(plan) => {
241252
let reporter =
242253
LabeledReporter::new(std::io::stdout(), self.workspace_path());

crates/vite_task_graph/src/query/mod.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ pub enum TaskQueryError {
6161
#[source]
6262
lookup_error: SpecifierLookupError<PackageUnknownError>,
6363
},
64-
65-
#[error("No packages have a task named '{task_name}'")]
66-
RecursiveTaskNotFound { task_name: Str },
6764
}
6865

6966
impl IndexedTaskGraph {
@@ -138,24 +135,11 @@ impl IndexedTaskGraph {
138135
}
139136
TaskQueryKind::Recursive { task_names } => {
140137
// Add all tasks matching the names across all packages
141-
let mut matched_names = FxHashSet::<&str>::with_capacity_and_hasher(
142-
task_names.len(),
143-
rustc_hash::FxBuildHasher,
144-
);
145138
for task_index in self.task_graph.node_indices() {
146139
let current_task_name =
147140
self.task_graph[task_index].task_display.task_name.as_str();
148141
if task_names.contains(current_task_name) {
149142
execution_graph.add_node(task_index);
150-
matched_names.insert(current_task_name);
151-
}
152-
}
153-
// Return an error if any requested task name was not found in any package
154-
for task_name in &task_names {
155-
if !matched_names.contains(task_name.as_str()) {
156-
return Err(TaskQueryError::RecursiveTaskNotFound {
157-
task_name: task_name.clone(),
158-
});
159143
}
160144
}
161145
}

crates/vite_task_plan/src/error.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,6 @@ impl Error {
185185
TaskPlanErrorKind::TaskQueryError(
186186
vite_task_graph::query::TaskQueryError::SpecifierLookupError { specifier, .. },
187187
) => Some(specifier.task_name.as_str()),
188-
TaskPlanErrorKind::TaskQueryError(
189-
vite_task_graph::query::TaskQueryError::RecursiveTaskNotFound { task_name },
190-
) => Some(task_name.as_str()),
191188
_ => None,
192189
}
193190
}

crates/vite_task_plan/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,15 @@ impl ExecutionPlan {
192192
&self.root_node
193193
}
194194

195+
/// Returns `true` if the plan contains no tasks to execute.
196+
#[must_use]
197+
pub fn is_empty(&self) -> bool {
198+
match &self.root_node {
199+
ExecutionItemKind::Expanded(graph) => graph.node_count() == 0,
200+
ExecutionItemKind::Leaf(_) => false,
201+
}
202+
}
203+
195204
/// Plan an execution from a plan request.
196205
///
197206
/// # Errors

0 commit comments

Comments
 (0)