[SERVER-33849] Use of codeName should be consistent across error messages Created: 13/Mar/18  Updated: 06/Dec/22

Status: Backlog
Project: Core Server
Component/s: Shell
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Julian Torres Assignee: Backlog - Query Optimization
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to SERVER-36755 writeErrors codeName is set in sharde... Backlog
Assigned Teams:
Query Optimization
Participants:
Case:

 Description   

Say we have two documents with two fields in a collection (testing), with a compound unique index:

use test
db.testing.insert({ a: 1, b: 1 })
db.testing.insert({ a: 1, b: 2 })
db.testing.createIndex({ a: 1, b: 1 }, { unique: true })

The error message generated by a call to findAndModify that violates the unique index is as follows:

test> db.testing.findAndModify({ query: { a: 1,b: 1 }, update: { a: 1,b: 2 } })
2018-03-12T21:46:46.427-0400 E QUERY    [thread1] Error: findAndModifyFailed failed: {
  "operationTime": Timestamp(1520905600, 1),
  "ok": 0,
  "errmsg": "E11000 duplicate key error collection: test.testing index: a_1_b_1 dup key: { : 1.0, : 2.0 }",
  "code": 11000,
  "codeName": "DuplicateKey",
  "$clusterTime": {
    "clusterTime": Timestamp(1520905600, 1),
    "signature": {
      "hash": BinData(0, "eiANq76RZ704EWnDJSY3orlIWxM="),
      "keyId": NumberLong("6532150305184808961")
    }
  }
} :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DBCollection.prototype.findAndModify@src/mongo/shell/collection.js:724:1
@(shell):1:1

In the above error message, codeName is specified. However in an insert or update operation, the codeName field is not specified:

test> db.testing.insert({a:1,b:1})
E11000 duplicate key error collection: test.testing index: a_1_b_1 dup key: { : 1.0, : 1.0 }
WriteResult({
  "nInserted": 0,
  "writeError": {
    "code": 11000,
    "errmsg": "E11000 duplicate key error collection: test.testing index: a_1_b_1 dup key: { : 1.0, : 1.0 }"
  }
})

These error messages should be made consistent across all methods in the shell.



 Comments   
Comment by Ian Whalen (Inactive) [ 06/Apr/18 ]

greg.mckeon acm looks like this was moved without a comment? We were under the impression this was within scope for mathias' work to unify error propagation.

Generated at Thu Feb 08 04:34:46 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.