plugin: Update to newer rbx-dom with better error handling

This commit is contained in:
Lucien Greathouse
2019-05-29 18:40:58 -07:00
parent 420627d892
commit 4c263bbb3e
3 changed files with 15 additions and 31 deletions

View File

@@ -1,34 +1,32 @@
local RbxDom = require(script:FindFirstAncestor("Rojo").RbxDom)
local Logging = require(script.Parent.Logging)
--[[
Attempts to set a property on the given instance.
]]
local function setCanonicalProperty(instance, key, value)
if not RbxDom.CanonicalProperty.isScriptable(instance.ClassName, key) then
return false
end
-- If we don't have permissions to access this value at all, we can skip it.
local readSuccess, existingValue = RbxDom.CanonicalProperty.read(instance, key)
local readSuccess, existingValue = RbxDom.readProperty(instance, key)
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)
if existingValue.kind == RbxDom.Error.Kind.UnknownProperty
or existingValue.kind == RbxDom.Error.Kind.PropertyNotReadable then
-- this is fine
return false
else
error(("Invalid property %s on class %s: %s"):format(tostring(key), instance.ClassName, existingValue), 2)
end
-- If we don't have permission to write a property, we just silently
-- ignore it.
if existingValue.kind == RbxDom.Error.Kind.Roblox and existingValue.extra:find("lacking permission") then
return false
end
error(("Invalid property %s on class %s: %s"):format(tostring(key), instance.ClassName, tostring(existingValue)), 2)
end
local writeSuccess, err = RbxDom.CanonicalProperty.write(instance, key, value)
local writeSuccess, err = RbxDom.writeProperty(instance, key, value)
if not writeSuccess then
error(("Cannot set property %s on class %s: %s"):format(tostring(key), instance.ClassName, err), 2)
error(("Cannot set property %s on class %s: %s"):format(tostring(key), instance.ClassName, tostring(err)), 2)
end
return true