From 0b1aa5a4c68f04d35a0784658b6c0fd42011c35e Mon Sep 17 00:00:00 2001 From: Dervex Date: Sun, 18 Aug 2024 14:28:19 +0200 Subject: [PATCH] Improve property parsing error details and command info --- CHANGELOG.md | 1 + src/cli/config.rs | 2 +- src/cli/studio.rs | 2 +- src/cli/update.rs | 4 ++-- src/core/meta.rs | 11 ++++++++++- src/core/processor/write.rs | 7 ++++--- src/middleware/data.rs | 4 ++-- src/middleware/json_model.rs | 10 +++++----- src/middleware/project.rs | 18 ++++++++++++++---- src/project.rs | 10 +++++----- 10 files changed, 45 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 393c6ff..19b1478 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), - Support for workspace-defined Argon config (`argon.toml`) - Default templates can now be updated when available (`update_templates` setting) +- Improved property parsing error details - filesystem and JSON path ### Changed diff --git a/src/cli/config.rs b/src/cli/config.rs index d6ffa65..e80d997 100644 --- a/src/cli/config.rs +++ b/src/cli/config.rs @@ -11,7 +11,7 @@ use crate::{ logger, util, }; -/// Edit global config with default editor or CLI +/// Edit global or workspace config with editor or CLI #[derive(Parser)] pub struct Config { /// Setting to change (if left empty config will be opened) diff --git a/src/cli/studio.rs b/src/cli/studio.rs index 13ef6f4..08d0300 100644 --- a/src/cli/studio.rs +++ b/src/cli/studio.rs @@ -4,7 +4,7 @@ use std::path::PathBuf; use crate::{argon_info, config::Config, ext::PathExt, studio}; -/// Launch a new instance of Roblox Studio +/// Launch a new Roblox Studio instance #[derive(Parser)] pub struct Studio { /// Path to place or model to open diff --git a/src/cli/update.rs b/src/cli/update.rs index 2a71aa8..1c4231f 100644 --- a/src/cli/update.rs +++ b/src/cli/update.rs @@ -3,10 +3,10 @@ use clap::{Parser, ValueEnum}; use crate::{argon_error, argon_info, config::Config, updater}; -/// Forcefully update Argon CLI and plugin if available +/// Forcefully update Argon components if available #[derive(Parser)] pub struct Update { - /// Whether to update `cli` or `plugin` or `both` + /// Whether to update `cli`, `plugin`, `templates` or `all` #[arg(hide_possible_values = true)] mode: Option, } diff --git a/src/core/meta.rs b/src/core/meta.rs index 48697e6..abed06d 100644 --- a/src/core/meta.rs +++ b/src/core/meta.rs @@ -1,5 +1,8 @@ use serde::{Deserialize, Serialize}; -use std::path::{Path, PathBuf}; +use std::{ + fmt::Display, + path::{Path, PathBuf}, +}; use crate::{ config::Config, @@ -43,6 +46,12 @@ impl NodePath { } } +impl Display for NodePath { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "tree/{}", self.inner.join("/")) + } +} + #[derive(Debug, Clone, PartialEq)] pub enum SourceKind { Path(PathBuf), diff --git a/src/core/processor/write.rs b/src/core/processor/write.rs index 061e18a..0af11b5 100644 --- a/src/core/processor/write.rs +++ b/src/core/processor/write.rs @@ -45,12 +45,13 @@ macro_rules! bad_name { macro_rules! filter_warn { ($id:expr) => { - warn!("Instance {:?} does not pass syncback filter! Skipping..", $id); + warn!("Instance {} does not pass syncback filter! Skipping..", $id); }; ($id:expr, $path:expr) => { warn!( - "Path: {:?} (source of instance: {:?}) does not pass syncback filter! Skipping..", - $path, $id + "Path: {} (source of instance: {}) does not pass syncback filter! Skipping..", + $path.display(), + $id ); }; } diff --git a/src/middleware/data.rs b/src/middleware/data.rs index 452c11f..278a1ea 100644 --- a/src/middleware/data.rs +++ b/src/middleware/data.rs @@ -75,7 +75,7 @@ pub fn read_data(path: &Path, vfs: &Vfs) -> Result { properties.insert(property, value); } Err(err) => { - error!("Failed to parse property: {}", err); + error!("Failed to parse property: {} at {}", err, path.display()); } } } @@ -87,7 +87,7 @@ pub fn read_data(path: &Path, vfs: &Vfs) -> Result { properties.insert(String::from("Attributes"), value); } Err(err) => { - error!("Failed to parse attributes: {}", err); + error!("Failed to parse attributes: {} at {}", err, path.display()); } } } diff --git a/src/middleware/json_model.rs b/src/middleware/json_model.rs index 33a8d68..60bfe5b 100644 --- a/src/middleware/json_model.rs +++ b/src/middleware/json_model.rs @@ -35,12 +35,12 @@ pub fn read_json_model(path: &Path, vfs: &Vfs) -> Result { } let model = serde_json::from_str(&contents)?; - let snapshot = walk(model)?; + let snapshot = walk(model, path)?; Ok(snapshot) } -fn walk(model: JsonModel) -> Result { +fn walk(model: JsonModel, path: &Path) -> Result { let mut snapshot = Snapshot::new(); let mut properties = HashMap::new(); @@ -61,7 +61,7 @@ fn walk(model: JsonModel) -> Result { properties.insert(property, value); } Err(err) => { - error!("Failed to parse property: {}", err); + error!("Failed to parse property: {} at {}", err, path.display()); } } } @@ -74,7 +74,7 @@ fn walk(model: JsonModel) -> Result { properties.insert(String::from("Attributes"), value); } Err(err) => { - error!("Failed to parse attributes: {}", err); + error!("Failed to parse attributes: {} at {}", err, path.display()); } } } @@ -92,7 +92,7 @@ fn walk(model: JsonModel) -> Result { // Append children for child in model.children.unwrap_or_default() { - snapshot.add_child(walk(child)?); + snapshot.add_child(walk(child, path)?); } Ok(snapshot) diff --git a/src/middleware/project.rs b/src/middleware/project.rs index c3c30de..0bb56c0 100644 --- a/src/middleware/project.rs +++ b/src/middleware/project.rs @@ -14,7 +14,7 @@ use crate::{ }, ext::PathExt, middleware::helpers, - project::{PathNode, Project, ProjectNode}, + project::{Project, ProjectNode, ProjectPath}, util, vfs::Vfs, }; @@ -68,7 +68,12 @@ pub fn new_snapshot_node( properties.insert(property.to_owned(), value); } Err(err) => { - error!("Failed to parse property: {}", err); + error!( + "Failed to parse property: {} at {}, JSON path: {}", + err, + path.display(), + node_path + ); } } } @@ -79,7 +84,12 @@ pub fn new_snapshot_node( properties.insert(String::from("Attributes"), value); } Err(err) => { - error!("Failed to parse attributes: {}", err); + error!( + "Failed to parse attributes: {} at {}, JSON path: {}", + err, + path.display(), + node_path + ); } } } @@ -132,7 +142,7 @@ pub fn new_snapshot_node( snapshot = path_snapshot; vfs.watch(&path, vfs.is_dir(&path))?; - } else if let PathNode::Required(_) = path_node { + } else if let ProjectPath::Required(_) = path_node { argon_warn!( "Path specified in the project does not exist: {}. Please create this path and restart Argon \ to watch for file changes in this path or remove it from the project to suppress this warning", diff --git a/src/project.rs b/src/project.rs index 76335c2..efb3395 100644 --- a/src/project.rs +++ b/src/project.rs @@ -21,16 +21,16 @@ use crate::{ #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(untagged)] -pub enum PathNode { +pub enum ProjectPath { Required(PathBuf), Optional { optional: PathBuf }, } -impl PathNode { +impl ProjectPath { pub fn path(&self) -> &Path { match self { - PathNode::Required(path) => path.as_ref(), - PathNode::Optional { optional } => optional.as_ref(), + ProjectPath::Required(path) => path.as_ref(), + ProjectPath::Optional { optional } => optional.as_ref(), } } } @@ -40,7 +40,7 @@ pub struct ProjectNode { #[serde(rename = "$className", skip_serializing_if = "Option::is_none")] pub class_name: Option, #[serde(rename = "$path", skip_serializing_if = "Option::is_none")] - pub path: Option, + pub path: Option, #[serde(flatten)] pub tree: BTreeMap,