repo: better error handling
fixup repo err handling
This commit is contained in:
parent
2c1f331523
commit
312dcc7ead
5 changed files with 35 additions and 6 deletions
21
tools/Cargo.lock
generated
21
tools/Cargo.lock
generated
|
|
@ -230,6 +230,26 @@ dependencies = [
|
|||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "2.0.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d452f284b73e6d76dd36758a0c8684b1d5be31f92b89d07fd5822175732206fc"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "2.0.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "26afc1baea8a989337eeb52b6e72a039780ce45c3edfcc9c5b9d112feeb173c2"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "0.8.19"
|
||||
|
|
@ -271,6 +291,7 @@ dependencies = [
|
|||
"anyhow",
|
||||
"clap",
|
||||
"serde",
|
||||
"thiserror",
|
||||
"toml",
|
||||
"uuid",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -7,5 +7,6 @@ edition = "2021"
|
|||
anyhow = "1.0.95"
|
||||
clap = { version = "4.5.26", features = ["derive"] }
|
||||
serde = { version = "1.0.217", features = ["derive"] }
|
||||
thiserror = "2.0.11"
|
||||
toml = "0.8.19"
|
||||
uuid = { version = "1.12.1", features = ["std", "v4" ] }
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ struct Args {
|
|||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
let args = Args::parse();
|
||||
let repo = Repo::new(&args.repo);
|
||||
let repo = Repo::new(&args.repo).unwrap();
|
||||
repo.compile(&args.target)?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,3 +3,4 @@ pub use recipe::Recipe;
|
|||
|
||||
pub mod repo;
|
||||
pub use repo::Repo;
|
||||
pub use repo::RepoLoadError;
|
||||
|
|
|
|||
|
|
@ -9,14 +9,20 @@ pub struct Repo {
|
|||
recipes: std::collections::HashMap<String, Recipe>,
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum RepoLoadError {
|
||||
#[error("io error: {0}")]
|
||||
StdIoError(#[from] std::io::Error),
|
||||
}
|
||||
|
||||
impl Repo {
|
||||
pub fn new(path: &str) -> Self {
|
||||
pub fn new(path: &str) -> Result<Self, RepoLoadError> {
|
||||
let mut repo = Self {
|
||||
path: std::string::String::from(path),
|
||||
recipes: std::collections::HashMap::<String, Recipe>::new(),
|
||||
};
|
||||
repo.add_dir(path).unwrap();
|
||||
repo
|
||||
repo.add_dir(path)?;
|
||||
Ok(repo)
|
||||
}
|
||||
|
||||
pub fn get_recipe(self: &Self, recipe_name: &str) -> Option<&Recipe> {
|
||||
|
|
@ -51,9 +57,9 @@ impl Repo {
|
|||
}
|
||||
|
||||
impl Repo {
|
||||
fn add_dir(self: &mut Self, path: &str) -> anyhow::Result<()> {
|
||||
fn add_dir(self: &mut Self, path: &str) -> Result<(), RepoLoadError> {
|
||||
// println!("reading Recipes from {path}");
|
||||
let dir_entries = std::fs::read_dir(path).unwrap();
|
||||
let dir_entries = std::fs::read_dir(path)?;
|
||||
for dir_entry in dir_entries {
|
||||
let dir_entry = dir_entry.unwrap();
|
||||
let file_type = dir_entry.file_type().unwrap();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue