From 271d5ef5fc73b859eaa826798bd9f57f951fb911 Mon Sep 17 00:00:00 2001 From: Xin Dong Date: Wed, 24 Apr 2019 09:40:34 -0700 Subject: [PATCH] Fix the bug where dropIndex command is not replying all necessary fields in error cases. Audited all places where ok is 0 to make sure $err and errmsg are both returned --- src/ExtCmd.actor.cpp | 6 +++++- test/correctness/smoke/test_errors.py | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/ExtCmd.actor.cpp b/src/ExtCmd.actor.cpp index bd9be97..f9010fd 100644 --- a/src/ExtCmd.actor.cpp +++ b/src/ExtCmd.actor.cpp @@ -608,7 +608,11 @@ ACTOR static Future> doDropIndexesActor(ReferenceaddDocument(BSON("nIndexesWas" << dropped + 1 << "ok" << 1.0)); return reply; } else { - reply->addDocument(BSON("ok" << 0.0)); + // clang-format off + reply->addDocument(BSON("ok" << 0.0 << + "$err" << "'index' must be a string or an object" << + "errmsg" << "'index' must be a string or an object")); + // clang-format on return reply; } } else { diff --git a/test/correctness/smoke/test_errors.py b/test/correctness/smoke/test_errors.py index afc5221..c74e036 100644 --- a/test/correctness/smoke/test_errors.py +++ b/test/correctness/smoke/test_errors.py @@ -22,6 +22,7 @@ # from pymongo.errors import OperationFailure +from bson.son import SON def test_error_reply(fixture_db): try: @@ -30,3 +31,13 @@ def test_error_reply(fixture_db): serverErrObj = e.details assert serverErrObj['$err'] != None assert "no such cmd: sometotallyrandomcmd" in serverErrObj['$err'] + +def test_drop_index_cmd_error_reply(fixture_db): + try: + fixture_db.command(SON([("dropIndexes", "testcoll"), ("index", 1)])) + except Exception as e: + assert isinstance(e, OperationFailure) + serverErrObj = e.details + assert serverErrObj['$err'] != None + assert serverErrObj['errmsg'] != None +