are you removed a mod?
Actually, that could be the solution. I'm testing a mod, so I copied a real game's save file to the folder with my testing version of Factorio. I only have a small part of the mods from the real game there, so lots of stuff was removed when I first loaded that file. The error occurred during testing, so I had loaded an autosave of the migrated file (that's why I didn't think of removed recipes in the first place).
Haven't looked at your code yet, but I guess you should check recipes and remove non-existing ones in on_configuration_changed().