@@ -1200,19 +1200,19 @@ impl Config {
1200
1200
}
1201
1201
1202
1202
#[ 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 ( ) )
1205
1205
}
1206
1206
1207
1207
#[ cfg( not( test) ) ]
1208
- fn get_toml ( file : & Path ) -> TomlConfig {
1208
+ fn get_toml ( file : & Path ) -> Result < TomlConfig , toml :: de :: Error > {
1209
1209
let contents =
1210
1210
t ! ( fs:: read_to_string( file) , format!( "config file {} not found" , file. display( ) ) ) ;
1211
1211
// Deserialize to Value and then TomlConfig to prevent the Deserialize impl of
1212
1212
// TomlConfig and sub types to be monomorphized 5x by toml.
1213
1213
toml:: from_str ( & contents)
1214
1214
. and_then ( |table : toml:: Value | TomlConfig :: deserialize ( table) )
1215
- . unwrap_or_else ( |err | {
1215
+ . inspect_err ( |_ | {
1216
1216
if let Ok ( Some ( changes) ) = toml:: from_str ( & contents)
1217
1217
. and_then ( |table : toml:: Value | ChangeIdWrapper :: deserialize ( table) )
1218
1218
. map ( |change_id| change_id. inner . map ( crate :: find_recent_config_change_ids) )
@@ -1224,17 +1224,17 @@ impl Config {
1224
1224
) ;
1225
1225
}
1226
1226
}
1227
-
1228
- eprintln ! ( "failed to parse TOML configuration '{}': {err}" , file. display( ) ) ;
1229
- exit ! ( 2 ) ;
1230
1227
} )
1231
1228
}
1232
1229
1233
1230
pub fn parse ( flags : Flags ) -> Config {
1234
1231
Self :: parse_inner ( flags, Self :: get_toml)
1235
1232
}
1236
1233
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 {
1238
1238
let mut config = Config :: default_opts ( ) ;
1239
1239
1240
1240
// Set flags.
@@ -1342,7 +1342,10 @@ impl Config {
1342
1342
} else {
1343
1343
toml_path. clone ( )
1344
1344
} ) ;
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
+ } )
1346
1349
} else {
1347
1350
config. config = None ;
1348
1351
TomlConfig :: default ( )
@@ -1373,7 +1376,13 @@ impl Config {
1373
1376
include_path. push ( "bootstrap" ) ;
1374
1377
include_path. push ( "defaults" ) ;
1375
1378
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
+ } ) ;
1377
1386
toml. merge ( included_toml, ReplaceOpt :: IgnoreDuplicate ) ;
1378
1387
}
1379
1388
@@ -2331,8 +2340,21 @@ impl Config {
2331
2340
if let Some ( config_path) = & self . config {
2332
2341
let builder_config_path =
2333
2342
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 ( ) ;
2336
2358
2337
2359
// Check the config compatibility
2338
2360
// FIXME: this doesn't cover `--set` flags yet.
0 commit comments