Throwing a mishap in `RenderedSpell.cast` crashes the game
object-Object opened this issue ยท 1 comments
Summary
Mishaps thrown in side effects, including AttemptSpell, are not caught by the VM and crash the game/server. For example: https://mclo.gs/6jEWQAo
This was supposed to be fixed by #630, but that PR missed the fact that Mishap extends Throwable, not Exception, so the following code does not catch mishaps:
This is a pretty common mistake in addons, especially since I don't think we've really documented that you're not supposed to throw mishaps in RenderedSpell subclasses.
Potential solutions
The simple fix would be to add another catch block specifically for mishaps. We should also document that mishaps should not be thrown in RenderedSpell.cast implementations.
However, I think the proper fix would be to change the base class of Mishap to Exception or RuntimeException. I don't really see a valid reason for mishaps not to be exceptions. As it currently stands, to catch mishaps, you either need to catch Throwable, which is bad practice since that also includes things like OutOfMemoryError and StackOverflowError; or specifically catch Mishap along with / instead of Exception, which is why this issue occurred in the first place.