Catch more sync failures (#845)

- Catch removal failures
- Catch name change failures
- Don't remove IDs for instances if they weren't actually destroyed
This commit is contained in:
boatbomber
2024-01-31 17:07:01 -08:00
committed by GitHub
parent 106a01223e
commit f3b0b0027e
3 changed files with 36 additions and 18 deletions

View File

@@ -113,27 +113,29 @@ end
function InstanceMap:destroyInstance(instance) function InstanceMap:destroyInstance(instance)
local id = self.fromInstances[instance] local id = self.fromInstances[instance]
local descendants = instance:GetDescendants()
instance:Destroy()
-- After the instance is successfully destroyed,
-- we can remove all the id mappings
if id ~= nil then if id ~= nil then
self:removeId(id) self:removeId(id)
end end
for _, descendantInstance in ipairs(instance:GetDescendants()) do for _, descendantInstance in descendants do
self:removeInstance(descendantInstance) self:removeInstance(descendantInstance)
end end
instance:Destroy()
end end
function InstanceMap:destroyId(id) function InstanceMap:destroyId(id)
local instance = self.fromIds[id] local instance = self.fromIds[id]
self:removeId(id)
if instance ~= nil then if instance ~= nil then
for _, descendantInstance in ipairs(instance:GetDescendants()) do self:destroyInstance(instance)
self:removeInstance(descendantInstance) else
end -- There is no instance with this id, so we can just remove the id
-- without worrying about instance destruction
instance:Destroy() self:removeId(id)
end end
end end

View File

@@ -437,8 +437,13 @@ function PatchTree.updateMetadata(tree, patch, instanceMap, unappliedPatch)
continue continue
end end
for _, change in node.changeList do for _, change in node.changeList do
if not failedChange.changedProperties[change[1]] then local property = change[1]
-- This change didn't fail local propertyFailedToApply = if property == "Name"
then failedChange.changedName ~= nil -- Name is not in changedProperties, so it needs a special case
else failedChange.changedProperties[property] ~= nil
if not propertyFailedToApply then
-- This change didn't fail, no need to mark
continue continue
end end
if change[4] == nil then if change[4] == nil then
@@ -446,7 +451,7 @@ function PatchTree.updateMetadata(tree, patch, instanceMap, unappliedPatch)
else else
change[4].isWarning = true change[4].isWarning = true
end end
Log.trace(" Marked property as warning: {}.{}", node.name, change[1]) Log.trace(" Marked property as warning: {}.{}", node.name, property)
end end
end end
for failedAdditionId in unappliedPatch.added do for failedAdditionId in unappliedPatch.added do

View File

@@ -25,10 +25,15 @@ local function applyPatch(instanceMap, patch)
local unappliedPatch = PatchSet.newEmpty() local unappliedPatch = PatchSet.newEmpty()
for _, removedIdOrInstance in ipairs(patch.removed) do for _, removedIdOrInstance in ipairs(patch.removed) do
if Types.RbxId(removedIdOrInstance) then local ok = pcall(function()
instanceMap:destroyId(removedIdOrInstance) if Types.RbxId(removedIdOrInstance) then
else instanceMap:destroyId(removedIdOrInstance)
instanceMap:destroyInstance(removedIdOrInstance) else
instanceMap:destroyInstance(removedIdOrInstance)
end
end)
if not ok then
table.insert(unappliedPatch.removed, removedIdOrInstance)
end end
end end
@@ -170,7 +175,13 @@ local function applyPatch(instanceMap, patch)
end end
if update.changedName ~= nil then if update.changedName ~= nil then
instance.Name = update.changedName local ok = pcall(function()
instance.Name = update.changedName
end)
if not ok then
unappliedUpdate.changedName = update.changedName
partiallyApplied = true
end
end end
if update.changedMetadata ~= nil then if update.changedMetadata ~= nil then