recipe error handling
This commit is contained in:
parent
312dcc7ead
commit
f7ea8eae09
1 changed files with 9 additions and 1 deletions
|
|
@ -1,3 +1,11 @@
|
||||||
|
#[derive(Debug, thiserror::Error)]
|
||||||
|
pub enum RecipeLoadError {
|
||||||
|
#[error(transparent)]
|
||||||
|
StdIoError(#[from] std::io::Error),
|
||||||
|
#[error(transparent)]
|
||||||
|
TomlDeserializeError(#[from] toml::de::Error),
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, serde::Deserialize)]
|
#[derive(Clone, Copy, Debug, PartialEq, serde::Deserialize)]
|
||||||
pub enum Unit {
|
pub enum Unit {
|
||||||
Foot,
|
Foot,
|
||||||
|
|
@ -91,7 +99,7 @@ pub struct Recipe {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Recipe {
|
impl Recipe {
|
||||||
pub fn from_file(file: &std::path::PathBuf) -> anyhow::Result<Self> {
|
pub fn from_file(file: &std::path::PathBuf) -> Result<Self, RecipeLoadError> {
|
||||||
let recipe_contents = std::fs::read_to_string(file)?;
|
let recipe_contents = std::fs::read_to_string(file)?;
|
||||||
let mut recipe: Recipe = toml::from_str(&recipe_contents)?;
|
let mut recipe: Recipe = toml::from_str(&recipe_contents)?;
|
||||||
if recipe.outputs == None {
|
if recipe.outputs == None {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue