Skip to content

Commit 697a384

Browse files
committed
Add a new KernelPackageNotFound error instead of unwrapping
1 parent 2133b33 commit 697a384

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/builder/bootloader.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ impl BuildConfig {
2727
.packages
2828
.iter()
2929
.find(|p| p.manifest_path == kernel_manifest_path)
30-
.unwrap();
30+
.ok_or_else(|| BootloaderError::KernelPackageNotFound {
31+
manifest_path: kernel_manifest_path.to_owned(),
32+
})?;
3133

3234
let bootloader_pkg = bootloader_package(project_metadata, kernel_pkg)?;
3335
let bootloader_root = bootloader_pkg.manifest_path.parent().ok_or_else(|| {

src/builder/error.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::io;
1+
use std::{io, path::PathBuf};
22
use thiserror::Error;
33

44
/// Represents an error that occurred while creating a new `Builder`.
@@ -93,9 +93,20 @@ pub enum BootloaderError {
9393
You need to add a dependency on a crate named `bootloader` in your Cargo.toml."
9494
)]
9595
BootloaderNotFound,
96+
9697
/// Bootloader dependency has not the right format
9798
#[error("The `bootloader` dependency has not the right format: {0}")]
9899
BootloaderInvalid(String),
100+
101+
/// Could not find kernel package in cargo metadata
102+
#[error(
103+
"Could not find package with manifest path `{manifest_path}` in cargo metadata output"
104+
)]
105+
KernelPackageNotFound {
106+
/// The manifest path of the kernel package
107+
manifest_path: PathBuf,
108+
},
109+
99110
/// Could not find some required information in the `cargo metadata` output
100111
#[error("Could not find required key `{key}` in cargo metadata output")]
101112
CargoMetadataIncomplete {

0 commit comments

Comments
 (0)