From https://wildfiregames.com/forum/index.php?/topic/22650-alpha-22-resourcesupplytype-is-undefined/
In some rare cases, the loop on events.TrainingFinished may include entities that have already been destroyed, and then pass undefined to setMetadata (there is already this check in the loops on f.e. ConstructionFinished and ChangedEntityTemplateInfo).