From 4c263bbb3e01d70a0353544b617950c5c8964609 Mon Sep 17 00:00:00 2001 From: Lucien Greathouse Date: Wed, 29 May 2019 18:40:58 -0700 Subject: [PATCH] plugin: Update to newer rbx-dom with better error handling --- plugin/modules/rbx-dom | 2 +- plugin/src/rojoValueToRobloxValue.lua | 14 ------------- plugin/src/setCanonicalProperty.lua | 30 +++++++++++++-------------- 3 files changed, 15 insertions(+), 31 deletions(-) diff --git a/plugin/modules/rbx-dom b/plugin/modules/rbx-dom index ac129152..74ec3e7d 160000 --- a/plugin/modules/rbx-dom +++ b/plugin/modules/rbx-dom @@ -1 +1 @@ -Subproject commit ac129152f250bf6a1ad51a1cbc9f9315130c8fbb +Subproject commit 74ec3e7d885868252b02f227c0e0ad86e3332120 diff --git a/plugin/src/rojoValueToRobloxValue.lua b/plugin/src/rojoValueToRobloxValue.lua index 94c57664..1e30dfde 100644 --- a/plugin/src/rojoValueToRobloxValue.lua +++ b/plugin/src/rojoValueToRobloxValue.lua @@ -7,20 +7,6 @@ local function rojoValueToRobloxValue(value) return nil end - -- TODO: Remove this once rbx_dom_weak and rbx_dom_lua agree on encoding - if value.Type == "BinaryString" then - local actualValue = "" - - for i = 1, #value.Value do - actualValue = actualValue .. string.char(i) - end - - value = { - Type = "BinaryString", - Value = actualValue, - } - end - local success, decodedValue = RbxDom.EncodedValue.decode(value) if not success then diff --git a/plugin/src/setCanonicalProperty.lua b/plugin/src/setCanonicalProperty.lua index fabbd733..eb3fd5aa 100644 --- a/plugin/src/setCanonicalProperty.lua +++ b/plugin/src/setCanonicalProperty.lua @@ -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