Skip to content

Commit e9fb5c2

Browse files
committed
Improve error message on build failure
Only print stderr if it's not empty. Stderr is always empty when running without `--quiet` because we then inherit stderr from the shell.
1 parent 070f8d6 commit e9fb5c2

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/builder.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,11 @@ impl fmt::Display for BuildKernelError {
410410
Run `cargo install cargo-xbuild` to install it.")
411411
}
412412
BuildKernelError::XbuildFailed{stderr} => {
413-
writeln!(f, "Kernel build failed:\n{}", String::from_utf8_lossy(stderr))
413+
writeln!(f, "Kernel build failed")?;
414+
if !stderr.is_empty() {
415+
writeln!(f, "\n{}", String::from_utf8_lossy(stderr))?;
416+
}
417+
Ok(())
414418
}
415419
BuildKernelError::XbuildJsonOutputInvalidUtf8(err) => {
416420
writeln!(f, "Output of kernel build with --message-format=json is not valid UTF-8:\n{}", err)
@@ -481,11 +485,13 @@ impl fmt::Display for CreateBootimageError {
481485
"The `bootloader` dependency has not the right format: {}",
482486
err
483487
),
484-
CreateBootimageError::BootloaderBuildFailed { stderr } => writeln!(
485-
f,
486-
"Bootloader build failed:\n\n{}",
487-
String::from_utf8_lossy(stderr)
488-
),
488+
CreateBootimageError::BootloaderBuildFailed { stderr } => {
489+
writeln!(f, "Bootloader build failed")?;
490+
if !stderr.is_empty() {
491+
writeln!(f, "\n{}", String::from_utf8_lossy(stderr))?;
492+
}
493+
Ok(())
494+
}
489495
CreateBootimageError::Io { message, error } => {
490496
writeln!(f, "I/O error: {}: {}", message, error)
491497
}

0 commit comments

Comments
 (0)