summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2021-10-29 23:39:23 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2021-10-29 23:39:48 +0200
commita8a14c41d818cb8c5ad6a78aca024b855231e027 (patch)
tree899048202184f15f8b8b1b011c1d738a3d4d5de3
parent8b71986fe1d7a6a889cbb437294b76b22a1e7377 (diff)
downloadrebel-a8a14c41d818cb8c5ad6a78aca024b855231e027.tar
rebel-a8a14c41d818cb8c5ad6a78aca024b855231e027.zip
driver: recipe: use common error types
-rw-r--r--crates/driver/src/recipe.rs41
1 files changed, 6 insertions, 35 deletions
diff --git a/crates/driver/src/recipe.rs b/crates/driver/src/recipe.rs
index 04f356b..0121800 100644
--- a/crates/driver/src/recipe.rs
+++ b/crates/driver/src/recipe.rs
@@ -1,10 +1,10 @@
-use std::{collections::HashMap, fmt, fs::File, io, path::Path, result};
+use std::{collections::HashMap, fs::File, path::Path, result};
use scoped_tls_hkt::scoped_thread_local;
use serde::{Deserialize, Deserializer};
use walkdir::WalkDir;
-use common::types::*;
+use common::{error::*, types::*};
use crate::task::{RecipeMeta, TaskDef};
@@ -37,41 +37,12 @@ struct Recipe {
pub tasks: HashMap<String, TaskDef>,
}
-#[derive(Debug)]
-pub enum Error {
- IOError(io::Error),
- YAMLError(serde_yaml::Error),
-}
-
-impl From<io::Error> for Error {
- fn from(err: io::Error) -> Self {
- Error::IOError(err)
- }
-}
-
-impl From<serde_yaml::Error> for Error {
- fn from(err: serde_yaml::Error) -> Self {
- Error::YAMLError(err)
- }
-}
-
-impl fmt::Display for Error {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- match self {
- Error::IOError(err) => write!(f, "IO error: {}", err),
- Error::YAMLError(err) => write!(f, "YAML error: {}", err),
- }
- }
-}
-
-impl std::error::Error for Error {}
-
-pub type Result<T> = std::result::Result<T, Error>;
-
fn read_recipe(path: &Path) -> Result<Recipe> {
- let f = File::open(path)?;
+ let f = File::open(path).context("IO error")?;
- let recipe: Recipe = serde_yaml::from_reader(f)?;
+ let recipe: Recipe = serde_yaml::from_reader(f)
+ .map_err(Error::new)
+ .context("YAML error")?;
Ok(recipe)
}