Implement new oneshot Vfs for CLI commands and enhance JSON5 serialization

- Added `new_oneshot` method to the Vfs struct, providing a backend suitable for one-time operations without file watching.
- Updated CLI commands (`fmt_project` and `syncback`) to utilize the new oneshot Vfs, improving error handling during file operations.
- Enhanced JSON5 serialization by introducing a custom serializer that directly builds a tree structure, improving performance and maintaining sorted keys.
- Improved error logging in JSON serialization to provide more context on failures.
This commit is contained in:
Joe 2026-01-31 13:06:37 -06:00
parent fca802a4e5
commit 5f91a0777a
7 changed files with 3753 additions and 44 deletions

View file

@ -83,12 +83,32 @@ pub fn syncback_json_model<'sync>(
model.schema = old_inst.metadata().schema.clone();
}
let serialized = match crate::json::to_vec_pretty_sorted(&model) {
Ok(bytes) => bytes,
Err(e) => {
// Provide more detail about what's in the model
let prop_details: Vec<_> = model
.properties
.iter()
.map(|(k, v)| format!("{}={:?}", k.as_str(), v))
.collect();
let attr_names: Vec<_> = model.attributes.keys().map(|k| k.as_str()).collect();
log::error!(
"Failed to serialize JSON model for class '{}': properties=[{}], attributes={:?}, error: {}",
model.class_name,
prop_details.join(", "),
attr_names,
e
);
return Err(e.context(format!(
"failed to serialize new JSON Model for class '{}'",
model.class_name
)));
}
};
Ok(SyncbackReturn {
fs_snapshot: FsSnapshot::new().with_added_file(
&snapshot.path,
crate::json::to_vec_pretty_sorted(&model)
.context("failed to serialize new JSON Model")?,
),
fs_snapshot: FsSnapshot::new().with_added_file(&snapshot.path, serialized),
children: Vec::new(),
removed_children: Vec::new(),
})