Closed jpd236 closed 2 months ago
In general, deletion of Hunt
s is not particularly well-exercised. It exists in the UI, but if I remember correctly it only exists for admins, and we've almost never deleted a hunt. Deleting a hunt doesn't remove it from users.hunts
or any other sort of cascading deletion.
In this case the bug is probably more strictly in the non-null assertion at https://github.com/deathandmayhem/jolly-roger/blob/b9bcc2f567691a3eddc63756af9088979c734b7e/imports/client/components/NotificationCenter.tsx#LL964 because hunts.get
(and I suppose puzzles.get
above it) are not guaranteed to have values for those keys (i.e. precisely in this case, where a Guess
object still exists and references a Hunt
which is no longer known to the client). There's perhaps other places where the non-null assertion operator (!
) can be a lie, either transiently or persistently, in the presence of deletions.
Part of me says that of course we should fix these bugs when we find them, but there's also a part of me that wants to set the expectation that deleting hunts (or other objects that can be referenced by others in general) is probably not something that's going to get exercised a ton, and maybe it'd be better to remove the hunt-deletion feature from the UI instead. Once real humans have started interacting with a hunt in any meaningful way, it's probably a bad idea to delete things out from under them, and it's hard to say what the appropriate user experience you'd expect to generate for any users that have loaded a puzzle from that hunt or sent in guesses for that hunt before it was deleted.
Still, if we have a button for creating a hunt and deleting it, ideally that wouldn't break /everything/.
I'm not sure if this is entirely sufficient, but I just did the following:
And started hitting errors and getting a blank page:
This line was failing because
hunt
was undefined: https://github.com/deathandmayhem/jolly-roger/blob/main/imports/model-helpers.ts#L14Adding a
!hunt ||
before the!hunt.submitTemplate
worked around the issue, but I'm not sure if there's a higher-level issue with something passing a null hunt to this function that shouldn't be.