As part of Audience Designations, we are changing how REST module enabling works, and migrating existing modules to the new system. See the parent and grandparent tasks for more context and details.
One barrier to this is that Router::buildModuleMap() throws an exception if an attempt is made to enable the same module (or flat route file) twice.
If the conditions for this exception are met, this throws an exception on any rest.php call. In other words, it completely shuts down the MW REST API framework by throwing an exception in ANY attempt call ANY endpoint, not just endpoints in the duplicate module/file.
This may have made sense when we had few routes files and the module system did not exist. Now, it is dangerous, and has caused a beta outage. See T415771: REST API broken on beta sites. For full disclosure, the patch responsible for that was created by the author of this task.
Reconsider this exception logic and adjust to make the consequence less catastrophic (or perhaps remove them entirely). There seem to be no negative repercussions for attempting to enable the same module twice, so it is possible that we could simply detect this situation and no-op any duplicate attempts. If investigation shows that there is a good reason to not do that, we should consider alternatives to report the misconfiguration without shutting down the entire system.
As a stretch goal, also consider the other exception in that same function. In similar fashion, a mistake in one module file can bring down the entire rest.php subsystem. A less drastic way to handle this might be prudent.