Turn rbxm/rbxmx errors into error variants

This commit is contained in:
Lucien Greathouse
2020-12-18 11:39:41 -08:00
parent eddbe7d0cf
commit f3745c68d2
3 changed files with 33 additions and 4 deletions

View File

@@ -18,6 +18,18 @@ pub enum SnapshotError {
#[error("malformed project file at path {}", .path.display())]
MalformedProject { source: ProjectError, path: PathBuf },
#[error("malformed .rbxm file at path {}", .path.display())]
MalformedRbxm {
source: rbx_binary::DecodeError,
path: PathBuf,
},
#[error("malformed .rbxmx file at path {}", .path.display())]
MalformedRbxmx {
source: rbx_xml::DecodeError,
path: PathBuf,
},
#[error("malformed .model.json file at path {}", .path.display())]
MalformedModelJson {
source: serde_json::Error,
@@ -68,6 +80,23 @@ impl SnapshotError {
}
}
pub(crate) fn malformed_rbxm(
source: rbx_binary::DecodeError,
path: impl Into<PathBuf>,
) -> Self {
Self::MalformedRbxm {
source,
path: path.into(),
}
}
pub(crate) fn malformed_rbxmx(source: rbx_xml::DecodeError, path: impl Into<PathBuf>) -> Self {
Self::MalformedRbxmx {
source,
path: path.into(),
}
}
pub(crate) fn malformed_model_json(
source: serde_json::Error,
path: impl Into<PathBuf>,

View File

@@ -5,7 +5,7 @@ use rbx_dom_weak::{RbxInstanceProperties, RbxTree};
use crate::snapshot::{InstanceContext, InstanceMetadata, InstanceSnapshot};
use super::middleware::SnapshotInstanceResult;
use super::{middleware::SnapshotInstanceResult, SnapshotError};
pub fn snapshot_rbxm(
context: &InstanceContext,
@@ -21,7 +21,7 @@ pub fn snapshot_rbxm(
let root_id = temp_tree.get_root_id();
rbx_binary::decode(&mut temp_tree, root_id, vfs.read(path)?.as_slice())
.expect("TODO: Handle rbx_binary errors");
.map_err(|err| SnapshotError::malformed_rbxm(err, path))?;
let root_instance = temp_tree.get_instance(root_id).unwrap();
let children = root_instance.get_children_ids();

View File

@@ -4,7 +4,7 @@ use memofs::Vfs;
use crate::snapshot::{InstanceContext, InstanceMetadata, InstanceSnapshot};
use super::middleware::SnapshotInstanceResult;
use super::{middleware::SnapshotInstanceResult, SnapshotError};
pub fn snapshot_rbxmx(
context: &InstanceContext,
@@ -16,7 +16,7 @@ pub fn snapshot_rbxmx(
.property_behavior(rbx_xml::DecodePropertyBehavior::ReadUnknown);
let temp_tree = rbx_xml::from_reader(vfs.read(path)?.as_slice(), options)
.expect("TODO: Handle rbx_xml errors");
.map_err(|err| SnapshotError::malformed_rbxmx(err, path))?;
let root_instance = temp_tree.get_instance(temp_tree.get_root_id()).unwrap();
let children = root_instance.get_children_ids();