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
question concerning the right handling of fixing a (rare) bug in an already published migration file (lua)
Re: question concerning the right handling of fixing a (rare) bug in an already published migration file (lua)
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).
Re: question concerning the right handling of fixing a (rare) bug in an already published migration file (lua)
@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?
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?
Re: question concerning the right handling of fixing a (rare) bug in an already published migration file (lua)
You can also run migration code in the on_configuration_changed event after checking if the buggy version of your mod was NOT installed
Re: question concerning the right handling of fixing a (rare) bug in an already published migration file (lua)
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.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?
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.
Maintainer of Auto Deconstruct, Cargo Ships, Vehicle Wagon, Honk, Shortwave.