Random `.startsWith is not a function` bug

  • Randomly will begin to receive the following error stack, after a while it sometimes just stops.


    TypeError: role.startsWith is not a function
    at Object.run (SpawnManager:75:22)
    at Object.wrap (screeps-profiler:272:12)
    at Object.module.exports.loop (main:18:12)
    at __mainLoop:1:52
    at ContextifyScript.Script.runInContext (vm.js:35:29)

  • When it's happening, right before that error do a `console.log(JSON.stringify(role))` and see what's in role.

  • sparr: role is creep.memory.role, inside a loop of Game.creeps.

    All of my creeps have a role, and it makes no sense for the error to be intermittent.

  • That's what it's supposed to be. Log it to find out what it actually is.

  • I failed to elucidate properly.


    This code has run for weeks properly on the live world.


    There is no rhyme or reason for it to intermittently fail on a private server, unless something wonky is going on in the server.

  • Yes, and the first step to diagnosing what is going wrong in the private server is to see what role contains when the error happens. I didn't say it was a problem with your code, just that modifying your code is the quickest way to get insight into the problem.