[SERVER-13362] Need better messaging in BSONElement::chk() errors Created: 26/Mar/14  Updated: 27/Jun/22  Resolved: 07/Aug/17

Status: Closed
Project: Core Server
Component/s: Usability
Affects Version/s: 2.6.0-rc2
Fix Version/s: 3.5.12

Type: Task Priority: Major - P3
Reporter: Ben Shteinfeld Assignee: Ben Shteinfeld
Resolution: Done Votes: 0
Labels: neweng, platforms-interns-2017
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-13367 Specialize operator<<(std::ostream&, ... Closed
Backwards Compatibility: Fully Compatible
Sprint: Platforms 2017-06-19, Platforms 2017-07-10, Platforms 2017-07-31, Platforms 2017-08-21
Participants:

 Description   

Original Title: mongod becomes very mad when passing wrong type for aggregate explain

Note: this is not an agg specific issue, but this is an example triggering the issue using agg.

db.runCommand({aggregate: "foo", pipeline: [], explain: 1})

returns

{
	"errmsg" : "exception: wrong type for field (explain) 1 != 8",
	"code" : 13111,
	"ok" : 0
}

Where I would have expected (like allowDiskUse does in same situation)

..
	"errmsg" : "exception: explain must be a bool, not a NumberDouble",

Furthermore, mongod becomes very mad in the logs:

2014-03-26T13:14:16.130-0700 [conn3] Assertion: 13111:wrong type for field (explain) 1 != 8
2014-03-26T13:14:16.134-0700 [conn3] 0x1006d60ab 0x10068a7a2 0x10067af4f 0x10067b02d 0x1000e29d0 0x1003c6624 0x10016d399 0x1001bb6f5 0x1001bc1f1 0x1001bd16c 0x1003fd43f 0x1002a2790 0x100007ac4 0x100698171 0x10070ae35 0x7fff88a01772 0x7fff889ee1a1
 0   mongod                              0x00000001006d60ab _ZN5mongo15printStackTraceERSo + 43
 1   mongod                              0x000000010068a7a2 _ZN5mongo10logContextEPKc + 114
 2   mongod                              0x000000010067af4f _ZN5mongo11msgassertedEiPKc + 255
 3   mongod                              0x000000010067b02d _ZN5mongo11msgassertedEiRKSs + 29
 4   mongod                              0x00000001000e29d0 _ZNK5mongo11BSONElement3chkEi + 800
 5   mongod                              0x00000001003c6624 _ZN5mongo8Pipeline12parseCommandERSsRKNS_7BSONObjERKN5boost13intrusive_ptrINS_17ExpressionContextEEE + 724
 6   mongod                              0x000000010016d399 _ZN5mongo15PipelineCommand3runERKSsRNS_7BSONObjEiRSsRNS_14BSONObjBuilderEb + 445
 7   mongod                              0x00000001001bb6f5 _ZN5mongo12_execCommandEPNS_7CommandERKSsRNS_7BSONObjEiRSsRNS_14BSONObjBuilderEb + 37
 8   mongod                              0x00000001001bc1f1 _ZN5mongo7Command11execCommandEPS0_RNS_6ClientEiPKcRNS_7BSONObjERNS_14BSONObjBuilderEb + 2245
 9   mongod                              0x00000001001bd16c _ZN5mongo12_runCommandsEPKcRNS_7BSONObjERNS_11_BufBuilderINS_16TrivialAllocatorEEERNS_14BSONObjBuilderEbi + 1388
 10  mongod                              0x00000001003fd43f _ZN5mongo11newRunQueryERNS_7MessageERNS_12QueryMessageERNS_5CurOpES1_ + 1615
 11  mongod                              0x00000001002a2790 _ZN5mongo16assembleResponseERNS_7MessageERNS_10DbResponseERKNS_11HostAndPortE + 1968
 12  mongod                              0x0000000100007ac4 _ZN5mongo16MyMessageHandler7processERNS_7MessageEPNS_21AbstractMessagingPortEPNS_9LastErrorE + 308
 13  mongod                              0x0000000100698171 _ZN5mongo17PortMessageServer17handleIncomingMsgEPv + 1681
 14  mongod                              0x000000010070ae35 thread_proxy + 229
 15  libsystem_c.dylib                   0x00007fff88a01772 _pthread_start + 327
 16  libsystem_c.dylib                   0x00007fff889ee1a1 thread_start + 13



 Comments   
Comment by Githook User [ 07/Aug/17 ]

Author:

{'username': 'bshteinfeld', 'email': 'ben.shteinfeld@mongodb.com', 'name': 'Ben Shteinfeld'}

Message: SERVER-13362 Remove BSONElement::chk(bool) overload
Branch: master
https://github.com/mongodb/mongo/commit/15f5790f257cd413fce8fe4653783aad1cd10909

Comment by Githook User [ 04/Aug/17 ]

Author:

{'username': 'bshteinfeld', 'email': 'ben.shteinfeld@mongodb.com', 'name': 'Ben Shteinfeld'}

Message: SERVER-13362 Change BSONElement::chk() to take a BSONType and use uassert
Branch: master
https://github.com/mongodb/mongo/commit/1599ba40e091bcf356bf0231bf32333397f07753

Comment by Mathias Stearn [ 26/Mar/14 ]

This is not an agg-specific issue. We need to clean up the messaging in BSONElement::chk(): https://github.com/mongodb/mongo/blob/r2.6.0-rc2/src/mongo/bson/bsonelement.h#L486-496

1) Should wrap types with calls to typeName().
2) This should probably uassert rather than massert.

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