mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-25 07:06:12 +00:00
Refactor ChangeProcessor loop to get rid of panics
This commit is contained in:
@@ -272,12 +272,11 @@ fn compute_and_apply_changes(tree: &mut RojoTree, vfs: &Vfs, id: RbxId) -> Optio
|
|||||||
let instigating_source = match &metadata.instigating_source {
|
let instigating_source = match &metadata.instigating_source {
|
||||||
Some(path) => path,
|
Some(path) => path,
|
||||||
None => {
|
None => {
|
||||||
log::warn!(
|
log::error!(
|
||||||
"Instance {} did not have an instigating source, but was considered for an update.",
|
"Instance {} did not have an instigating source, but was considered for an update.",
|
||||||
id
|
id
|
||||||
);
|
);
|
||||||
log::warn!("This is a Rojo bug. Please file an issue!");
|
log::error!("This is a bug. Please file an issue!");
|
||||||
|
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -285,19 +284,21 @@ fn compute_and_apply_changes(tree: &mut RojoTree, vfs: &Vfs, id: RbxId) -> Optio
|
|||||||
// How we process a file change event depends on what created this
|
// How we process a file change event depends on what created this
|
||||||
// file/folder in the first place.
|
// file/folder in the first place.
|
||||||
let applied_patch_set = match instigating_source {
|
let applied_patch_set = match instigating_source {
|
||||||
InstigatingSource::Path(path) => {
|
InstigatingSource::Path(path) => match vfs.metadata(path).with_not_found() {
|
||||||
let maybe_meta = vfs.metadata(path).with_not_found().unwrap();
|
Ok(Some(_)) => {
|
||||||
|
// Our instance was previously created from a path and that
|
||||||
match maybe_meta {
|
// path still exists. We can generate a snapshot starting at
|
||||||
Some(_meta) => {
|
// that path and use it as the source for our patch.
|
||||||
// Our instance was previously created from a path and
|
|
||||||
// that path still exists. We can generate a snapshot
|
|
||||||
// starting at that path and use it as the source for
|
|
||||||
// our patch.
|
|
||||||
|
|
||||||
let snapshot = match snapshot_from_vfs(&metadata.context, &vfs, &path) {
|
let snapshot = match snapshot_from_vfs(&metadata.context, &vfs, &path) {
|
||||||
Ok(maybe_snapshot) => {
|
Ok(Some(snapshot)) => snapshot,
|
||||||
maybe_snapshot.expect("snapshot did not return an instance")
|
Ok(None) => {
|
||||||
|
log::error!(
|
||||||
|
"Snapshot did not return an instance from path {}",
|
||||||
|
path.display()
|
||||||
|
);
|
||||||
|
log::error!("This may be a bug!");
|
||||||
|
return None;
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
log::error!("Snapshot error: {}", ErrorDisplay(err));
|
log::error!("Snapshot error: {}", ErrorDisplay(err));
|
||||||
@@ -308,9 +309,9 @@ fn compute_and_apply_changes(tree: &mut RojoTree, vfs: &Vfs, id: RbxId) -> Optio
|
|||||||
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)
|
||||||
}
|
}
|
||||||
None => {
|
Ok(None) => {
|
||||||
// Our instance was previously created from a path, but
|
// Our instance was previously created from a path, but that
|
||||||
// that path no longer exists.
|
// path no longer exists.
|
||||||
//
|
//
|
||||||
// We associate deleting the instigating file for an
|
// We associate deleting the instigating file for an
|
||||||
// instance with deleting that instance.
|
// instance with deleting that instance.
|
||||||
@@ -320,8 +321,12 @@ fn compute_and_apply_changes(tree: &mut RojoTree, vfs: &Vfs, id: RbxId) -> Optio
|
|||||||
|
|
||||||
apply_patch_set(tree, patch_set)
|
apply_patch_set(tree, patch_set)
|
||||||
}
|
}
|
||||||
|
Err(err) => {
|
||||||
|
log::error!("Error processing filesystem change: {}", ErrorDisplay(err));
|
||||||
|
return None;
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
|
||||||
InstigatingSource::ProjectNode(project_path, instance_name, project_node) => {
|
InstigatingSource::ProjectNode(project_path, instance_name, project_node) => {
|
||||||
// This instance is the direct subject of a project node. Since
|
// This instance is the direct subject of a project node. Since
|
||||||
// there might be information associated with our instance from
|
// there might be information associated with our instance from
|
||||||
@@ -336,9 +341,14 @@ fn compute_and_apply_changes(tree: &mut RojoTree, vfs: &Vfs, id: RbxId) -> Optio
|
|||||||
);
|
);
|
||||||
|
|
||||||
let snapshot = match snapshot_result {
|
let snapshot = match snapshot_result {
|
||||||
Ok(maybe_snapshot) => maybe_snapshot.expect("snapshot did not return an instance"),
|
Ok(Some(snapshot)) => snapshot,
|
||||||
|
Ok(None) => {
|
||||||
|
log::error!("Snapshot did not return an instance from a project node.");
|
||||||
|
log::error!("This is a bug!");
|
||||||
|
return None;
|
||||||
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
log::error!("Snapshot error: {}", ErrorDisplay(err));
|
log::error!("{}", ErrorDisplay(err));
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user