[SERVER-34536] shell autocomplete is broken for constructors Created: 18/Apr/18  Updated: 29/Oct/23  Resolved: 27/Apr/18

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: 3.7.3
Fix Version/s: 4.0.0-rc0

Type: Bug Priority: Major - P3
Reporter: Eric Milkie Assignee: David Bradford (Inactive)
Resolution: Fixed Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Problem/Incident
is caused by SERVER-32663 Make it an error to reference a nonex... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Steps To Reproduce:

Start the shell (with a mongod already running) and type:
db.createCollection(
and then hit tab. You will get:
db.createCollection(exception during autocomplete: "Unknown Error Code: constructor"
The expected output would be something like
Display all 176 possibilities? (y or n)

Sprint: TIG 2018-05-07
Participants:

 Description   

If you hit tab when in constructor context in the shell, you get an error.



 Comments   
Comment by Githook User [ 27/Apr/18 ]

Author:

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

Message: SERVER-34536: Fix shell autocompletion
Branch: master
https://github.com/mongodb/mongo/commit/c159a533c4625ee2709ceba07f0f45e012647a80

Comment by Max Hirschhorn [ 18/Apr/18 ]

I think we could change the get handler

const handler = {
    get: function(obj, prop) {
        if (!obj.hasOwnProperty(prop)) {
            throw new Error('Unknown Error Code: ' + prop);
        }
 
        return obj[prop];
    }
};

to be

const handler = {
    get: function(obj, prop) {
        if (!(prop in obj)) {
            throw new Error('Unknown Error Code: ' + prop);
        }
 
        return obj[prop];
    }
};

so that it walks the prototype chain and allows the caller to use properties that are define on Object.prototype, such as Object.prototype.constructor.

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