33 reason = "Arc<Path> is used for non-UTF-8 path data in error types"
44) ]
55use std:: path:: Path ;
6- use std:: { env:: JoinPathsError , ffi:: OsStr , fmt :: Display , sync:: Arc } ;
6+ use std:: { env:: JoinPathsError , ffi:: OsStr , sync:: Arc } ;
77
88use vite_path:: { AbsolutePath , relative:: InvalidPathDataError } ;
99use vite_str:: Str ;
10+ use vite_task_graph:: display:: TaskDisplay ;
1011
11- use crate :: {
12- context:: { PlanContext , TaskCallStackDisplay , TaskRecursionError } ,
13- envs:: ResolveEnvError ,
14- } ;
12+ use crate :: { context:: TaskRecursionError , envs:: ResolveEnvError } ;
1513
1614#[ derive( Debug , thiserror:: Error ) ]
1715pub enum CdCommandError {
@@ -30,7 +28,7 @@ pub struct WhichError {
3028 #[ source]
3129 pub error : which:: Error ,
3230}
33- impl Display for WhichError {
31+ impl std :: fmt :: Display for WhichError {
3432 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
3533 write ! (
3634 f,
@@ -66,7 +64,7 @@ pub enum PathType {
6664 Program ,
6765 PackagePath ,
6866}
69- impl Display for PathType {
67+ impl std :: fmt :: Display for PathType {
7068 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
7169 match self {
7270 Self :: Cwd => write ! ( f, "current working directory" ) ,
@@ -84,18 +82,26 @@ pub struct PathFingerprintError {
8482 pub kind : PathFingerprintErrorKind ,
8583}
8684
87- /// Errors that can occur when planning a specific execution from a task .
85+ /// Errors that can occur when planning a specific execution from a task.
8886#[ derive( Debug , thiserror:: Error ) ]
89- pub enum TaskPlanErrorKind {
87+ pub enum Error {
88+ #[ error( "Failed to plan tasks from `{command}` in task {task_display}" ) ]
89+ NestPlan {
90+ task_display : TaskDisplay ,
91+ command : Str ,
92+ #[ source]
93+ error : Box < Self > ,
94+ } ,
95+
9096 #[ error( "Failed to load task graph" ) ]
91- TaskGraphLoadError (
97+ TaskGraphLoad (
9298 #[ source]
9399 #[ from]
94100 vite_task_graph:: TaskGraphLoadError ,
95101 ) ,
96102
97103 #[ error( "Failed to execute 'cd' command" ) ]
98- CdCommandError (
104+ CdCommand (
99105 #[ source]
100106 #[ from]
101107 CdCommandError ,
@@ -105,10 +111,10 @@ pub enum TaskPlanErrorKind {
105111 ProgramNotFound ( #[ from] WhichError ) ,
106112
107113 #[ error( transparent) ]
108- PathFingerprintError ( #[ from] PathFingerprintError ) ,
114+ PathFingerprint ( #[ from] PathFingerprintError ) ,
109115
110116 #[ error( "Failed to query tasks from task graph" ) ]
111- TaskQueryError (
117+ TaskQuery (
112118 #[ source]
113119 #[ from]
114120 vite_task_graph:: query:: TaskQueryError ,
@@ -118,7 +124,7 @@ pub enum TaskPlanErrorKind {
118124 TaskRecursionDetected ( #[ from] TaskRecursionError ) ,
119125
120126 #[ error( "Invalid vite task command: {program} with args {args:?} under cwd {cwd:?}" ) ]
121- ParsePlanRequestError {
127+ ParsePlanRequest {
122128 program : Str ,
123129 args : Arc < [ Str ] > ,
124130 cwd : Arc < AbsolutePath > ,
@@ -127,100 +133,38 @@ pub enum TaskPlanErrorKind {
127133 } ,
128134
129135 #[ error( "Failed to add node_modules/.bin to PATH environment variable" ) ]
130- AddNodeModulesBinPathError {
136+ AddNodeModulesBinPath {
131137 #[ source]
132138 join_paths_error : JoinPathsError ,
133139 } ,
134140
135141 #[ error( "Failed to resolve environment variables" ) ]
136- ResolveEnvError ( #[ source] ResolveEnvError ) ,
142+ ResolveEnv ( #[ source] ResolveEnvError ) ,
137143
138144 #[ error( "No task specifier provided for 'run' command" ) ]
139145 MissingTaskSpecifier ,
140146}
141147
142- #[ derive( Debug , thiserror:: Error ) ]
143- pub struct Error {
144- task_call_stack : TaskCallStackDisplay ,
145-
146- #[ source]
147- kind : TaskPlanErrorKind ,
148- }
149-
150- impl Display for Error {
151- fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
152- write ! ( f, "Failed to plan execution" ) ?;
153- if !self . task_call_stack . is_empty ( ) {
154- write ! ( f, ", task call stack: {}" , self . task_call_stack) ?;
155- }
156- Ok ( ( ) )
157- }
158- }
159-
160- impl TaskPlanErrorKind {
161- #[ must_use]
162- pub fn with_empty_call_stack ( self ) -> Error {
163- Error { task_call_stack : TaskCallStackDisplay :: default ( ) , kind : self }
164- }
165- }
166-
167148impl Error {
168149 #[ must_use]
169150 pub const fn is_missing_task_specifier ( & self ) -> bool {
170- matches ! ( self . kind , TaskPlanErrorKind :: MissingTaskSpecifier )
151+ matches ! ( self , Self :: MissingTaskSpecifier )
171152 }
172153
173154 /// If this error represents a top-level task-not-found lookup failure,
174155 /// returns the task name that the user typed.
175156 ///
176- /// Returns `None` if the error occurred in a nested task (non-empty call stack ),
157+ /// Returns `None` if the error occurred in a nested task (wrapped in `NestPlan` ),
177158 /// since nested task errors should propagate as-is rather than triggering
178159 /// interactive task selection.
179160 #[ must_use]
180161 pub fn task_not_found_name ( & self ) -> Option < & str > {
181- if !self . task_call_stack . is_empty ( ) {
182- return None ;
183- }
184- match & self . kind {
185- TaskPlanErrorKind :: TaskQueryError (
186- vite_task_graph:: query:: TaskQueryError :: SpecifierLookupError { specifier, .. } ,
187- ) => Some ( specifier. task_name . as_str ( ) ) ,
188- _ => None ,
189- }
190- }
191- }
192-
193- #[ expect(
194- clippy:: result_large_err,
195- reason = "Error wraps TaskPlanErrorKind with call stack for diagnostics"
196- ) ]
197- pub trait TaskPlanErrorKindResultExt {
198- type Ok ;
199- /// Attach the current task call stack from the planning context to the error.
200- fn with_plan_context ( self , context : & PlanContext < ' _ > ) -> Result < Self :: Ok , Error > ;
201-
202- /// Attach an empty task call stack to the error.
203- fn with_empty_call_stack ( self ) -> Result < Self :: Ok , Error > ;
204- }
205-
206- impl < T > TaskPlanErrorKindResultExt for Result < T , TaskPlanErrorKind > {
207- type Ok = T ;
208-
209- /// Attach the current task call stack from the planning context to the error.
210- fn with_plan_context ( self , context : & PlanContext < ' _ > ) -> Result < T , Error > {
211- match self {
212- Ok ( value) => Ok ( value) ,
213- Err ( kind) => {
214- let task_call_stack = context. display_call_stack ( ) ;
215- Err ( Error { task_call_stack, kind } )
216- }
217- }
218- }
219-
220- fn with_empty_call_stack ( self ) -> Result < T , Error > {
221162 match self {
222- Ok ( value) => Ok ( value) ,
223- Err ( kind) => Err ( kind. with_empty_call_stack ( ) ) ,
163+ Self :: TaskQuery ( vite_task_graph:: query:: TaskQueryError :: SpecifierLookupError {
164+ specifier,
165+ ..
166+ } ) => Some ( specifier. task_name . as_str ( ) ) ,
167+ _ => None ,
224168 }
225169 }
226170}
0 commit comments