@@ -96,8 +96,12 @@ impl Builder {
96
96
} ) ;
97
97
}
98
98
let mut executables = Vec :: new ( ) ;
99
- for line in String :: from_utf8 ( output. stdout ) . unwrap ( ) . lines ( ) {
100
- let mut artifact = json:: parse ( line) . unwrap ( ) ;
99
+ for line in String :: from_utf8 ( output. stdout )
100
+ . map_err ( BuildKernelError :: XbuildJsonOutputInvalidUtf8 ) ?
101
+ . lines ( )
102
+ {
103
+ let mut artifact =
104
+ json:: parse ( line) . map_err ( BuildKernelError :: XbuildJsonOutputInvalidJson ) ?;
101
105
if let Some ( executable) = artifact[ "executable" ] . take_string ( ) {
102
106
executables. push ( PathBuf :: from ( executable) ) ;
103
107
}
@@ -233,8 +237,12 @@ impl Builder {
233
237
} ) ;
234
238
}
235
239
let mut bootloader_elf_path = None ;
236
- for line in String :: from_utf8 ( output. stdout ) . unwrap ( ) . lines ( ) {
237
- let mut artifact = json:: parse ( line) . unwrap ( ) ;
240
+ for line in String :: from_utf8 ( output. stdout )
241
+ . map_err ( CreateBootimageError :: XbuildJsonOutputInvalidUtf8 ) ?
242
+ . lines ( )
243
+ {
244
+ let mut artifact =
245
+ json:: parse ( line) . map_err ( CreateBootimageError :: XbuildJsonOutputInvalidJson ) ?;
238
246
if let Some ( executable) = artifact[ "executable" ] . take_string ( ) {
239
247
if bootloader_elf_path
240
248
. replace ( PathBuf :: from ( executable) )
@@ -316,10 +324,8 @@ pub enum BuildKernelError {
316
324
XbuildFailed {
317
325
stderr : Vec < u8 > ,
318
326
} ,
319
- CargoConfigInvalid {
320
- path : PathBuf ,
321
- error : String ,
322
- } ,
327
+ XbuildJsonOutputInvalidUtf8 ( std:: string:: FromUtf8Error ) ,
328
+ XbuildJsonOutputInvalidJson ( json:: Error ) ,
323
329
}
324
330
325
331
impl fmt:: Display for BuildKernelError {
@@ -338,9 +344,12 @@ impl fmt::Display for BuildKernelError {
338
344
BuildKernelError :: XbuildFailed { stderr} => {
339
345
writeln ! ( f, "Kernel build failed:\n {}" , String :: from_utf8_lossy( stderr) )
340
346
}
341
- BuildKernelError :: CargoConfigInvalid { path, error} => {
342
- writeln ! ( f, "Failed to read cargo config at {}:\n {}" , path. display( ) , error)
343
- } ,
347
+ BuildKernelError :: XbuildJsonOutputInvalidUtf8 ( err) => {
348
+ writeln ! ( f, "Output of kernel build with --message-format=json is not valid UTF-8:\n {}" , err)
349
+ }
350
+ BuildKernelError :: XbuildJsonOutputInvalidJson ( err) => {
351
+ writeln ! ( f, "Output of kernel build with --message-format=json is not valid JSON:\n {}" , err)
352
+ }
344
353
}
345
354
}
346
355
}
@@ -374,6 +383,8 @@ pub enum CreateBootimageError {
374
383
ObjcopyFailed {
375
384
stderr : Vec < u8 > ,
376
385
} ,
386
+ XbuildJsonOutputInvalidUtf8 ( std:: string:: FromUtf8Error ) ,
387
+ XbuildJsonOutputInvalidJson ( json:: Error ) ,
377
388
}
378
389
379
390
impl fmt:: Display for CreateBootimageError {
@@ -422,6 +433,16 @@ impl fmt::Display for CreateBootimageError {
422
433
"Failed to run `llvm-objcopy`: {}" ,
423
434
String :: from_utf8_lossy( stderr)
424
435
) ,
436
+ CreateBootimageError :: XbuildJsonOutputInvalidUtf8 ( err) => writeln ! (
437
+ f,
438
+ "Output of bootloader build with --message-format=json is not valid UTF-8:\n {}" ,
439
+ err
440
+ ) ,
441
+ CreateBootimageError :: XbuildJsonOutputInvalidJson ( err) => writeln ! (
442
+ f,
443
+ "Output of bootloader build with --message-format=json is not valid JSON:\n {}" ,
444
+ err
445
+ ) ,
425
446
}
426
447
}
427
448
}
0 commit comments