Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-34788

Improve error message when assert.commandWorked/Failed gets an unexpected type

    • Fully Compatible
    • TIG 2018-07-16
    • 1

      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.

            Assignee:
            david.bradford@mongodb.com David Bradford (Inactive)
            Reporter:
            kyle.suarez@mongodb.com Kyle Suarez
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: