From 90982866bf8c238e4e9bfd8c2045078fbe44db66 Mon Sep 17 00:00:00 2001 From: Olivier Trepanier Date: Tue, 11 Jun 2019 16:25:47 -0700 Subject: [PATCH 1/8] Improve error message for invalid changed hooks --- src/SingleEventManager.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/SingleEventManager.lua b/src/SingleEventManager.lua index 0d2b3b82..6561bd0e 100644 --- a/src/SingleEventManager.lua +++ b/src/SingleEventManager.lua @@ -53,7 +53,14 @@ function SingleEventManager:connectEvent(key, listener) end function SingleEventManager:connectPropertyChange(key, listener) - local event = self._instance:GetPropertyChangedSignal(key) + local success, event = pcall(function() + return self._instance:GetPropertyChangedSignal(key) + end) + + if not success then + error(("Cannot get property '%s' changed signal from %s"):format(key, self._instance.ClassName), 0) + end + self:_connect(CHANGE_PREFIX .. key, event, listener) end From 3f5f2a70b5c2e8ca590a6983de23ba560b525801 Mon Sep 17 00:00:00 2001 From: Olivier Trepanier Date: Tue, 11 Jun 2019 16:33:28 -0700 Subject: [PATCH 2/8] Convert hook key to string to prevent possible bug --- src/SingleEventManager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SingleEventManager.lua b/src/SingleEventManager.lua index 6561bd0e..5d2a125e 100644 --- a/src/SingleEventManager.lua +++ b/src/SingleEventManager.lua @@ -58,7 +58,7 @@ function SingleEventManager:connectPropertyChange(key, listener) end) if not success then - error(("Cannot get property '%s' changed signal from %s"):format(key, self._instance.ClassName), 0) + error(("Cannot get property '%s' changed signal from %s"):format(tostring(key), self._instance.ClassName), 0) end self:_connect(CHANGE_PREFIX .. key, event, listener) From c2e27f725a2e250e627e0cb311780f015eeb7500 Mon Sep 17 00:00:00 2001 From: Olivier Trepanier Date: Tue, 11 Jun 2019 16:45:53 -0700 Subject: [PATCH 3/8] Add test case to verify that error is thrown --- src/SingleEventManager.spec.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/SingleEventManager.spec.lua b/src/SingleEventManager.spec.lua index 41ebc262..9d87e271 100644 --- a/src/SingleEventManager.spec.lua +++ b/src/SingleEventManager.spec.lua @@ -226,5 +226,14 @@ return function() instance.Name = "baz" expect(eventSpy.callCount).to.equal(2) end) + + it("should throw an error if the property is invalid", function() + local instance = Instance.new("Folder") + local manager = SingleEventManager.new(instance) + + expect(function() + manager:connectPropertyChange("foo", function() end) + end).to.throw() + end) end) end \ No newline at end of file From 81fe955ecb96f865b3c2c92692769e8ce2322847 Mon Sep 17 00:00:00 2001 From: jeparlefrancais <35781636+jeparlefrancais@users.noreply.github.com> Date: Fri, 14 Jun 2019 09:03:32 -0700 Subject: [PATCH 4/8] Change error message wording Co-Authored-By: Paul Doyle <37384169+ZoteTheMighty@users.noreply.github.com> --- src/SingleEventManager.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SingleEventManager.lua b/src/SingleEventManager.lua index 5d2a125e..e3d7c3cd 100644 --- a/src/SingleEventManager.lua +++ b/src/SingleEventManager.lua @@ -58,7 +58,7 @@ function SingleEventManager:connectPropertyChange(key, listener) end) if not success then - error(("Cannot get property '%s' changed signal from %s"):format(tostring(key), self._instance.ClassName), 0) + error(("Cannot subscribe to changed signal: %q is not a property of %s"):format(tostring(key), self._instance.ClassName), 0) end self:_connect(CHANGE_PREFIX .. key, event, listener) @@ -141,4 +141,4 @@ function SingleEventManager:resume() self._suspendedEventQueue = {} end -return SingleEventManager \ No newline at end of file +return SingleEventManager From 33f8b26483ab7111bd3a007fa1f491c0ca79a33d Mon Sep 17 00:00:00 2001 From: Olivier Trepanier Date: Fri, 14 Jun 2019 16:49:48 -0700 Subject: [PATCH 5/8] Reduce line length --- src/SingleEventManager.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/SingleEventManager.lua b/src/SingleEventManager.lua index e3d7c3cd..4db012c1 100644 --- a/src/SingleEventManager.lua +++ b/src/SingleEventManager.lua @@ -58,7 +58,10 @@ function SingleEventManager:connectPropertyChange(key, listener) end) if not success then - error(("Cannot subscribe to changed signal: %q is not a property of %s"):format(tostring(key), self._instance.ClassName), 0) + error(("Cannot subscribe to changed signal: %q is not a property of %s"):format( + tostring(key), + self._instance.ClassName + ), 0) end self:_connect(CHANGE_PREFIX .. key, event, listener) From e453e31212ccfb4795eab4707c0fd7b2f8679e3d Mon Sep 17 00:00:00 2001 From: Olivier Trepanier Date: Mon, 17 Jun 2019 18:08:59 -0700 Subject: [PATCH 6/8] Remove new line --- src/SingleEventManager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SingleEventManager.lua b/src/SingleEventManager.lua index 4db012c1..5293a60a 100644 --- a/src/SingleEventManager.lua +++ b/src/SingleEventManager.lua @@ -144,4 +144,4 @@ function SingleEventManager:resume() self._suspendedEventQueue = {} end -return SingleEventManager +return SingleEventManager \ No newline at end of file From 483411275b03d43d20c94023fdc291d2f2edec08 Mon Sep 17 00:00:00 2001 From: Olivier Trepanier Date: Thu, 20 Jun 2019 16:11:04 -0700 Subject: [PATCH 7/8] Append original error message to assertion --- src/SingleEventManager.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SingleEventManager.lua b/src/SingleEventManager.lua index 5293a60a..bb579c78 100644 --- a/src/SingleEventManager.lua +++ b/src/SingleEventManager.lua @@ -58,9 +58,9 @@ function SingleEventManager:connectPropertyChange(key, listener) end) if not success then - error(("Cannot subscribe to changed signal: %q is not a property of %s"):format( + error(("Cannot get changed signal on property %q: %s"):format( tostring(key), - self._instance.ClassName + event ), 0) end From b18789c3373775722c588d5d2bbf954a301a1ba5 Mon Sep 17 00:00:00 2001 From: Olivier Trepanier Date: Wed, 24 Jul 2019 17:49:35 -0700 Subject: [PATCH 8/8] Add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a80036e..1b343718 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Roact Changelog ## Unreleased Changes +* Improved the error message when an invalid changed hook name is used. ([#216](https://github.com/Roblox/roact/pull/216)) * Fixed a bug where fragments could not be used as children of an element or another fragment. ([#214](https://github.com/Roblox/roact/pull/214)) ## [1.1.0](https://github.com/Roblox/roact/releases/tag/v1.1.0) (June 3rd, 2019)