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,5 +1,6 @@
use std::{path::Path, str};
use anyhow::Context;
use maplit::hashmap;
use memofs::{IoResultExt, Vfs};
use rbx_dom_weak::RbxValue;
@@ -28,9 +29,8 @@ pub fn snapshot_lua(context: &InstanceContext, vfs: &Vfs, path: &Path) -> Snapsh
let contents = vfs.read(path)?;
let contents_str = str::from_utf8(&contents)
// TODO: Turn into error type
.expect("File content was not valid UTF-8")
.to_string();
.with_context(|| format!("File was not valid UTF-8: {}", path.display()))?
.to_owned();
let meta_path = path.with_file_name(format!("{}.meta.json", instance_name));
@@ -71,10 +71,14 @@ pub fn snapshot_lua_init(
let dir_snapshot = snapshot_dir(context, vfs, folder_path)?.unwrap();
if dir_snapshot.class_name != "Folder" {
panic!(
anyhow::bail!(
"init.lua, init.server.lua, and init.client.lua can \
only be used if the instance produced by the parent \
directory would be a Folder."
only be used if the instance produced by the containing \
directory would be a Folder.\n\n\
The directory {} turned into an instance of class {}.",
folder_path.display(),
dir_snapshot.class_name
);
}