question concerning the right handling of fixing a (rare) bug in an already published migration file (lua)

Place to get help with not working mods / modding interface.
xyzzycgn
Burner Inserter
Burner Inserter
Posts: 14
Joined: Tue Dec 24, 2024 7:37 pm
Contact:

question concerning the right handling of fixing a (rare) bug in an already published migration file (lua)

Post by xyzzycgn »

In one of my mods I have a faulty (lua) migration script that triggers in some rare cases a nil access and I would like to fix that,
but I am not completely sure what's the correct way to do that.

As far as I understood, migration files are only run once for a certain save file (if that migration isn't contained
in the save file), so I would assume that could fix the bug and publish it with a new version of the mod. For those save files which already
already contain the older (buggy) version it shouldn't be executed again, but for the others, the new (corrected) one should be executed.

Is this right or did I understand sth wrong?

Thx for your help

xyzzycgn
User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 4188
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: question concerning the right handling of fixing a (rare) bug in an already published migration file (lua)

Post by boskid »

Save files are only recording names of migrations that were applied, which means for a lua migration to run there must be 2 facts fulfilled: 1/ migration file must be present and 2/ name of that migration file was not recorded as already applied. If you remove a migration then it will simply not apply anymore, If you want your fixed migration to run it will have to have a different name (if not, then it wont apply if the previous version was already applied).
xyzzycgn
Burner Inserter
Burner Inserter
Posts: 14
Joined: Tue Dec 24, 2024 7:37 pm
Contact:

Re: question concerning the right handling of fixing a (rare) bug in an already published migration file (lua)

Post by xyzzycgn »

@boskid Thx for your quick reponse

As save files for which the migration already has been applied didn't trigger the fault (and have the desired state), IMO there
only a need for running the corrected version for save files for which it hasn't been applied yet, ecspecially there's
no need for rerunning it again for the former ones.

So republishing the corrected version (with the same name) for only the later ones sounds valid for me - or do you see any flaws?
Natha
Filter Inserter
Filter Inserter
Posts: 283
Joined: Sun Mar 15, 2015 1:48 pm
Contact:

Re: question concerning the right handling of fixing a (rare) bug in an already published migration file (lua)

Post by Natha »

You can also run migration code in the on_configuration_changed event after checking if the buggy version of your mod was NOT installed
robot256
Smart Inserter
Smart Inserter
Posts: 1274
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: question concerning the right handling of fixing a (rare) bug in an already published migration file (lua)

Post by robot256 »

xyzzycgn wrote: Wed Sep 24, 2025 9:46 am @boskid Thx for your quick reponse

As save files for which the migration already has been applied didn't trigger the fault (and have the desired state), IMO there
only a need for running the corrected version for save files for which it hasn't been applied yet, ecspecially there's
no need for rerunning it again for the former ones.

So republishing the corrected version (with the same name) for only the later ones sounds valid for me - or do you see any flaws?
I did this with a lot of migration files when updating mods to 2.0. Then added new migrations to fix whatever broke during the 2.0 upgrade. Maybe not strictly necessary to keep them all, but that's what I did and it worked.
My mods: Multiple Unit Train Control, RGB Pipes, Shipping Containers, Rocket Log, Smart Artillery Wagons.
Maintainer of Auto Deconstruct, Cargo Ships, Vehicle Wagon, Honk, Shortwave.
Post Reply

Return to “Modding help”