summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2018-04-25 16:36:59 -0400
committerMathias Stearn <mathias@10gen.com>2018-05-08 14:57:37 -0400
commit2d35461cb54e35afea223714fab1a184a9b381e2 (patch)
tree6b4b4379605b76f812fc02b20f54b4eccfddf349 /src
parent589af3820b00ed0b7ac26a84cfeed6554ab191f3 (diff)
downloadmongo-2d35461cb54e35afea223714fab1a184a9b381e2.tar.gz
SERVER-34628 Remove support for Status/StatusWith returns in TypedCommand
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/commands.cpp8
-rw-r--r--src/mongo/db/commands.h32
-rw-r--r--src/mongo/db/commands_test.cpp21
3 files changed, 5 insertions, 56 deletions
diff --git a/src/mongo/db/commands.cpp b/src/mongo/db/commands.cpp
index 6bfc1bbcd5c..b24813e9b83 100644
--- a/src/mongo/db/commands.cpp
+++ b/src/mongo/db/commands.cpp
@@ -351,14 +351,6 @@ void CommandReplyBuilder::reset() {
getBodyBuilder().resetToEmpty();
}
-void CommandReplyBuilder::fillFrom(const Status& status) {
- if (!status.isOK()) {
- reset();
- }
- auto bob = getBodyBuilder();
- CommandHelpers::appendCommandStatusNoThrow(bob, status);
-}
-
//////////////////////////////////////////////////////////////
// CommandInvocation
diff --git a/src/mongo/db/commands.h b/src/mongo/db/commands.h
index 1bb669945c8..7b0c2e26a36 100644
--- a/src/mongo/db/commands.h
+++ b/src/mongo/db/commands.h
@@ -428,39 +428,18 @@ public:
}
/**
- * Write the specified 'status' and associated fields into this reply body, as with
- * CommandHelpers::appendCommandStatus. Appends the "ok" and related fields if they
- * haven't already been set.
- * - If 'status' is not OK, this reply is reset before adding result.
- * - Otherwise, any data previously written to the body is left in place.
- */
- void fillFrom(const Status& status);
-
- /**
* The specified 'object' must be BSON-serializable.
- * Appends the "ok" and related fields if they haven't already been set.
*
* BSONSerializable 'x' means 'x.serialize(bob)' appends a representation of 'x'
* into 'BSONObjBuilder* bob'.
*/
template <typename T>
void fillFrom(const T& object) {
+ static_assert(!isStatusOrStatusWith<std::decay_t<T>>,
+ "Status and StatusWith<T> aren't supported by TypedCommand and fillFrom(). "
+ "Use uassertStatusOK() instead.");
auto bob = getBodyBuilder();
object.serialize(&bob);
- CommandHelpers::appendCommandStatus(bob, Status::OK());
- }
-
- /**
- * Equivalent to calling fillFrom with sw.getValue() or sw.getStatus(), whichever
- * 'sw' is holding.
- */
- template <typename T>
- void fillFrom(const StatusWith<T>& sw) {
- if (sw.isOK()) {
- fillFrom(sw.getValue());
- } else {
- fillFrom(sw.getStatus());
- }
}
private:
@@ -787,12 +766,9 @@ class TypedCommand<Derived>::MinimalInvocationBase : public InvocationBaseIntern
*
* R typedRun(OperationContext* opCtx);
*
- * where R is either void or usable as an argument to 'CommandReplyBuilder::fillFrom'.
- * So it's one of:
+ * where R is one of:
* - void
- * - mongo::Status
* - T, where T is usable with fillFrom.
- * - mongo::StatusWith<T>, where T usable with fillFrom.
*
* Note: a void typedRun produces a "pass-fail" command. If it runs to completion
* the result will be considered and formatted as an "ok".
diff --git a/src/mongo/db/commands_test.cpp b/src/mongo/db/commands_test.cpp
index b2e9752e3fa..0bec7ad4b51 100644
--- a/src/mongo/db/commands_test.cpp
+++ b/src/mongo/db/commands_test.cpp
@@ -326,15 +326,11 @@ private:
template <typename Fn>
using CmdT = MyCommand<typename std::decay<Fn>::type>;
-auto okFn = [] { return Status::OK(); };
-auto errFn = [] { return Status(ErrorCodes::UnknownError, "some error"); };
-auto throwFn = []() -> Status { uasserted(ErrorCodes::UnknownError, "some error"); };
+auto throwFn = [] { uasserted(ErrorCodes::UnknownError, "some error"); };
ExampleIncrementCommand exampleIncrementCommand;
ExampleMinimalCommand exampleMinimalCommand;
ExampleVoidCommand exampleVoidCommand;
-CmdT<decltype(okFn)> okStatusCommand("okStatus", okFn);
-CmdT<decltype(errFn)> errStatusCommand("notOkStatus", errFn);
CmdT<decltype(throwFn)> throwStatusCommand("throwsStatus", throwFn);
struct IncrementTestCommon {
@@ -393,21 +389,6 @@ TEST(TypedCommand, runVoid) {
});
}
-TEST(TypedCommand, runOkStatus) {
- IncrementTestCommon{}.run(
- okStatusCommand, [](int i, const BSONObj& reply) { ASSERT_EQ(reply["ok"].Double(), 1.0); });
-}
-
-TEST(TypedCommand, runErrStatus) {
- IncrementTestCommon{}.run(errStatusCommand, [](int i, const BSONObj& reply) {
- Status status = errFn();
- ASSERT_EQ(reply["ok"].Double(), 0.0);
- ASSERT_EQ(reply["errmsg"].String(), status.reason());
- ASSERT_EQ(reply["code"].Int(), status.code());
- ASSERT_EQ(reply["codeName"].String(), ErrorCodes::errorString(status.code()));
- });
-}
-
TEST(TypedCommand, runThrowStatus) {
IncrementTestCommon{}.run(throwStatusCommand, [](int i, const BSONObj& reply) {
Status status = Status::OK();