@@ -13,6 +13,7 @@ use crate::helpers::emojis::*;
1313use crate :: helpers:: { self , get_workspace_root} ;
1414use crate :: sourcedirs;
1515use ahash:: AHashSet ;
16+ use anyhow:: { anyhow, Result } ;
1617use build_types:: * ;
1718use console:: style;
1819use indicatif:: { ProgressBar , ProgressStyle } ;
@@ -54,15 +55,19 @@ pub struct CompilerArgs {
5455 pub parser_args : Vec < String > ,
5556}
5657
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 > {
5863 let filename = & helpers:: get_abs_path ( path) ;
5964 let package_root = helpers:: get_abs_path (
6065 & helpers:: get_nearest_config ( & std:: path:: PathBuf :: from ( path) ) . expect ( "Couldn't find package root" ) ,
6166 ) ;
6267 let workspace_root = get_workspace_root ( & package_root) . map ( |p| helpers:: get_abs_path ( & p) ) ;
6368 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) ? ;
6671 let rescript_version = if let Some ( rescript_version) = rescript_version {
6772 rescript_version
6873 } else {
@@ -111,28 +116,13 @@ pub fn get_compiler_args(path: &str, rescript_version: Option<String>, bsc_path:
111116 & workspace_root,
112117 & None ,
113118 ) ;
114- serde_json:: to_string_pretty ( & CompilerArgs {
119+
120+ let result = serde_json:: to_string_pretty ( & CompilerArgs {
115121 compiler_args,
116122 parser_args,
117- } )
118- . unwrap ( )
119- }
123+ } ) ?;
120124
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)
136126}
137127
138128pub fn initialize_build (
@@ -141,14 +131,14 @@ pub fn initialize_build(
141131 show_progress : bool ,
142132 path : & str ,
143133 bsc_path : Option < String > ,
144- ) -> Result < BuildState , InitializeBuildError > {
134+ ) -> Result < BuildState > {
145135 let project_root = helpers:: get_abs_path ( path) ;
146136 let workspace_root = helpers:: get_workspace_root ( & project_root) ;
147137 let bsc_path = match bsc_path {
148138 Some ( bsc_path) => bsc_path,
149139 None => helpers:: get_bsc ( & project_root, workspace_root. to_owned ( ) ) ,
150140 } ;
151- let root_config_name = packages:: get_package_name ( & project_root) ;
141+ let root_config_name = packages:: get_package_name ( & project_root) ? ;
152142 let rescript_version = helpers:: get_rescript_version ( & bsc_path) ;
153143
154144 if show_progress {
@@ -157,7 +147,7 @@ pub fn initialize_build(
157147 }
158148
159149 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 ) ? ;
161151 let timing_package_tree_elapsed = timing_package_tree. elapsed ( ) ;
162152
163153 if show_progress {
@@ -173,7 +163,7 @@ pub fn initialize_build(
173163 }
174164
175165 if !packages:: validate_packages_dependencies ( & packages) {
176- return Err ( InitializeBuildError :: PackageDependencyValidation ) ;
166+ return Err ( anyhow ! ( "Failed to validate package dependencies" ) ) ;
177167 }
178168
179169 let timing_source_files = Instant :: now ( ) ;
@@ -435,27 +425,6 @@ pub fn incremental_build(
435425 }
436426}
437427
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-
459428// write build.ninja files in the packages after a non-incremental build
460429// this is necessary to bust the editor tooling cache. The editor tooling
461430// is watching this file.
@@ -477,15 +446,15 @@ pub fn build(
477446 no_timing : bool ,
478447 create_sourcedirs : bool ,
479448 bsc_path : Option < String > ,
480- ) -> Result < BuildState , BuildError > {
449+ ) -> Result < BuildState > {
481450 let default_timing: Option < std:: time:: Duration > = if no_timing {
482451 Some ( std:: time:: Duration :: new ( 0.0 as u64 , 0.0 as u32 ) )
483452 } else {
484453 None
485454 } ;
486455 let timing_total = Instant :: now ( ) ;
487456 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}" ) ) ?;
489458
490459 match incremental_build (
491460 & mut build_state,
@@ -512,7 +481,7 @@ pub fn build(
512481 Err ( e) => {
513482 clean:: cleanup_after_build ( & build_state) ;
514483 write_build_ninja ( & build_state) ;
515- Err ( BuildError :: IncrementalBuild ( e ) )
484+ Err ( anyhow ! ( "Incremental build failed. Error: {e}" ) )
516485 }
517486 }
518487}
0 commit comments