[SERVER-3917] Display cleaner error in shell for invalid ObjectId - stack trace displayed Created: 21/Sep/11  Updated: 31/Jan/18  Resolved: 23/Mar/17

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: 2.0.0
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: Ryan Nitz Assignee: Mira Carey
Resolution: Done Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Participants:

 Description   

This is a bit noisy. This should probably just show:

Tue Sep 20 19:12:11 Error: 10448 invalid object id: length (shell):1

PRIMARY> db.data.dbProfile.findOne(

{cid: ObjectId("5277f6db23be91479fe6499b2d8808c5")}

);
Tue Sep 20 19:12:11 Assertion: 10448:invalid object id: length
0x4a3942 0x4f2cc1 0x509844 0x5609dc 0x552455 0x56056f 0x51dc06 0x51dc82 0x51f08e 0x514a8f 0x4752c7 0x4762c6 0x3ae961ec1d 0x46edc9
mongo(_ZN5mongo11msgassertedEiPKc+0x112) [0x4a3942]
mongo() [0x4f2cc1]
mongo(ZN5mongo21object_id_constructorEP9JSContextP8JSObjectjPlS4+0x94) [0x509844]
mongo(js_Invoke+0x40c) [0x5609dc]
mongo(js_Interpret+0x1305) [0x552455]
mongo(js_Execute+0x36f) [0x56056f]
mongo(JS_EvaluateUCScriptForPrincipals+0x66) [0x51dc06]
mongo(JS_EvaluateUCScript+0x22) [0x51dc82]
mongo(JS_EvaluateScript+0x6e) [0x51f08e]
mongo(_ZN5mongo7SMScope4execERKNS_10StringDataERKSsbbbi+0x11f) [0x514a8f]
mongo(_Z5_mainiPPc+0x2957) [0x4752c7]
mongo(main+0x26) [0x4762c6]
/lib64/libc.so.6(__libc_start_main+0xfd) [0x3ae961ec1d]
mongo(_ZNSt15basic_streambufIcSt11char_traitsIcEE6xsputnEPKcl+0x61) [0x46edc9]
Tue Sep 20 19:12:11 Error: 10448 invalid object id: length (shell):1



 Comments   
Comment by Mira Carey [ 23/Mar/17 ]

At least as recently as 3.0 (our most recent JS overhaul), ObjectId construction with an invalid parameter produced only the desired exception, rather than a backtrace.

Comment by Tianon Gravi [ 16/Dec/11 ]

The nosiness wouldn't be as bothersome if it were a regular catchable exception (hence allowing to hide the output). As it stands, invalid IDs print all that internal backtrace information even if the exception is caught (which is thrown, but have no way to quiet the other stuff).

Example:

> try { new ObjectId('obviously-invalid') } catch (e) { print('caught exception'); }
Fri Dec 16 15:59:25 Assertion: 10448:invalid object id: length
0x489b49 0x4c6c4c 0x4e5f2c 0x4d4979 0x7f7838c8a06c 0x3a9702f0420e 
 mongo(_ZN5mongo11msgassertedEiPKc+0x119) [0x489b49]
 mongo() [0x4c6c4c]
 mongo(_ZN5mongo12objectIdInitEPNS_7V8ScopeERKN2v89ArgumentsE+0x60c) [0x4e5f2c]
 mongo(_ZN5mongo7V8Scope10v8CallbackERKN2v89ArgumentsE+0x89) [0x4d4979]
 /usr/lib64/libv8.so.3.7.12.6(+0x9a06c) [0x7f7838c8a06c]
 [0x3a9702f0420e]
caught exception: 10448 invalid object id: length

Ought to be more like:

> try { new ObjectId('obviously-invalid') } catch (e) { print('caught exception'); }
caught exception: 10448 invalid object id: length

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