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

assert.commandWorked with writeError sets error code to object

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Shell
    • Server Tooling & Methods
    • ALL
    • Repl 2019-02-11

      Try this:

      try {
          assert.commandWorked({
              "n" : 0,
              "writeErrors" : [
                      {
                              "index" : 0,
                              "code" : 263,
                              "errmsg" : "foo"
                      }
              ],
              "ok" : 1
          });
      } catch (ex) {
          print(typeof ex.code);
      }
      

      Expected: number
      Actual: object

      The problem is _getErrorWithCode(), compiled into the shell from utils.js. That function expects the provided error object to be a command failure with ok: 0, or an object with a "writeError" field, not a "writeErrors" array.

      I think _getErrorWithCode() should check for writeErrors, too. I'm not sure "writeError" is ever actually present.

      This is a problem for tests that check things like "ex.code === 123". If the command failed with a writeErrors array, the exception's code is an object, not the expected number, and the check may be false incorrectly.

            Assignee:
            backlog-server-stm Backlog - Server Tooling and Methods (STM) (Inactive)
            Reporter:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: