@@ -1200,19 +1200,19 @@ impl Config {
12001200 }
12011201
12021202 #[ cfg( test) ]
1203- fn get_toml ( _: & Path ) -> TomlConfig {
1204- TomlConfig :: default ( )
1203+ fn get_toml ( _: & Path ) -> Result < TomlConfig , toml :: de :: Error > {
1204+ Ok ( TomlConfig :: default ( ) )
12051205 }
12061206
12071207 #[ cfg( not( test) ) ]
1208- fn get_toml ( file : & Path ) -> TomlConfig {
1208+ fn get_toml ( file : & Path ) -> Result < TomlConfig , toml :: de :: Error > {
12091209 let contents =
12101210 t ! ( fs:: read_to_string( file) , format!( "config file {} not found" , file. display( ) ) ) ;
12111211 // Deserialize to Value and then TomlConfig to prevent the Deserialize impl of
12121212 // TomlConfig and sub types to be monomorphized 5x by toml.
12131213 toml:: from_str ( & contents)
12141214 . and_then ( |table : toml:: Value | TomlConfig :: deserialize ( table) )
1215- . unwrap_or_else ( |err | {
1215+ . inspect_err ( |_ | {
12161216 if let Ok ( Some ( changes) ) = toml:: from_str ( & contents)
12171217 . and_then ( |table : toml:: Value | ChangeIdWrapper :: deserialize ( table) )
12181218 . map ( |change_id| change_id. inner . map ( crate :: find_recent_config_change_ids) )
@@ -1224,17 +1224,17 @@ impl Config {
12241224 ) ;
12251225 }
12261226 }
1227-
1228- eprintln ! ( "failed to parse TOML configuration '{}': {err}" , file. display( ) ) ;
1229- exit ! ( 2 ) ;
12301227 } )
12311228 }
12321229
12331230 pub fn parse ( flags : Flags ) -> Config {
12341231 Self :: parse_inner ( flags, Self :: get_toml)
12351232 }
12361233
1237- pub ( crate ) fn parse_inner ( mut flags : Flags , get_toml : impl Fn ( & Path ) -> TomlConfig ) -> Config {
1234+ pub ( crate ) fn parse_inner (
1235+ mut flags : Flags ,
1236+ get_toml : impl Fn ( & Path ) -> Result < TomlConfig , toml:: de:: Error > ,
1237+ ) -> Config {
12381238 let mut config = Config :: default_opts ( ) ;
12391239
12401240 // Set flags.
@@ -1342,7 +1342,10 @@ impl Config {
13421342 } else {
13431343 toml_path. clone ( )
13441344 } ) ;
1345- get_toml ( & toml_path)
1345+ get_toml ( & toml_path) . unwrap_or_else ( |e| {
1346+ eprintln ! ( "ERROR: Failed to parse '{}': {e}" , toml_path. display( ) ) ;
1347+ exit ! ( 2 ) ;
1348+ } )
13461349 } else {
13471350 config. config = None ;
13481351 TomlConfig :: default ( )
@@ -1373,7 +1376,13 @@ impl Config {
13731376 include_path. push ( "bootstrap" ) ;
13741377 include_path. push ( "defaults" ) ;
13751378 include_path. push ( format ! ( "config.{include}.toml" ) ) ;
1376- let included_toml = get_toml ( & include_path) ;
1379+ let included_toml = get_toml ( & include_path) . unwrap_or_else ( |e| {
1380+ eprintln ! (
1381+ "ERROR: Failed to parse default config profile at '{}': {e}" ,
1382+ include_path. display( )
1383+ ) ;
1384+ exit ! ( 2 ) ;
1385+ } ) ;
13771386 toml. merge ( included_toml, ReplaceOpt :: IgnoreDuplicate ) ;
13781387 }
13791388
@@ -2331,8 +2340,21 @@ impl Config {
23312340 if let Some ( config_path) = & self . config {
23322341 let builder_config_path =
23332342 self . out . join ( self . build . triple ) . join ( "ci-rustc" ) . join ( BUILDER_CONFIG_FILENAME ) ;
2334- let ci_config_toml = Self :: get_toml ( & builder_config_path) ;
2335- let current_config_toml = Self :: get_toml ( config_path) ;
2343+
2344+ let ci_config_toml = match Self :: get_toml ( & builder_config_path) {
2345+ Ok ( ci_config_toml) => ci_config_toml,
2346+ Err ( e) if e. to_string ( ) . contains ( "unknown field" ) => {
2347+ println ! ( "WARNING: CI rustc has some fields that are no longer supported in bootstrap; download-rustc will be disabled." ) ;
2348+ println ! ( "HELP: Consider rebasing to a newer commit if available." ) ;
2349+ return None ;
2350+ } ,
2351+ Err ( e) => {
2352+ eprintln ! ( "ERROR: Failed to parse CI rustc config at '{}': {e}" , builder_config_path. display( ) ) ;
2353+ exit ! ( 2 ) ;
2354+ } ,
2355+ } ;
2356+
2357+ let current_config_toml = Self :: get_toml ( config_path) . unwrap ( ) ;
23362358
23372359 // Check the config compatibility
23382360 // FIXME: this doesn't cover `--set` flags yet.
0 commit comments