1use std::path::PathBuf;
2use thiserror::Error;
3
4#[derive(Error, Debug)]
5pub enum BuilderErr {
6 #[error("Error retrieving root privileges")]
7 NoPrivileges,
8 #[error("Missing kernel configuration file: {path}")]
9 KernelConfigMissing { path: PathBuf },
10 #[error("Missing option in kernel configuration: {0}")]
11 KernelConfigMissingOption(String),
12 #[error("Error updating kernel config: {details}")]
13 KernelConfigUpdateError { details: String },
14 #[error("Kernel build failed: {0}")]
15 KernelBuildFail(String),
16 #[error("Error linking file to {path}: {source}")]
17 LinkingFileError {
18 source: std::io::Error,
19 path: PathBuf,
20 },
21 #[error("Could not parse config file")]
22 ConfigError(#[from] config::ConfigError),
23 #[error("Could not create prompt")]
24 PromptError(#[from] dialoguer::Error),
25 #[error("Error while starting menuconfig")]
26 MenuconfigError,
27 #[error("Command execution failed: {0}")]
28 CommandError(String),
29 #[error("Invalid configuration: {0}")]
30 InvalidConfig(String),
31 #[error("Discovery error: {0}")]
32 DiscoveryError(String),
33}
34
35impl BuilderErr {
36 #[must_use]
37 pub fn kernel_config_missing() -> Self {
38 Self::KernelConfigMissing {
39 path: PathBuf::from("/usr/src/.config"),
40 }
41 }
42
43 #[must_use]
44 pub fn invalid_config(msg: impl Into<String>) -> Self {
45 Self::InvalidConfig(msg.into())
46 }
47
48 #[must_use]
49 pub fn discovery_error(msg: impl Into<String>) -> Self {
50 Self::DiscoveryError(msg.into())
51 }
52
53 #[must_use]
54 pub fn linking_file_error(source: std::io::Error, path: PathBuf) -> Self {
55 Self::LinkingFileError { source, path }
56 }
57
58 #[must_use]
59 pub fn kernel_config_update_error(details: String) -> Self {
60 Self::KernelConfigUpdateError { details }
61 }
62}