mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-20 17:41:37 +00:00
Do not validate .model.json files with no content/whitespace only (#420)
* Ignore empty/whitespace-only model.json files
* Ignore no return value from model.json files during snapshot
* Use str::from_utf8 instead of String::from_utf8
* Revert "Ignore no return value from model.json files during snapshot"
This reverts commit 0aef16e30a.
* Add test for empty .model.json files
* Change empty .model.json check method
Co-authored-by: Lucien Greathouse <me@lpghatguy.com>
* Format code with cargo fmt
* Use raw string instead
Co-authored-by: Lucien Greathouse <me@lpghatguy.com>
This commit is contained in:
parent
7599ef6626
commit
ca8865a3ce
8 changed files with 130 additions and 2 deletions
|
|
@ -1,4 +1,4 @@
|
|||
use std::{borrow::Cow, collections::HashMap, path::Path};
|
||||
use std::{borrow::Cow, collections::HashMap, path::Path, str};
|
||||
|
||||
use anyhow::Context;
|
||||
use memofs::Vfs;
|
||||
|
|
@ -18,7 +18,14 @@ pub fn snapshot_json_model(
|
|||
instance_name: &str,
|
||||
) -> SnapshotInstanceResult {
|
||||
let contents = vfs.read(path)?;
|
||||
let instance: JsonModel = serde_json::from_slice(&contents)
|
||||
let contents_str = str::from_utf8(&contents)
|
||||
.with_context(|| format!("File was not valid UTF-8: {}", path.display()))?;
|
||||
|
||||
if contents_str.trim().is_empty() {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
let instance: JsonModel = serde_json::from_str(contents_str)
|
||||
.with_context(|| format!("File is not a valid JSON model: {}", path.display()))?;
|
||||
|
||||
let mut snapshot = instance
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue