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

fix: error if cleanup method no longer exists #191

Closed
wants to merge 1 commit into from

Conversation

christopher-buss
Copy link
Contributor

I have an issue where I was passing in a method to a Trove, but the method usually is cleaned up by the time the trove wants to clear it, therefore the destroy method no longer exists, so it throws an error. This just checks to make sure the cleanup method exists before we try to use it.

@christopher-buss
Copy link
Contributor Author

The only issue with this is objects that do not have a valid method would just get "silently ignored", and may be hard to track down the problem. But I don't know how to differentiate between a "hey my cleanup method doesn't exist anymore it's okay", and "oh I supplied the wrong cleanup method this was never going to work".

@Sleitnick
Copy link
Owner

If a user accidentally puts in the wrong cleanup method name, this would cause it to silently fail. I also am unsure why your method itself would be gone? I don't see a reason why you'd want to clear out the actual methods of an object; that seems like a symptom of something else going on.

I would also argue that cleanup methods should be idempotent; you should be able to call them more than once without adverse effects.

@christopher-buss
Copy link
Contributor Author

In my case I am in a legacy project that is using a mixture of janitors and troves. I was passing in a janitor to the trove as it is returned that way to me by part of the library, but the janitor may have already destroyed itself by the time the trove gets around to cleaning up the janitor, hence the janitor is unusable and all of it's methods have gone.

But I do agree. This could cause silent failiures which are probably more pressing than my use case.

I've managed to work around this by removing the janitor from the trove if the janitor cleans up:

local janitor = -- get some janitor here
local toRemove = self._trove:Add(janitor)
janitor:Add(function()
    self._trove:Remove(toRemove)
end)

It's a bit of an.. interesting solution, but is probably the better way to go about this than allowing silent failiures.

Thanks for the response, I will close this PR!

@Sleitnick
Copy link
Owner

Glad you were able to find a workaround!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants