Why consistency matters ["horror" story]

here’s a fun bug that took me all of today to solve :triumph:

The team uses a system where we have all these services that get required/initialized on runtime by one main handler and allows services to require each other without issues.

For some reason ONE of the services I am working with is being required twice, as when I tested by putting a print at the top of the module, it printed twice… Though non of the other modules did that.

I thought maybe the handler isn’t properly caching the module when it’s first required, but that wasn’t it… otherwise, all the others would have run into this issue…

I tried commenting out the parts of other services that use this module but that didn’t work either…

I tried replacing the print with error() to see if i can find out anything, though because of how error works the handler just stops running and so I didn’t get my two errors i was hoping for…

I had no clue how this bug is happening, or how I can find the cause…

At the end of the day, one of my team mates came on and saw I was having this issue and suggested to use debug.traceback(), I had no clue that existed or how it worked. After looking it up and then using it, I immediately found my problem!

I was using the handler to require the module, however, the paths i gave the handler in each of the two other service i was requiring from were not the same…

one used game.StarterPlayer.[path] and the other users player.PlayerScripts.[path]

I did not catch that at all as I was working to find the issue, since my thoughts were set on that its an issue with me calling some function incorrectly.

take aways

  1. Always be consistent with how your code operates.
  2. debug.traceback() is a godsend!
3 Likes