Modding API: Add exception handler and option to ignore exceptions

Things that we aren't going to implement
Post Reply
mrvn
Smart Inserter
Smart Inserter
Posts: 5709
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Modding API: Add exception handler and option to ignore exceptions

Post by mrvn »

TL;DR
Mods should be able to provide an exception handler and the game should have the option to ignore an exception instead of aborting the game.
What ?
Mods should be able to provide an exception handler that gets called when an exception occurs. The handler should be able to return one of 4 values:

1) Critical failure

The mod was unable to recover from the error and the game should abort like now.

2) Warning

The mod has probably recovered from the error but the game should show a pop-up about the error with the default to continue.

3) Retry

The mod has reset it's internal logic so the action causing the exception should be retried (e.g. events should be triggered again). A double failure is then critical. This could be rate limited, too, see 4.

4) Ignore

The mod doesn't have internal state that would break by ignoring an exception so the game should just continue anyway. If this happens too often, e.g. more than 10 times in a minute, the game should show the usual error pop-up.


On top of that the error pop-up should have more options. First there should be an option to save the game. On load the last LUA callback should be retried. This would often allow fixing the mod and continue the game without loosing everything since the last save. There should also be an ignore button that lets the game simply continue and maybe an option to remove the event handler that failed. While that would break functionality in many mods this would allow e.g. making a blueprint with the latest changes, reloading a save and reapplying all the work done since then. Or simply play on without the broken mod.
Why ?
With many mods interacting it is easy for errors to happen, especially on updates. It is annoying to loose all the work since the last autosave every time that happens. Looking at the mods source I often find that the error has no greater effect. E.g. I click on a button of the mod and the GUI fails to open. The only problem is that the GUI won't open. No need to abort the game. I can just not click the button and keep on playing for now. Or save the game, fix the mod and reload.

While there are many cases where an error has follow up consequences or just will error again and again and again there are also many cases where it is perfectly save to just keep on playing or play with the mods functionality reduced. This should be a choice for the user.

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Modding API: Add exception handler and option to ignore exceptions

Post by DaveMcW »

You need more pcall in your life.

eduran
Filter Inserter
Filter Inserter
Posts: 344
Joined: Fri May 09, 2014 2:52 pm
Contact:

Re: Modding API: Add exception handler and option to ignore exceptions

Post by eduran »

If you really want to go down that route: https://www.lua.org/pil/8.4.html. With that it is already possible for mods to intercept errors and decide how to continue.

And you are rather daring to post this in Rseding's view. I expect him to bust down your door (or maybe just move this to "won't implement") and tell you how terrible an idea this is any second :D

Bilka
Factorio Staff
Factorio Staff
Posts: 3133
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Modding API: Add exception handler and option to ignore exceptions

Post by Bilka »

eduran wrote:
Mon Apr 22, 2019 5:02 pm
And you are rather daring to post this in Rseding's view. I expect him to bust down your door (or maybe just move this to "won't implement") and tell you how terrible an idea this is any second :D
Maybe that's why this was posted in ideas and suggestions 🤔 Well, I moved it here and it's too late now :p
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13209
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Modding API: Add exception handler and option to ignore exceptions

Post by Rseding91 »

eduran wrote:
Mon Apr 22, 2019 5:02 pm
... And you are rather daring to post this in Rseding's view. I expect him to bust down your door (or maybe just move this to "won't implement") and tell you how terrible an idea this is any second :D
Correct. My answer to this is: No.

When a Lua error happens the game aborts the current call stack and halts the game to show the error and exit to the main menu. It's not in a recoverable state and never will be.

Factorio does not do try-catch-continue in the main update loop - that's an absolute terrible way to write code and should never be done. If I could figure out a way to remove the ability for mods to use pcall without breaking the rest of the game I would do it.

If your mod errors then the solution is for you to fix your mod. If you're using a mod that errors then the solution is to stop using that mod or get the mod author to fix it.

I'm never going to make it easy for people to do what modded minecraft has become where something as simple as teleporting the player can produce 39 errors and spam the log file with 6 pages of try-catch-continue errors.
If you want to get ahold of me I'm almost always on Discord.

Post Reply

Return to “Won't implement”