Skip to content

Commit 5a3721f

Browse files
committed
feat: improve file parsing error display
1 parent 348e914 commit 5a3721f

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

crates/vite_task_graph/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl vite_graph_ser::GetKey for TaskNode {
8888

8989
#[derive(Debug, thiserror::Error)]
9090
pub enum TaskGraphLoadError {
91-
#[error("Failed to load package graph: {0}")]
91+
#[error("Failed to load package graph")]
9292
PackageGraphLoadError(#[from] vite_workspace::Error),
9393

9494
#[error("Failed to load task config file for package at {package_path:?}")]

crates/vite_task_plan/src/context.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,14 @@ pub struct TaskCallStackDisplay {
6464
frames: Arc<[TaskCallStackFrameDisplay]>,
6565
}
6666

67+
impl TaskCallStackDisplay {
68+
pub fn is_empty(&self) -> bool {
69+
self.frames.is_empty()
70+
}
71+
}
72+
6773
impl Display for TaskCallStackDisplay {
6874
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
69-
if self.frames.is_empty() {
70-
write!(f, "<empty>")?;
71-
return Ok(());
72-
}
7375
for (i, frame) in self.frames.iter().enumerate() {
7476
if i > 0 {
7577
write!(f, " -> ")?;

crates/vite_task_plan/src/error.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,23 @@ pub enum TaskPlanErrorKind {
126126
}
127127

128128
#[derive(Debug, thiserror::Error)]
129-
#[error("Failed to plan execution, task call stack: {task_call_stack}")]
130129
pub struct Error {
131130
task_call_stack: TaskCallStackDisplay,
132131

133132
#[source]
134133
kind: TaskPlanErrorKind,
135134
}
136135

136+
impl Display for Error {
137+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
138+
write!(f, "Failed to plan execution")?;
139+
if !self.task_call_stack.is_empty() {
140+
write!(f, ", task call stack: {}", self.task_call_stack)?
141+
}
142+
Ok(())
143+
}
144+
}
145+
137146
impl TaskPlanErrorKind {
138147
pub fn with_empty_call_stack(self) -> Error {
139148
Error { task_call_stack: TaskCallStackDisplay::default(), kind: self }

0 commit comments

Comments
 (0)