[SERVER-34788] Improve error message when assert.commandWorked/Failed gets an unexpected type Created: 02/May/18  Updated: 29/Oct/23  Resolved: 12/Jul/18

Status: Closed
Project: Core Server
Component/s: Testing Infrastructure
Affects Version/s: None
Fix Version/s: 4.1.1

Type: Improvement Priority: Major - P3
Reporter: Kyle Suarez Assignee: David Bradford (Inactive)
Resolution: Fixed Votes: 0
Labels: neweng, tig-assertjs
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Sprint: TIG 2018-07-16
Participants:
Story Points: 1

 Description   

When assert.commandWorked() or assert.commandFailed() is passed a non-object, we throw:

    function _assertCommandWorked(res, msg, {ignoreWriteErrors, ignoreWriteConcernErrors}) {
        _validateAssertionMessage(msg);
 
        if (typeof res !== "object") {
            doassert("unknown response given to commandWorked");
        }

This leads to stack traces that are hard to reason about.

[ValidateCollections:job0:b23b-mdb_793e-ent_7007-qa_a6ce-1525027831965-041:ValidateCollections] 2018-04-29T18:58:39.654+0000 2018-04-29T18:58:39.653+0000 E QUERY    [js] Error: unknown response given to commandWorked :
[ValidateCollections:job0:b23b-mdb_793e-ent_7007-qa_a6ce-1525027831965-041:ValidateCollections] 2018-04-29T18:58:39.654+0000 doassert@src/mongo/shell/assert.js:18:14
[ValidateCollections:job0:b23b-mdb_793e-ent_7007-qa_a6ce-1525027831965-041:ValidateCollections] 2018-04-29T18:58:39.654+0000 _assertCommandWorked@src/mongo/shell/assert.js:485:13
[ValidateCollections:job0:b23b-mdb_793e-ent_7007-qa_a6ce-1525027831965-041:ValidateCollections] 2018-04-29T18:58:39.654+0000 assert.commandWorked@src/mongo/shell/assert.js:594:16
[ValidateCollections:job0:b23b-mdb_793e-ent_7007-qa_a6ce-1525027831965-041:ValidateCollections] 2018-04-29T18:58:39.654+0000 CollectionValidator/this.validateNodes/<@jstests/hooks/validate_collections.js:128:17
[ValidateCollections:job0:b23b-mdb_793e-ent_7007-qa_a6ce-1525027831965-041:ValidateCollections] 2018-04-29T18:58:39.655+0000 CollectionValidator/this.validateNodes@jstests/hooks/validate_collections.js:127:13
[ValidateCollections:job0:b23b-mdb_793e-ent_7007-qa_a6ce-1525027831965-041:ValidateCollections] 2018-04-29T18:58:39.655+0000 @jstests/hooks/run_validate_collections.js:36:5
[ValidateCollections:job0:b23b-mdb_793e-ent_7007-qa_a6ce-1525027831965-041:ValidateCollections] 2018-04-29T18:58:39.655+0000 @jstests/hooks/run_validate_collections.js:5:2
[ValidateCollections:job0:b23b-mdb_793e-ent_7007-qa_a6ce-1525027831965-041:ValidateCollections] 2018-04-29T18:58:39.655+0000 failed to load: jstests/hooks/run_validate_collections.js
[ValidateCollections:job0:b23b-mdb_793e-ent_7007-qa_a6ce-1525027831965-041:ValidateCollections] 2018-04-29T18:58:39.658+0000 Full collection validation after running 'b23b-mdb_793e-ent_7007-qa_a6ce-1525027831965-041' failed

We could, at the very least, include what the type of res was in the assertion error message.



 Comments   
Comment by Githook User [ 12/Jul/18 ]

Author:

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

Message: SERVER-34788: Improve commandWorked/Failed assertion messages
Branch: master
https://github.com/mongodb/mongo/commit/8b95fa8d528069a8000926b5fd78d61336b25c17

Comment by Judah Schvimer [ 02/May/18 ]

I think we may as well just attempt to print out "res" as well. If we get back a string or a number that would also be useful. 

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