summaryrefslogtreecommitdiff
path: root/src/mongo/rpc
diff options
context:
space:
mode:
authorGeorge Wangensteen <george.wangensteen@mongodb.com>2020-10-26 20:40:49 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-11-06 01:06:48 +0000
commitd12213c0198b2a2adfa033a8661e026c9e9c7f7f (patch)
treee2ed810c4f96dea80438cbf2a83030034e56abee /src/mongo/rpc
parent2c2146ac0ae876984423c04a258e32b4c5843315 (diff)
downloadmongo-d12213c0198b2a2adfa033a8661e026c9e9c7f7f.tar.gz
SERVER-51374 Create IDL definition for ErrorReply
Diffstat (limited to 'src/mongo/rpc')
-rw-r--r--src/mongo/rpc/SConscript1
-rw-r--r--src/mongo/rpc/reply_builder_interface.cpp12
2 files changed, 13 insertions, 0 deletions
diff --git a/src/mongo/rpc/SConscript b/src/mongo/rpc/SConscript
index 43f089fa02a..d9f13bcfeb7 100644
--- a/src/mongo/rpc/SConscript
+++ b/src/mongo/rpc/SConscript
@@ -62,6 +62,7 @@ env.Library(
'$BUILD_DIR/mongo/base',
'$BUILD_DIR/mongo/db/dbmessage',
'$BUILD_DIR/mongo/db/server_options_core',
+ '$BUILD_DIR/mongo/idl/basic_types',
'$BUILD_DIR/mongo/s/common_s',
'$BUILD_DIR/mongo/util/net/network',
'metadata',
diff --git a/src/mongo/rpc/reply_builder_interface.cpp b/src/mongo/rpc/reply_builder_interface.cpp
index 6f4eddbbebe..1871d70af7a 100644
--- a/src/mongo/rpc/reply_builder_interface.cpp
+++ b/src/mongo/rpc/reply_builder_interface.cpp
@@ -35,6 +35,7 @@
#include "mongo/base/status_with.h"
#include "mongo/db/jsobj.h"
+#include "mongo/idl/basic_types_gen.h"
namespace mongo {
namespace rpc {
@@ -73,6 +74,17 @@ BSONObj augmentReplyWithStatus(const Status& status, BSONObj reply) {
extraInfo->serialize(&bob);
}
+ // Ensure the error reply satisfies the IDL-defined requirements.
+ try {
+ ErrorReply::parse(IDLParserErrorContext("augmentReplyWithStatus"), bob.asTempObj());
+ } catch (const DBException&) {
+ invariant(false,
+ "invalid error-response to a command constructed in "
+ "rpc::augmentReplyWithStatus. All erroring command responses "
+ "must comply with the format specified by the IDL-defined struct ErrorReply, "
+ "defined in idl/basic_types.idl");
+ }
+
return bob.obj();
}