[SERVER-32663] Make it an error to reference a nonexistent error code via JavaScript Created: 11/Jan/18  Updated: 30/Oct/23  Resolved: 07/Mar/18

Status: Closed
Project: Core Server
Component/s: JavaScript, Shell, Testing Infrastructure
Affects Version/s: None
Fix Version/s: 3.7.3

Type: Improvement Priority: Minor - P4
Reporter: Kevin Albertson Assignee: David Bradford (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Problem/Incident
causes SERVER-34536 shell autocomplete is broken for cons... Closed
Backwards Compatibility: Fully Compatible
Sprint: TIG 2018-03-12
Participants:

 Description   

In the shell, referencing non-existent error codes on the generated ErrorCodes object gives undefined but should throw an error.

During SERVER-31335 it was discovered that a test was calling

assert.writeErrorWithCode(res, ErrorCodes.DocumentFailedValidation)

(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.



 Comments   
Comment by Githook User [ 07/Mar/18 ]

Author:

{'email': 'david.bradford@mongodb.com', 'name': 'David Bradford', 'username': 'dbradf'}

Message: SERVER-32663: throw exception if non-existing ErrorCode is referenced
Branch: master
https://github.com/mongodb/mongo/commit/2b601814b9270e0fe62dfb41dd240b9b41660dd7

Generated at Thu Feb 08 04:30:54 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.