summaryrefslogtreecommitdiff
path: root/src/mongo/db/error_labels.cpp
diff options
context:
space:
mode:
authorLingzhi Deng <lingzhi.deng@mongodb.com>2019-11-12 13:37:38 +0000
committerevergreen <evergreen@mongodb.com>2019-11-12 13:37:38 +0000
commit1f143f362f5b3fde180b8eb668c4e3f7933bd78d (patch)
tree84f75a6288e18757906a4e0611eb8cc9da9b7872 /src/mongo/db/error_labels.cpp
parentb526ac445bb0b39b53bd291ef6d23a73a38a1f11 (diff)
downloadmongo-1f143f362f5b3fde180b8eb668c4e3f7933bd78d.tar.gz
SERVER-43941: Add "errorLabels" field to failCommand failpoint
Diffstat (limited to 'src/mongo/db/error_labels.cpp')
-rw-r--r--src/mongo/db/error_labels.cpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/mongo/db/error_labels.cpp b/src/mongo/db/error_labels.cpp
index d56ba6dd82d..383f4f77551 100644
--- a/src/mongo/db/error_labels.cpp
+++ b/src/mongo/db/error_labels.cpp
@@ -28,6 +28,7 @@
*/
#include "mongo/db/error_labels.h"
+#include "mongo/db/commands.h"
namespace mongo {
@@ -94,17 +95,28 @@ bool ErrorLabelBuilder::_isCommitOrAbort() const {
_commandName == "abortTransaction";
}
-BSONObj getErrorLabels(const OperationSessionInfoFromClient& sessionOptions,
+BSONObj getErrorLabels(OperationContext* opCtx,
+ const OperationSessionInfoFromClient& sessionOptions,
const std::string& commandName,
boost::optional<ErrorCodes::Error> code,
boost::optional<ErrorCodes::Error> wcCode,
bool isInternalClient) {
- BSONArrayBuilder labelArray;
+ if (MONGO_unlikely(errorLabelsOverride(opCtx))) {
+ // This command was failed by a failCommand failpoint. Thus, we return the errorLabels
+ // specified in the failpoint to supress any other error labels that would otherwise be
+ // returned by the ErrorLabelBuilder.
+ if (errorLabelsOverride(opCtx).get().isEmpty()) {
+ return BSONObj();
+ } else {
+ return BSON(kErrorLabelsFieldName << errorLabelsOverride(opCtx).get());
+ }
+ }
+ BSONArrayBuilder labelArray;
ErrorLabelBuilder labelBuilder(sessionOptions, commandName, code, wcCode, isInternalClient);
labelBuilder.build(labelArray);
- return (labelArray.arrSize() > 0) ? BSON("errorLabels" << labelArray.arr()) : BSONObj();
+ return (labelArray.arrSize() > 0) ? BSON(kErrorLabelsFieldName << labelArray.arr()) : BSONObj();
}
bool isTransientTransactionError(ErrorCodes::Error code,