Drop SnapshotError in favor of anyhow::Error

This commit is contained in:
Lucien Greathouse
2020-12-18 12:16:05 -08:00
parent f3745c68d2
commit 3b149cc875
15 changed files with 70 additions and 183 deletions

View File

@@ -1,13 +1,12 @@
use std::{borrow::Cow, collections::HashMap, path::Path};
use anyhow::Context;
use rbx_dom_weak::UnresolvedRbxValue;
use rbx_reflection::try_resolve_value;
use serde::{Deserialize, Serialize};
use crate::snapshot::InstanceSnapshot;
use super::error::SnapshotError;
/// Represents metadata in a sibling file with the same basename.
///
/// As an example, hello.meta.json next to hello.lua would allow assigning
@@ -23,9 +22,13 @@ pub struct AdjacentMetadata {
}
impl AdjacentMetadata {
pub fn from_slice(slice: &[u8], path: &Path) -> Result<Self, SnapshotError> {
serde_json::from_slice(slice)
.map_err(|source| SnapshotError::malformed_meta_json(source, path))
pub fn from_slice(slice: &[u8], path: &Path) -> anyhow::Result<Self> {
serde_json::from_slice(slice).with_context(|| {
format!(
"File contained malformed .meta.json data: {}",
path.display()
)
})
}
pub fn apply_ignore_unknown_instances(&mut self, snapshot: &mut InstanceSnapshot) {
@@ -75,9 +78,13 @@ pub struct DirectoryMetadata {
}
impl DirectoryMetadata {
pub fn from_slice(slice: &[u8], path: &Path) -> Result<Self, SnapshotError> {
serde_json::from_slice(slice)
.map_err(|source| SnapshotError::malformed_meta_json(source, path))
pub fn from_slice(slice: &[u8], path: &Path) -> anyhow::Result<Self> {
serde_json::from_slice(slice).with_context(|| {
format!(
"File contained malformed init.meta.json data: {}",
path.display()
)
})
}
pub fn apply_all(&mut self, snapshot: &mut InstanceSnapshot) {