-
Notifications
You must be signed in to change notification settings - Fork 143
Throw a nicer error when failing to set primitive properties #21
Throw a nicer error when failing to set primitive properties #21
Conversation
Neat! Does it make sense to move this error catching into |
I would have done it, but I think that'd be worth it, all things considered. I'll change the PR in a few minutes. |
lib/Reconciler.lua
Outdated
Used in _setRbxProp to avoid creating a new closure for every property set. | ||
]] | ||
|
||
local function _rawSet(rbx, key, value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand the allusion to rawset
with this function name, but this version isn't very raw, is it? Would there be any problem with just naming this function set
?
As a small style nitpick, you should remove the blank line after the documentation comment to group it visually with this function.
) | ||
|
||
error(message, 0) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we introduce nice stack trace logic on the error cases below as well?
I haven't seen them ever come up in real code, but giving them equally pleasant messages would be good. I can understand if you'd want to push that into a different PR as well, though.
Q: The Travis CI build is failing because line 449 is too long. Should I break the string across multiple lines or just suppress the line length warning for this line ( |
I think suppressing the line length warning is okay in this case. After that, this looks good to me! Do you think there will be any significant performance impacts here? This does introduce a |
I ran some benchmarks using the same methodology as my blog post. For comparison, here are results without this PR:
Here are the results with the PR applied:
Marginally slower, and the difference between the two scenarios gets faster over time (branch prediction? CPU-level caching? some Lua optimization that speeds up hot code paths? I have no idea). I think that's acceptable for this. If the overhead gets to be too much, one option is to only use |
That performance gradient is super weird! Looks like performance should be just fine. |
This fixes #19. It adds a prettier error message (with stack trace shown if
Roact.DEBUG_ENABLE
has been called; stack trace is drawn from the new element, not the old one) when reconciliation tries to set a primitive element property to an invalid type (or anything that causesReconciler._setRbxProp
to throw).Example stack trace
Roact.DEBUG_ENABLE
has been called.Remarks
I'm not happy with the code duplication, but extracting it into a function will add another line to the stack trace - is that something that's acceptable if it means eliminating the code duplication?
There are no tests for this behavior, like most of Reconciler - I'm not sure if lemur supports type-checks on Roblox properties at the moment. If it does I'll write some tests for this.
I've suppressed the line-number reporting as much as possible (read: not a lot) by using
error(message, 0)
. This removes the initial line that reports the direct source of the error (...Roact.Reconciler:line#
). Since this is an error raised by Roact, not a bug in Roact, I'm assuming we want to include as little information about Roact's internals to cut down on clutter.