mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-20 12:45:05 +00:00
Add snapshot error handling to ChangeProcessor
This commit is contained in:
@@ -9,6 +9,7 @@ use memofs::{IoResultExt, Vfs, VfsEvent};
|
|||||||
use rbx_dom_weak::{RbxId, RbxValue};
|
use rbx_dom_weak::{RbxId, RbxValue};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
error::ErrorDisplay,
|
||||||
message_queue::MessageQueue,
|
message_queue::MessageQueue,
|
||||||
snapshot::{
|
snapshot::{
|
||||||
apply_patch_set, compute_patch_set, AppliedPatchSet, InstigatingSource, PatchSet, RojoTree,
|
apply_patch_set, compute_patch_set, AppliedPatchSet, InstigatingSource, PatchSet, RojoTree,
|
||||||
@@ -294,9 +295,15 @@ fn compute_and_apply_changes(tree: &mut RojoTree, vfs: &Vfs, id: RbxId) -> Optio
|
|||||||
// starting at that path and use it as the source for
|
// starting at that path and use it as the source for
|
||||||
// our patch.
|
// our patch.
|
||||||
|
|
||||||
let snapshot = snapshot_from_vfs(&metadata.context, &vfs, &path)
|
let snapshot = match snapshot_from_vfs(&metadata.context, &vfs, &path) {
|
||||||
.expect("snapshot failed")
|
Ok(maybe_snapshot) => {
|
||||||
.expect("snapshot did not return an instance");
|
maybe_snapshot.expect("snapshot did not return an instance")
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
log::error!("Snapshot error: {}", ErrorDisplay(err));
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let patch_set = compute_patch_set(&snapshot, &tree, id);
|
let patch_set = compute_patch_set(&snapshot, &tree, id);
|
||||||
apply_patch_set(tree, patch_set)
|
apply_patch_set(tree, patch_set)
|
||||||
@@ -320,15 +327,21 @@ fn compute_and_apply_changes(tree: &mut RojoTree, vfs: &Vfs, id: RbxId) -> Optio
|
|||||||
// there might be information associated with our instance from
|
// there might be information associated with our instance from
|
||||||
// the project file, we snapshot the entire project node again.
|
// the project file, we snapshot the entire project node again.
|
||||||
|
|
||||||
let snapshot = snapshot_project_node(
|
let snapshot_result = snapshot_project_node(
|
||||||
&metadata.context,
|
&metadata.context,
|
||||||
&project_path,
|
&project_path,
|
||||||
instance_name,
|
instance_name,
|
||||||
project_node,
|
project_node,
|
||||||
&vfs,
|
&vfs,
|
||||||
)
|
);
|
||||||
.expect("snapshot failed")
|
|
||||||
.expect("snapshot did not return an instance");
|
let snapshot = match snapshot_result {
|
||||||
|
Ok(maybe_snapshot) => maybe_snapshot.expect("snapshot did not return an instance"),
|
||||||
|
Err(err) => {
|
||||||
|
log::error!("Snapshot error: {}", ErrorDisplay(err));
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let patch_set = compute_patch_set(&snapshot, &tree, id);
|
let patch_set = compute_patch_set(&snapshot, &tree, id);
|
||||||
apply_patch_set(tree, patch_set)
|
apply_patch_set(tree, patch_set)
|
||||||
|
|||||||
18
src/error.rs
Normal file
18
src/error.rs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
use std::{error::Error, fmt};
|
||||||
|
|
||||||
|
/// Wrapper type to print errors with source-chasing.
|
||||||
|
pub struct ErrorDisplay<E>(pub E);
|
||||||
|
|
||||||
|
impl<E: Error> fmt::Display for ErrorDisplay<E> {
|
||||||
|
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
writeln!(formatter, "{}", self.0)?;
|
||||||
|
|
||||||
|
let mut current_err: &dyn Error = &self.0;
|
||||||
|
while let Some(source) = current_err.source() {
|
||||||
|
writeln!(formatter, " caused by {}", source)?;
|
||||||
|
current_err = &*source;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,6 +10,7 @@ mod tree_view;
|
|||||||
mod auth_cookie;
|
mod auth_cookie;
|
||||||
mod change_processor;
|
mod change_processor;
|
||||||
mod common_setup;
|
mod common_setup;
|
||||||
|
mod error;
|
||||||
mod glob;
|
mod glob;
|
||||||
mod message_queue;
|
mod message_queue;
|
||||||
mod multimap;
|
mod multimap;
|
||||||
|
|||||||
Reference in New Issue
Block a user