Gregory Schier
2025-06-27 13:32:52 -07:00
parent 25d50246c0
commit 9ab02130b0
6 changed files with 38 additions and 21 deletions

View File

@@ -6,8 +6,11 @@ use thiserror::Error;
pub enum Error {
#[error("Yaml error: {0}")]
YamlParseError(#[from] serde_yaml::Error),
#[error("Sync parse error: {0}")]
ParseError(String),
#[error("Yaml error: {0}")]
#[error(transparent)]
ModelError(#[from] yaak_models::error::Error),
#[error("Unknown model: {0}")]
@@ -16,7 +19,7 @@ pub enum Error {
#[error("I/o error: {0}")]
IoError(#[from] io::Error),
#[error("Yaml error: {0}")]
#[error("JSON error: {0}")]
JsonParseError(#[from] serde_json::Error),
#[error("Invalid sync file: {0}")]

View File

@@ -1,6 +1,7 @@
use crate::error::Error::UnknownModel;
use crate::error::Result;
use chrono::NaiveDateTime;
use log::warn;
use serde::{Deserialize, Serialize};
use sha1::{Digest, Sha1};
use std::fs;
@@ -37,9 +38,21 @@ impl SyncModel {
let ext = file_path.extension().unwrap_or_default();
if ext == "yml" || ext == "yaml" {
Ok(Some((serde_yaml::from_str(&content_str)?, checksum)))
Ok(match serde_yaml::from_str::<SyncModel>(&content_str) {
Ok(m) => Some((m, checksum)),
Err(e) => {
warn!("Error parsing {:?} {:?}", file_path.file_name(), e);
None
}
})
} else if ext == "json" {
Ok(Some((serde_json::from_str(&content_str)?, checksum)))
Ok(match serde_json::from_str::<SyncModel>(&content_str) {
Ok(m) => Some((m, checksum)),
Err(e) => {
warn!("Error parsing {:?} {:?}", file_path.file_name(), e);
None
}
})
} else {
Ok(None)
}