diff --git a/src/ExtCmd.actor.cpp b/src/ExtCmd.actor.cpp index ce00844..0157bac 100644 --- a/src/ExtCmd.actor.cpp +++ b/src/ExtCmd.actor.cpp @@ -124,9 +124,7 @@ ACTOR static Future> doDropDatabase(ReferenceaddDocument(BSON("ok" << 1.0 << - "err" << e.what() << - "code" << e.code())); + reply->setError(e); // clang-format on return reply; } @@ -187,7 +185,7 @@ struct GetlasterrorCmd { try { WriteResult res = wait(lastWrite); bob.appendNumber("n", (long long)res.n); //< FIXME: ??? - bob << "err" << BSONNULL << "ok" << 1.0; + bob << "$err" << BSONNULL << "ok" << 1.0; if (!res.upsertedOIDList.empty()) { bob.appendElements(DataValue::decode_key_part(res.upsertedOIDList[0]).wrap("upserted")); } @@ -195,8 +193,9 @@ struct GetlasterrorCmd { bob << "updatedExisting" << (res.nModified > 0 && res.upsertedOIDList.empty()); } } catch (Error& e) { - bob.append("err", e.what()); + bob.append("$err", e.name()); bob.append("code", e.code()); + bob.append("errmsg", e.what()); bob.appendNumber("n", (long long)0); bob.append("ok", 1.0); } @@ -226,13 +225,10 @@ struct GetLogCmd { static Future> call(Reference nmc, Reference query, Reference reply) { - bson::BSONObjBuilder bob; if (query->ns.first != "admin") { // clang-format off - reply->addDocument((bob << "ok" << 0.0 << - "errmsg" << "access denied; use admin db" << - "$err" << "access denied; use admin db").obj()); + reply->setError(access_denied_use_admin_db()); // clang-format on return reply; } @@ -283,15 +279,9 @@ struct ReplSetGetStatusCmd { static Future> call(Reference nmc, Reference query, Reference reply) { - bson::BSONObjBuilder bob; // FIXME: what do we really want to report here? - bob.append("ok", 0.0); - bob.append("errmsg", "not really talking to mongodb"); - bob.append("$err", "not really talking to mongodb"); - - reply->addDocument(bob.obj()); - + reply->setError(not_really_talking_to_mongodb()); return reply; } }; @@ -391,7 +381,7 @@ ACTOR static Future> doDropCollection(ReferenceaddDocument(BSON("ok" << 1.0)); return reply; } catch (Error& e) { - reply->addDocument(BSON("ok" << 1.0 << "err" << e.what() << "code" << e.code())); + reply->setError(e); return reply; } } @@ -483,7 +473,7 @@ ACTOR static Future> doRenameCollection(ReferenceaddDocument(BSON("ok" << 1.0)); return reply; } catch (Error& e) { - reply->addDocument(BSON("ok" << 0.0 << "errmsg" << e.what() << "code" << e.code())); + reply->setError(e); return reply; } } @@ -518,7 +508,7 @@ ACTOR static Future> getStreamCount(ReferenceaddDocument(BSON("n" << (double)std::max(count - skip, 0) << "ok" << 1.0)); return reply; } catch (Error& e) { - reply->addDocument(BSON("$err" << e.what() << "code" << e.code() << "ok" << 1.0)); + reply->setError(e); reply->setResponseFlags(2); return reply; } @@ -632,10 +622,7 @@ ACTOR static Future> doFindAndModify(ReferenceaddDocument(replyObj); } catch (Error& e) { // clang-format off - reply->addDocument(BSON("errmsg" << e.what() << - "$err" << e.what() << - "code" << e.code() << - "ok" << 1.0)); + reply->setError(e); // clang-format on } @@ -702,9 +689,7 @@ ACTOR static Future> doDropIndexesActor(ReferenceaddDocument(BSON("ok" << 0.0 << - "$err" << "'index' must be a string or an object" << - "errmsg" << "'index' must be a string or an object")); + reply->setError(index_must_be_a_string_or_an_object()); // clang-format on return reply; } @@ -724,9 +709,7 @@ ACTOR static Future> doDropIndexesActor(ReferenceaddDocument(BSON("ok" << 0.0 << - "err" << e.what() << - "code" << e.code())); + reply->setError(e); // clang-format on return reply; } @@ -767,10 +750,7 @@ ACTOR static Future> doCreateIndexes(ReferenceaddDocument(BSON("ok" << 1.0)); } catch (Error& e) { // clang-format off - reply->addDocument(BSON("ok" << 0.0 << - "$err" << e.what() << - "errmsg" << e.what() << - "code" << e.code())); + reply->setError(e); // clang-format on } return reply; @@ -917,7 +897,7 @@ ACTOR static Future> doCreateCollection(ReferenceaddDocument(BSON("ok" << 1.0)); return reply; } catch (Error& e) { - reply->addDocument(BSON("ok" << 1.0 << "err" << e.what() << "code" << e.code())); + reply->setError(e); return reply; } } @@ -945,11 +925,7 @@ ACTOR static Future> doGetKVStatusActor(ReferenceaddDocument( - BSON("ok" << 1.0 << "err" - << "This command is supported only with version 3.0 and above of the KV Store, if you are using " - "an older FDB version please use the fdbcli utility to check its status." - << "code" << e.code())); + reply->setError(unsupported_fdb_version_for_kvstatus()); } return reply; @@ -1067,8 +1043,8 @@ ACTOR static Future> insertAndReply(Reference> getStreamDistinct(ReferenceaddDocument(BSON("$err" << e.what() << "code" << e.code() << "ok" << 1.0)); + reply->setError(e); reply->setResponseFlags(2 /*0b0010*/); return reply; } diff --git a/src/ExtMsg.actor.cpp b/src/ExtMsg.actor.cpp index 9f96d80..711e7ed 100644 --- a/src/ExtMsg.actor.cpp +++ b/src/ExtMsg.actor.cpp @@ -487,7 +487,7 @@ ACTOR static Future runQuery(Reference ec, } catch (Error& e) { if (e.code() != error_code_end_of_stream) { reply = Reference(new ExtMsgReply(msg->header, msg->query)); - reply->addDocument(BSON("$err" << e.what() << "code" << e.code() << "ok" << 1.0)); + reply->setError(e); reply->setResponseFlags(2 /*0b0010*/); replyStream.send(reply); } @@ -1115,8 +1115,8 @@ ACTOR Future doUpdateCmd(Namespace ns, TraceEvent(SevError, "ExtMsgUpdateFailure").error(e); // clang-format off cmdResult.writeErrors.push_back(BSON("index" << idx << + "$err" << e.name() << "code" << e.code() << - "$err" << e.what() << "errmsg" << e.what())); // clang-format on if (ordered) @@ -1182,6 +1182,7 @@ ACTOR static Future doGetMoreRun(Reference getMore, Referen cursor->refresh(); } catch (Error& e) { reply->setError(e); + reply->setResponseFlags(2 /*0b0010*/); } } else { reply->addResponseFlag(1 /*0b0001*/); @@ -1269,8 +1270,8 @@ ACTOR Future doDeleteCmd(Namespace ns, TraceEvent(SevError, "ExtMsgDeleteFailure").error(e); // clang-format off writeErrors.push_back(BSON("index" << idx << + "$err" << e.name() << "code" << e.code() << - "$err" << e.what() << "errmsg" << e.what())); // clang-format on if (ordered) diff --git a/src/ExtMsg.actor.h b/src/ExtMsg.actor.h index 87dd6f9..6c07bba 100644 --- a/src/ExtMsg.actor.h +++ b/src/ExtMsg.actor.h @@ -113,22 +113,20 @@ struct ExtMsgReply : ExtMsg, FastAllocated { replyHeader.documentCount++; } - void setError(std::string msg, int code) { + void setError(std::string msg, int code, std::string errmsg) { // Clear if response contains any outstanding documents documents.clear(); replyHeader.documentCount = 0; - // Set query failure flag - addResponseFlag(2); - // clang-format off addDocument(BSON("ok" << 0 << "$err" << msg << - "code" << code)); + "code" << code << + "errmsg" << errmsg)); // clang-format on } - void setError(Error e) { setError(e.what(), e.code()); } + void setError(Error e) { setError(e.name(), e.code(), e.what()); } void setResponseFlags(int32_t flags) { replyHeader.responseFlags = flags; } diff --git a/src/error_definitions.h b/src/error_definitions.h index 30a875b..a3cddb6 100644 --- a/src/error_definitions.h +++ b/src/error_definitions.h @@ -85,6 +85,13 @@ DOCLAYER_ERROR(wire_protocol_mismatch, 29966, "Wire protocol mismatch. Bad messa DOCLAYER_ERROR(no_index_name, 29967, "No index name specified"); DOCLAYER_ERROR(unsupported_index_type, 29969, "Document Layer does not support this index type, yet."); +DOCLAYER_ERROR(access_denied_use_admin_db, 29972, "access denied; use admin db"); +DOCLAYER_ERROR(not_really_talking_to_mongodb, 29973, "not really talking to mongodb"); +DOCLAYER_ERROR(index_must_be_a_string_or_an_object, 29974, "'index' must be a string or an object"); +DOCLAYER_ERROR(unsupported_fdb_version_for_kvstatus, + 29975, + "This command is supported only with version 3.0 and above of the KV Store, if you are using an older " + "FDB version please use the fdbcli utility to check its status."); DOCLAYER_ERROR(collection_name_does_not_exist, 29976, "Collection name does not exist."); DOCLAYER_ERROR(collection_name_already_exist, 29977, "Collection name already exist."); DOCLAYER_ERROR(old_and_new_collection_name_cannot_be_same, 29978, "Old and New collection name cannot be same.");