Occasionally we’ll run into these scenarios where we need to load the system.js functions into the global context, but for whatever reason one (or more) scripts are borked.
I created on that essentially looks like the following to illustrate this point.
123
varthisFunctionShouldFail=function(){return"Fail}
When you try to execute a db.loadServerScripts() call, the entire process will fail as there is a malformed script.
This is a major pain in the ass when you have large background processes that rely heavily on internal system scripts.
In order to address this, we wrote a small script that you can run against any database to validate the internal scripts: