From 7b84fce737b559034962a676074b3993d53ee114 Mon Sep 17 00:00:00 2001 From: Lucien Greathouse Date: Thu, 10 Jan 2019 16:57:44 -0800 Subject: [PATCH] Fix syncing projects that mention properties with elevated permissions. Permission errors aren't reported since I'm not sure what the user could do about them. Some properties can be set in the model format but not in live-sync mode, like HttpEnabled. --- plugin/src/Reconciler.lua | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/plugin/src/Reconciler.lua b/plugin/src/Reconciler.lua index db0728e2..df925325 100644 --- a/plugin/src/Reconciler.lua +++ b/plugin/src/Reconciler.lua @@ -67,15 +67,34 @@ local function setProperty(instance, key, value) return end - local ok, err = pcall(function() - if instance[key] ~= value then + -- If we don't have permissions to access this value at all, we can skip it. + local readSuccess, existingValue = pcall(function() + return instance[key] + end) + + if not readSuccess then + -- An error will be thrown if there was a permission issue or if the + -- property doesn't exist. In the latter case, we should tell the user + -- because it's probably their fault. + if existingValue:find("lacking permission") then + Logging.trace("Permission error reading property %s on class %s", tostring(key), instance.ClassName) + return + else + error(("Invalid property %s on class %s: %s"):format(tostring(key), instance.ClassName, existingValue), 2) + end + end + + local writeSuccess, err = pcall(function() + if existingValue ~= value then instance[key] = value end end) - if not ok then + if not writeSuccess then error(("Cannot set property %s on class %s: %s"):format(tostring(key), instance.ClassName, err), 2) end + + return true end local Reconciler = {}