FancyModLoader icon indicating copy to clipboard operation
FancyModLoader copied to clipboard

Add mechanism for mods to abort loading

Open UpcraftLP opened this issue 7 months ago • 5 comments

Sometimes, a mod needs to abort the loading process and have the user close or restart the game.

The best way to do so seems to be via ModLoader.addLoadingIssue() and passing an issue with severity ERROR; however, this method is marked as @ApiStatus.Internal, so mods probably should not be using it.

Either unmark it as internal, or add a proper way for mods to abort the loading process.

UpcraftLP avatar May 22 '25 00:05 UpcraftLP

Have you tried throwing a ModLoadingException? :-P

shartte avatar May 22 '25 07:05 shartte

Have you tried throwing a ModLoadingException? :-P

That does not quite work because it gets double-wrapped (there's a catch for Throwable which then gets wrapped in a ModLoadingException without care for whether it already is one)

throwing ModLoadingException:

Image


adding to the list manually via ModLoader.addLoadingIssue():

Image

UpcraftLP avatar May 22 '25 07:05 UpcraftLP

Don't use addLoadingIssue, you can't guarantee that the loader will ever check that again depending on where you do it.

If your plan is to actually ask the user to restart the game, I actually wanted to add a specific mechanism for requesting that for other reasons.

However: We'd need to check the double wrap, really. Usually we do check for ModLoadingExceptions.

shartte avatar May 22 '25 07:05 shartte

Don't use addLoadingIssue, you can't guarantee that the loader will ever check that again depending on where you do it.

Fair enough

If your plan is to actually ask the user to restart the game, I actually wanted to add a specific mechanism for requesting that for other reasons.

My plan is to use a GraphicsBootstrapper in some specific circumstances; I dont want to ship the main mod as jar-in-jar file, so I opted to ship a separate jar for the bootstrap service and extract it only when necessary, then ask the user to restart the game to get it loaded (currently by means of throwing a ModLoadingException).

However: We'd need to check the double wrap, really. Usually we do check for ModLoadingExceptions.

That would be great, yes

UpcraftLP avatar May 22 '25 07:05 UpcraftLP

My plan is to use a GraphicsBootstrapper in some specific circumstances; I dont want to ship the main mod as jar-in-jar file, so I opted to ship a separate jar for the bootstrap service and extract it only when necessary, then ask the user to restart the game to get it loaded (currently by means of throwing a ModLoadingException).

You do realize your mod will likely be excluded from ATM for that, yes?

shartte avatar May 22 '25 07:05 shartte