Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-3147

CodeNames for command errors not reported in reply of write operations

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: libmongoc
    • Labels:
      None

      According to this comment on CDRIVER-2635, the codeName for a given error should be available via the reply parameter of whatever functions that have it. However, write functions that fail do not report any error information in the reply.

      e.g. the following code sample

      mongoc_write_concern_set_w(wc, 100);
      mongoc_write_concern_append(wc, options);
      if (!mongoc_collection_insert_one(collection, insert, options, &reply, &error)) {
          printf("err inserting, reply: %s\n", bson_as_relaxed_extended_json(&reply, NULL));
          printf("err domain: %d code: %d message: %s\n", error.domain, error.code, error.message);
      }
      

      Fails and produces the following output:

      err inserting, reply: { "insertedCount" : 0 }
      err domain: 17 code: 2 message: cannot use 'w' > 1 when a host is not replicated

      For reference, the shell does accurately report a "BadValue" codeName:

      > db.mycoll.insertOne({}, {writeConcern: {w: 100}})
      2019-05-24T15:55:21.234-0400 E QUERY    [js] WriteCommandError: cannot use 'w' > 1 when a host is not replicated :
      WriteCommandError({
      	"ok" : 0,
      	"errmsg" : "cannot use 'w' > 1 when a host is not replicated",
      	"code" : 2,
      	"codeName" : "BadValue"
      })
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            patrick.freed@mongodb.com Patrick Freed
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: