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

assert.commandWorkedOrFailedWithCode unexpected behaviour with some commands

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 6.3.0-rc0, 6.0.11
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Fully Compatible
    • ALL
    • v6.0
    • Execution Team 2022-12-12, Execution Team 2022-12-26
    • 135

          assert.commandWorkedOrFailedWithCode = function commandWorkedOrFailedWithCode(res, errorCodeSet, msg) {
              if (!res.ok) {
                  return assert.commandFailedWithCode(res, errorCodeSet, msg);
              } else {
                  return assert.commandWorked(res, msg);
              }
          }; 

      But not all operations, such as insert, have the 'ok' field in the response. For those operations the commandFailedWithCode branch is always taken. 

      Possible fix:

          assert.commandWorkedOrFailedWithCode = function commandWorkedOrFailedWithCode(res, errorCodeSet, msg) {
              try {            return assert.commandWorked(res, msg);        } 
              catch (e) {            return assert.commandFailedWithCode(res, errorCodeSet, msg);        }    
      }; 
      

            Assignee:
            yujin.kang@mongodb.com Yujin Kang Park
            Reporter:
            yujin.kang@mongodb.com Yujin Kang Park
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: