@@ -1212,19 +1212,19 @@ impl Config {
1212
1212
}
1213
1213
1214
1214
#[ cfg( test) ]
1215
- fn get_toml ( _: & Path ) -> TomlConfig {
1216
- TomlConfig :: default ( )
1215
+ fn get_toml ( _: & Path ) -> Result < TomlConfig , toml :: de :: Error > {
1216
+ Ok ( TomlConfig :: default ( ) )
1217
1217
}
1218
1218
1219
1219
#[ cfg( not( test) ) ]
1220
- fn get_toml ( file : & Path ) -> TomlConfig {
1220
+ fn get_toml ( file : & Path ) -> Result < TomlConfig , toml :: de :: Error > {
1221
1221
let contents =
1222
1222
t ! ( fs:: read_to_string( file) , format!( "config file {} not found" , file. display( ) ) ) ;
1223
1223
// Deserialize to Value and then TomlConfig to prevent the Deserialize impl of
1224
1224
// TomlConfig and sub types to be monomorphized 5x by toml.
1225
1225
toml:: from_str ( & contents)
1226
1226
. and_then ( |table : toml:: Value | TomlConfig :: deserialize ( table) )
1227
- . unwrap_or_else ( |err | {
1227
+ . inspect_err ( |_ | {
1228
1228
if let Ok ( Some ( changes) ) = toml:: from_str ( & contents)
1229
1229
. and_then ( |table : toml:: Value | ChangeIdWrapper :: deserialize ( table) )
1230
1230
. map ( |change_id| change_id. inner . map ( crate :: find_recent_config_change_ids) )
@@ -1236,17 +1236,17 @@ impl Config {
1236
1236
) ;
1237
1237
}
1238
1238
}
1239
-
1240
- eprintln ! ( "failed to parse TOML configuration '{}': {err}" , file. display( ) ) ;
1241
- exit ! ( 2 ) ;
1242
1239
} )
1243
1240
}
1244
1241
1245
1242
pub fn parse ( flags : Flags ) -> Config {
1246
1243
Self :: parse_inner ( flags, Self :: get_toml)
1247
1244
}
1248
1245
1249
- pub ( crate ) fn parse_inner ( mut flags : Flags , get_toml : impl Fn ( & Path ) -> TomlConfig ) -> Config {
1246
+ pub ( crate ) fn parse_inner (
1247
+ mut flags : Flags ,
1248
+ get_toml : impl Fn ( & Path ) -> Result < TomlConfig , toml:: de:: Error > ,
1249
+ ) -> Config {
1250
1250
let mut config = Config :: default_opts ( ) ;
1251
1251
1252
1252
// Set flags.
@@ -1354,7 +1354,10 @@ impl Config {
1354
1354
} else {
1355
1355
toml_path. clone ( )
1356
1356
} ) ;
1357
- get_toml ( & toml_path)
1357
+ get_toml ( & toml_path) . unwrap_or_else ( |e| {
1358
+ eprintln ! ( "ERROR: Failed to parse '{}': {e}" , toml_path. display( ) ) ;
1359
+ exit ! ( 2 ) ;
1360
+ } )
1358
1361
} else {
1359
1362
config. config = None ;
1360
1363
TomlConfig :: default ( )
@@ -1385,7 +1388,13 @@ impl Config {
1385
1388
include_path. push ( "bootstrap" ) ;
1386
1389
include_path. push ( "defaults" ) ;
1387
1390
include_path. push ( format ! ( "config.{include}.toml" ) ) ;
1388
- let included_toml = get_toml ( & include_path) ;
1391
+ let included_toml = get_toml ( & include_path) . unwrap_or_else ( |e| {
1392
+ eprintln ! (
1393
+ "ERROR: Failed to parse default config profile at '{}': {e}" ,
1394
+ include_path. display( )
1395
+ ) ;
1396
+ exit ! ( 2 ) ;
1397
+ } ) ;
1389
1398
toml. merge ( included_toml, ReplaceOpt :: IgnoreDuplicate ) ;
1390
1399
}
1391
1400
@@ -2343,8 +2352,21 @@ impl Config {
2343
2352
if let Some ( config_path) = & self . config {
2344
2353
let builder_config_path =
2345
2354
self . out . join ( self . build . triple ) . join ( "ci-rustc" ) . join ( BUILDER_CONFIG_FILENAME ) ;
2346
- let ci_config_toml = Self :: get_toml ( & builder_config_path) ;
2347
- let current_config_toml = Self :: get_toml ( config_path) ;
2355
+
2356
+ let ci_config_toml = match Self :: get_toml ( & builder_config_path) {
2357
+ Ok ( ci_config_toml) => ci_config_toml,
2358
+ Err ( e) if e. to_string ( ) . contains ( "unknown field" ) => {
2359
+ println ! ( "WARNING: CI rustc has some fields that are no longer supported in bootstrap; download-rustc will be disabled." ) ;
2360
+ println ! ( "HELP: Consider rebasing to a newer commit if available." ) ;
2361
+ return None ;
2362
+ } ,
2363
+ Err ( e) => {
2364
+ eprintln ! ( "ERROR: Failed to parse CI rustc config at '{}': {e}" , builder_config_path. display( ) ) ;
2365
+ exit ! ( 2 ) ;
2366
+ } ,
2367
+ } ;
2368
+
2369
+ let current_config_toml = Self :: get_toml ( config_path) . unwrap ( ) ;
2348
2370
2349
2371
// Check the config compatibility
2350
2372
// FIXME: this doesn't cover `--set` flags yet.
0 commit comments