bootimage/builder/
error.rs1use std::{io, path::PathBuf};
2use thiserror::Error;
3
4#[derive(Debug, Error)]
6pub enum BuilderError {
7 #[error("Could not find Cargo.toml file starting from current folder: {0:?}")]
9 LocateCargoManifest(#[from] locate_cargo_manifest::LocateManifestError),
10}
11
12#[derive(Debug, Error)]
14#[non_exhaustive]
15pub enum BuildKernelError {
16 #[error("I/O error: {message}:\n{error}")]
18 Io {
19 message: &'static str,
21 error: io::Error,
23 },
24
25 #[error(
27 "Failed to run `cargo xbuild`. Perhaps it is not installed?\n\
28 Run `cargo install cargo-xbuild` to install it."
29 )]
30 XbuildNotFound,
31
32 #[error("Kernel build failed.\nStderr: {}", String::from_utf8_lossy(.stderr))]
34 BuildFailed {
35 stderr: Vec<u8>,
37 },
38
39 #[error("Output of kernel build with --message-format=json is not valid UTF-8:\n{0}")]
41 BuildJsonOutputInvalidUtf8(std::string::FromUtf8Error),
42 #[error("Output of kernel build with --message-format=json is not valid JSON:\n{0}")]
44 BuildJsonOutputInvalidJson(json::Error),
45}
46
47#[derive(Debug, Error)]
49#[non_exhaustive]
50pub enum CreateBootimageError {
51 #[error("An error occurred while trying to build the bootloader: {0}")]
53 Bootloader(#[from] BootloaderError),
54
55 #[error("Error while running `cargo metadata` for current project: {0:?}")]
57 CargoMetadata(#[from] cargo_metadata::Error),
58
59 #[error("Bootloader build failed.\nStderr: {}", String::from_utf8_lossy(.stderr))]
61 BootloaderBuildFailed {
62 stderr: Vec<u8>,
64 },
65
66 #[error("An error occurred while trying to create the disk image: {0}")]
68 DiskImage(#[from] DiskImageError),
69
70 #[error("I/O error: {message}:\n{error}")]
72 Io {
73 message: &'static str,
75 error: io::Error,
77 },
78
79 #[error("Output of bootloader build with --message-format=json is not valid UTF-8:\n{0}")]
81 BuildJsonOutputInvalidUtf8(std::string::FromUtf8Error),
82 #[error("Output of bootloader build with --message-format=json is not valid JSON:\n{0}")]
84 BuildJsonOutputInvalidJson(json::Error),
85}
86
87#[derive(Debug, Error)]
89pub enum BootloaderError {
90 #[error(
92 "Bootloader dependency not found\n\n\
93 You need to add a dependency on a crate named `bootloader` in your Cargo.toml."
94 )]
95 BootloaderNotFound,
96
97 #[error("The `bootloader` dependency has not the right format: {0}")]
99 BootloaderInvalid(String),
100
101 #[error(
103 "Could not find package with manifest path `{manifest_path}` in cargo metadata output"
104 )]
105 KernelPackageNotFound {
106 manifest_path: PathBuf,
108 },
109
110 #[error("Could not find required key `{key}` in cargo metadata output")]
112 CargoMetadataIncomplete {
113 key: String,
115 },
116}
117
118#[derive(Debug, Error)]
120pub enum DiskImageError {
121 #[error(
123 "Could not find the `llvm-tools-preview` rustup component.\n\n\
124 You can install by executing `rustup component add llvm-tools-preview`."
125 )]
126 LlvmToolsNotFound,
127
128 #[error("Failed to locate the `llvm-tools-preview` rustup component: {0:?}")]
130 LlvmTools(llvm_tools::Error),
131
132 #[error("Could not find `llvm-objcopy` in the `llvm-tools-preview` rustup component.")]
134 LlvmObjcopyNotFound,
135
136 #[error("Failed to run `llvm-objcopy`: {}", String::from_utf8_lossy(.stderr))]
138 ObjcopyFailed {
139 stderr: Vec<u8>,
141 },
142
143 #[error("I/O error: {message}:\n{error}")]
145 Io {
146 message: &'static str,
148 error: io::Error,
150 },
151}
152
153impl From<llvm_tools::Error> for DiskImageError {
154 fn from(err: llvm_tools::Error) -> Self {
155 match err {
156 llvm_tools::Error::NotFound => DiskImageError::LlvmToolsNotFound,
157 other => DiskImageError::LlvmTools(other),
158 }
159 }
160}