mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-25 15:16:07 +00:00
Add error for malformed project files
This commit is contained in:
@@ -39,6 +39,16 @@ impl SnapshotError {
|
|||||||
path: Some(path.into()),
|
path: Some(path.into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn malformed_project(
|
||||||
|
inner: serde_json::Error,
|
||||||
|
path: impl Into<PathBuf>,
|
||||||
|
) -> SnapshotError {
|
||||||
|
SnapshotError {
|
||||||
|
detail: SnapshotErrorDetail::MalformedProject { inner },
|
||||||
|
path: Some(path.into()),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Error for SnapshotError {
|
impl Error for SnapshotError {
|
||||||
@@ -72,6 +82,7 @@ pub enum SnapshotErrorDetail {
|
|||||||
FileDidNotExist,
|
FileDidNotExist,
|
||||||
FileNameBadUnicode,
|
FileNameBadUnicode,
|
||||||
FileContentsBadUnicode { inner: std::str::Utf8Error },
|
FileContentsBadUnicode { inner: std::str::Utf8Error },
|
||||||
|
MalformedProject { inner: serde_json::Error },
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SnapshotErrorDetail {
|
impl SnapshotErrorDetail {
|
||||||
@@ -81,6 +92,7 @@ impl SnapshotErrorDetail {
|
|||||||
match self {
|
match self {
|
||||||
IoError { inner } => Some(inner),
|
IoError { inner } => Some(inner),
|
||||||
FileContentsBadUnicode { inner } => Some(inner),
|
FileContentsBadUnicode { inner } => Some(inner),
|
||||||
|
MalformedProject { inner } => Some(inner),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -97,6 +109,7 @@ impl fmt::Display for SnapshotErrorDetail {
|
|||||||
FileContentsBadUnicode { inner } => {
|
FileContentsBadUnicode { inner } => {
|
||||||
write!(formatter, "file had malformed unicode: {}", inner)
|
write!(formatter, "file had malformed unicode: {}", inner)
|
||||||
}
|
}
|
||||||
|
MalformedProject { inner } => write!(formatter, "{}", inner),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
|
error::SnapshotError,
|
||||||
middleware::{SnapshotFileResult, SnapshotInstanceResult, SnapshotMiddleware},
|
middleware::{SnapshotFileResult, SnapshotInstanceResult, SnapshotMiddleware},
|
||||||
snapshot_from_imfs,
|
snapshot_from_imfs,
|
||||||
};
|
};
|
||||||
@@ -42,8 +43,7 @@ impl SnapshotMiddleware for SnapshotProject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let project = Project::load_from_slice(entry.contents(imfs)?, entry.path())
|
let project = Project::load_from_slice(entry.contents(imfs)?, entry.path())
|
||||||
// TODO: Turn this into an error object
|
.map_err(|err| SnapshotError::malformed_project(err, entry.path()))?;
|
||||||
.expect("Invalid project file");
|
|
||||||
|
|
||||||
// Snapshotting a project should always return an instance, so this
|
// Snapshotting a project should always return an instance, so this
|
||||||
// unwrap is safe.
|
// unwrap is safe.
|
||||||
|
|||||||
Reference in New Issue
Block a user