@@ -13,6 +13,7 @@ use crate::helpers::emojis::*;
13
13
use crate :: helpers:: { self , get_workspace_root} ;
14
14
use crate :: sourcedirs;
15
15
use ahash:: AHashSet ;
16
+ use anyhow:: { anyhow, Result } ;
16
17
use build_types:: * ;
17
18
use console:: style;
18
19
use indicatif:: { ProgressBar , ProgressStyle } ;
@@ -54,15 +55,19 @@ pub struct CompilerArgs {
54
55
pub parser_args : Vec < String > ,
55
56
}
56
57
57
- pub fn get_compiler_args ( path : & str , rescript_version : Option < String > , bsc_path : Option < String > ) -> String {
58
+ pub fn get_compiler_args (
59
+ path : & str ,
60
+ rescript_version : Option < String > ,
61
+ bsc_path : Option < String > ,
62
+ ) -> Result < String > {
58
63
let filename = & helpers:: get_abs_path ( path) ;
59
64
let package_root = helpers:: get_abs_path (
60
65
& helpers:: get_nearest_config ( & std:: path:: PathBuf :: from ( path) ) . expect ( "Couldn't find package root" ) ,
61
66
) ;
62
67
let workspace_root = get_workspace_root ( & package_root) . map ( |p| helpers:: get_abs_path ( & p) ) ;
63
68
let root_rescript_config =
64
- packages:: read_config ( & workspace_root. to_owned ( ) . unwrap_or ( package_root. to_owned ( ) ) ) ;
65
- let rescript_config = packages:: read_config ( & package_root) ;
69
+ packages:: read_config ( & workspace_root. to_owned ( ) . unwrap_or ( package_root. to_owned ( ) ) ) ? ;
70
+ let rescript_config = packages:: read_config ( & package_root) ? ;
66
71
let rescript_version = if let Some ( rescript_version) = rescript_version {
67
72
rescript_version
68
73
} else {
@@ -111,28 +116,13 @@ pub fn get_compiler_args(path: &str, rescript_version: Option<String>, bsc_path:
111
116
& workspace_root,
112
117
& None ,
113
118
) ;
114
- serde_json:: to_string_pretty ( & CompilerArgs {
119
+
120
+ let result = serde_json:: to_string_pretty ( & CompilerArgs {
115
121
compiler_args,
116
122
parser_args,
117
- } )
118
- . unwrap ( )
119
- }
123
+ } ) ?;
120
124
121
- #[ derive( Debug , Clone ) ]
122
- pub enum InitializeBuildError {
123
- PackageDependencyValidation ,
124
- }
125
-
126
- impl fmt:: Display for InitializeBuildError {
127
- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
128
- match self {
129
- Self :: PackageDependencyValidation => write ! (
130
- f,
131
- "{} {}Could not Validate Package Dependencies" ,
132
- LINE_CLEAR , CROSS ,
133
- ) ,
134
- }
135
- }
125
+ Ok ( result)
136
126
}
137
127
138
128
pub fn initialize_build (
@@ -141,14 +131,14 @@ pub fn initialize_build(
141
131
show_progress : bool ,
142
132
path : & str ,
143
133
bsc_path : Option < String > ,
144
- ) -> Result < BuildState , InitializeBuildError > {
134
+ ) -> Result < BuildState > {
145
135
let project_root = helpers:: get_abs_path ( path) ;
146
136
let workspace_root = helpers:: get_workspace_root ( & project_root) ;
147
137
let bsc_path = match bsc_path {
148
138
Some ( bsc_path) => bsc_path,
149
139
None => helpers:: get_bsc ( & project_root, workspace_root. to_owned ( ) ) ,
150
140
} ;
151
- let root_config_name = packages:: get_package_name ( & project_root) ;
141
+ let root_config_name = packages:: get_package_name ( & project_root) ? ;
152
142
let rescript_version = helpers:: get_rescript_version ( & bsc_path) ;
153
143
154
144
if show_progress {
@@ -157,7 +147,7 @@ pub fn initialize_build(
157
147
}
158
148
159
149
let timing_package_tree = Instant :: now ( ) ;
160
- let packages = packages:: make ( filter, & project_root, & workspace_root) ;
150
+ let packages = packages:: make ( filter, & project_root, & workspace_root, show_progress ) ? ;
161
151
let timing_package_tree_elapsed = timing_package_tree. elapsed ( ) ;
162
152
163
153
if show_progress {
@@ -173,7 +163,7 @@ pub fn initialize_build(
173
163
}
174
164
175
165
if !packages:: validate_packages_dependencies ( & packages) {
176
- return Err ( InitializeBuildError :: PackageDependencyValidation ) ;
166
+ return Err ( anyhow ! ( "Failed to validate package dependencies" ) ) ;
177
167
}
178
168
179
169
let timing_source_files = Instant :: now ( ) ;
@@ -435,27 +425,6 @@ pub fn incremental_build(
435
425
}
436
426
}
437
427
438
- #[ derive( Debug , Clone ) ]
439
- pub enum BuildError {
440
- InitializeBuild ( InitializeBuildError ) ,
441
- IncrementalBuild ( IncrementalBuildError ) ,
442
- }
443
-
444
- impl fmt:: Display for BuildError {
445
- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
446
- match self {
447
- Self :: InitializeBuild ( e) => {
448
- write ! ( f, "{} {}Error Initializing Build: {}" , LINE_CLEAR , CROSS , e)
449
- }
450
- Self :: IncrementalBuild ( e) => write ! (
451
- f,
452
- "{} {}Error Running Incremental Build: {}" ,
453
- LINE_CLEAR , CROSS , e
454
- ) ,
455
- }
456
- }
457
- }
458
-
459
428
// write build.ninja files in the packages after a non-incremental build
460
429
// this is necessary to bust the editor tooling cache. The editor tooling
461
430
// is watching this file.
@@ -477,15 +446,15 @@ pub fn build(
477
446
no_timing : bool ,
478
447
create_sourcedirs : bool ,
479
448
bsc_path : Option < String > ,
480
- ) -> Result < BuildState , BuildError > {
449
+ ) -> Result < BuildState > {
481
450
let default_timing: Option < std:: time:: Duration > = if no_timing {
482
451
Some ( std:: time:: Duration :: new ( 0.0 as u64 , 0.0 as u32 ) )
483
452
} else {
484
453
None
485
454
} ;
486
455
let timing_total = Instant :: now ( ) ;
487
456
let mut build_state = initialize_build ( default_timing, filter, show_progress, path, bsc_path)
488
- . map_err ( BuildError :: InitializeBuild ) ?;
457
+ . map_err ( |e| anyhow ! ( "Could not initialize build. Error: {e}" ) ) ?;
489
458
490
459
match incremental_build (
491
460
& mut build_state,
@@ -512,7 +481,7 @@ pub fn build(
512
481
Err ( e) => {
513
482
clean:: cleanup_after_build ( & build_state) ;
514
483
write_build_ninja ( & build_state) ;
515
- Err ( BuildError :: IncrementalBuild ( e ) )
484
+ Err ( anyhow ! ( "Incremental build failed. Error: {e}" ) )
516
485
}
517
486
}
518
487
}
0 commit comments