Skip to content

Commit

Permalink
Catch more sync failures (#845)
Browse files Browse the repository at this point in the history
- Catch removal failures
- Catch name change failures
- Don't remove IDs for instances if they weren't actually destroyed
  • Loading branch information
boatbomber authored Feb 1, 2024
1 parent 106a012 commit f3b0b00
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 18 deletions.
22 changes: 12 additions & 10 deletions plugin/src/InstanceMap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -113,27 +113,29 @@ end
function InstanceMap:destroyInstance(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
self:removeId(id)
end

for _, descendantInstance in ipairs(instance:GetDescendants()) do
for _, descendantInstance in descendants do
self:removeInstance(descendantInstance)
end

instance:Destroy()
end

function InstanceMap:destroyId(id)
local instance = self.fromIds[id]
self:removeId(id)

if instance ~= nil then
for _, descendantInstance in ipairs(instance:GetDescendants()) do
self:removeInstance(descendantInstance)
end

instance:Destroy()
self:destroyInstance(instance)
else
-- There is no instance with this id, so we can just remove the id
-- without worrying about instance destruction
self:removeId(id)
end
end

Expand Down
11 changes: 8 additions & 3 deletions plugin/src/PatchTree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -437,16 +437,21 @@ function PatchTree.updateMetadata(tree, patch, instanceMap, unappliedPatch)
continue
end
for _, change in node.changeList do
if not failedChange.changedProperties[change[1]] then
-- This change didn't fail
local property = change[1]
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
end
if change[4] == nil then
change[4] = { isWarning = true }
else
change[4].isWarning = true
end
Log.trace(" Marked property as warning: {}.{}", node.name, change[1])
Log.trace(" Marked property as warning: {}.{}", node.name, property)
end
end
for failedAdditionId in unappliedPatch.added do
Expand Down
21 changes: 16 additions & 5 deletions plugin/src/Reconciler/applyPatch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@ local function applyPatch(instanceMap, patch)
local unappliedPatch = PatchSet.newEmpty()

for _, removedIdOrInstance in ipairs(patch.removed) do
if Types.RbxId(removedIdOrInstance) then
instanceMap:destroyId(removedIdOrInstance)
else
instanceMap:destroyInstance(removedIdOrInstance)
local ok = pcall(function()
if Types.RbxId(removedIdOrInstance) then
instanceMap:destroyId(removedIdOrInstance)
else
instanceMap:destroyInstance(removedIdOrInstance)
end
end)
if not ok then
table.insert(unappliedPatch.removed, removedIdOrInstance)
end
end

Expand Down Expand Up @@ -170,7 +175,13 @@ local function applyPatch(instanceMap, patch)
end

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

if update.changedMetadata ~= nil then
Expand Down

0 comments on commit f3b0b00

Please sign in to comment.