I tried a couple different ways to reproduce this with just IR and Krastorio2 installed and wasn't able to. However I did manage to get this same error to occur when tinkering via /editor.
How that block of code works was re-worked for 0.8.7 anyway (to support per-player label toggling), and I can't reproduce the error using /editor any longer. Can you give it a try and let me know?
If it's still happening, if you can upload a savefile somewhere, that'd be helpful.