Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve errors when an item no longer exists #354

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ccutrer
Copy link
Contributor

@ccutrer ccutrer commented Nov 8, 2024

If a user keeps a ref to an item, and that item disappears, calling a method on that item will now raise a helpful StaleProxyError, instead of a NoMethodError on nil

The proxy code was significantly refactored, and Thing will also inherit the same stale proxy I also removed the $things registry lookup on every access of a thing, using the same event subscriber mechanism as Item.

I also moved several methods from GenericItem to Item, so that Proxy can detect that those methods should exist even for dummy/stale items.

@ccutrer ccutrer added the bug Something isn't working label Nov 8, 2024
@jimtng
Copy link
Contributor

jimtng commented Nov 9, 2024

How does it behave when referring to an item that had never existed in the first place?

Enumerable and predicate methods will now behave better when they refer
to stale proxies - filtering methods will just remove them. I run into
this occasionally when I have multiple rules firing, and some of them
are adding or removing items - and calling items.locations would raise
a NoMethodError for #location? due to a race condition. This should no
longer happen - it will just ignore the now-stale items.

Signed-off-by: Cody Cutrer <[email protected]>
@ccutrer ccutrer marked this pull request as draft November 17, 2024 12:17
If a user keeps a ref to an item, and that item disappears,
calling a method on that item will now raise a helpful
StaleProxyError, instead of a NoMethodError on nil

The proxy code was significantly refactored, and Thing
proxies will also inherit the same stale proxy handling.
I also removed the $things registry lookup on every access
of a thing, using the same event subscriber mechanism as Item.

I also moved several methods from GenericItem to Item, so that
Proxy can detect that those methods should exist even for
dummy/stale items.

Signed-off-by: Cody Cutrer <[email protected]>
@ccutrer
Copy link
Contributor Author

ccutrer commented Nov 17, 2024

Exactly as before - it depends on the context. If it's a context that we're expecting an item (and thus dummy item creation is enabled), it will just create the item proxy, even though an item doesn't exist. In other contexts, it will still raise an error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants