Skip to content

Commit

Permalink
Improve property parsing error details and command info
Browse files Browse the repository at this point in the history
  • Loading branch information
DervexDev committed Aug 18, 2024
1 parent cbc60a8 commit 0b1aa5a
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 24 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/cli/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/cli/studio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/cli/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<UpdateMode>,
}
Expand Down
11 changes: 10 additions & 1 deletion src/core/meta.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use serde::{Deserialize, Serialize};
use std::path::{Path, PathBuf};
use std::{
fmt::Display,
path::{Path, PathBuf},
};

use crate::{
config::Config,
Expand Down Expand Up @@ -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),
Expand Down
7 changes: 4 additions & 3 deletions src/core/processor/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/middleware/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub fn read_data(path: &Path, vfs: &Vfs) -> Result<DataSnapshot> {
properties.insert(property, value);
}
Err(err) => {
error!("Failed to parse property: {}", err);
error!("Failed to parse property: {} at {}", err, path.display());
}
}
}
Expand All @@ -87,7 +87,7 @@ pub fn read_data(path: &Path, vfs: &Vfs) -> Result<DataSnapshot> {
properties.insert(String::from("Attributes"), value);
}
Err(err) => {
error!("Failed to parse attributes: {}", err);
error!("Failed to parse attributes: {} at {}", err, path.display());
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/middleware/json_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ pub fn read_json_model(path: &Path, vfs: &Vfs) -> Result<Snapshot> {
}

let model = serde_json::from_str(&contents)?;
let snapshot = walk(model)?;
let snapshot = walk(model, path)?;

Ok(snapshot)
}

fn walk(model: JsonModel) -> Result<Snapshot> {
fn walk(model: JsonModel, path: &Path) -> Result<Snapshot> {
let mut snapshot = Snapshot::new();
let mut properties = HashMap::new();

Expand All @@ -61,7 +61,7 @@ fn walk(model: JsonModel) -> Result<Snapshot> {
properties.insert(property, value);
}
Err(err) => {
error!("Failed to parse property: {}", err);
error!("Failed to parse property: {} at {}", err, path.display());
}
}
}
Expand All @@ -74,7 +74,7 @@ fn walk(model: JsonModel) -> Result<Snapshot> {
properties.insert(String::from("Attributes"), value);
}
Err(err) => {
error!("Failed to parse attributes: {}", err);
error!("Failed to parse attributes: {} at {}", err, path.display());
}
}
}
Expand All @@ -92,7 +92,7 @@ fn walk(model: JsonModel) -> Result<Snapshot> {

// Append children
for child in model.children.unwrap_or_default() {
snapshot.add_child(walk(child)?);
snapshot.add_child(walk(child, path)?);
}

Ok(snapshot)
Expand Down
18 changes: 14 additions & 4 deletions src/middleware/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
},
ext::PathExt,
middleware::helpers,
project::{PathNode, Project, ProjectNode},
project::{Project, ProjectNode, ProjectPath},
util,
vfs::Vfs,
};
Expand Down Expand Up @@ -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
);
}
}
}
Expand All @@ -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
);
}
}
}
Expand Down Expand Up @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}
}
Expand All @@ -40,7 +40,7 @@ pub struct ProjectNode {
#[serde(rename = "$className", skip_serializing_if = "Option::is_none")]
pub class_name: Option<String>,
#[serde(rename = "$path", skip_serializing_if = "Option::is_none")]
pub path: Option<PathNode>,
pub path: Option<ProjectPath>,
#[serde(flatten)]
pub tree: BTreeMap<String, ProjectNode>,

Expand Down

0 comments on commit 0b1aa5a

Please sign in to comment.