mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-01 06:53:11 +02:00
Fix sync import issues:
https://feedback.yaak.app/p/yaml-error-missing-field-type-at-line-4521-column-1
This commit is contained in:
@@ -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}")]
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user