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

assert.commandWorked with writeError sets error code to object

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major - P3
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: Backlog
    • Component/s: Shell
    • Labels:
    • Operating System:
      ALL
    • Sprint:
      Repl 2019-02-11

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated: