In the shell, referencing non-existent error codes on the generated ErrorCodes object gives undefined but should throw an error.
SERVER-31335 it was discovered that a test was calling
(link to code). This was a typo, and ErrorCodes.DocumentFailedValidation is undefined. At the time, the assert function assumed a falsey error code meant that any code was okay, so this assertion passed. assert.writeErrorWithCode no longer allows undefined as an error code. But we should still throw if a non-existent error code is referenced.
Per Max's suggestion
I think we'd need to have the Python script generate the ErrorCodes object as a Proxy object and make it error (or abort) if any property is accessed that isn't defined on the ErrorCodes object itself.