summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/pipeline')
-rw-r--r--src/mongo/db/pipeline/accumulation_statement.h2
-rw-r--r--src/mongo/db/pipeline/aggregation_request_test.cpp14
-rw-r--r--src/mongo/db/pipeline/document.h3
-rw-r--r--src/mongo/db/pipeline/document_source_add_fields_test.cpp7
-rw-r--r--src/mongo/db/pipeline/document_source_bucket_auto_test.cpp56
-rw-r--r--src/mongo/db/pipeline/document_source_bucket_test.cpp50
-rw-r--r--src/mongo/db/pipeline/document_source_change_stream_test.cpp8
-rw-r--r--src/mongo/db/pipeline/document_source_check_resume_token_test.cpp8
-rw-r--r--src/mongo/db/pipeline/document_source_count_test.cpp12
-rw-r--r--src/mongo/db/pipeline/document_source_current_op_test.cpp18
-rw-r--r--src/mongo/db/pipeline/document_source_facet.cpp2
-rw-r--r--src/mongo/db/pipeline/document_source_facet_test.cpp53
-rw-r--r--src/mongo/db/pipeline/document_source_graph_lookup_test.cpp6
-rw-r--r--src/mongo/db/pipeline/document_source_group.h2
-rw-r--r--src/mongo/db/pipeline/document_source_group_test.cpp10
-rw-r--r--src/mongo/db/pipeline/document_source_lookup_change_post_image.h2
-rw-r--r--src/mongo/db/pipeline/document_source_lookup_change_post_image_test.cpp12
-rw-r--r--src/mongo/db/pipeline/document_source_lookup_test.cpp10
-rw-r--r--src/mongo/db/pipeline/document_source_project_test.cpp5
-rw-r--r--src/mongo/db/pipeline/document_source_replace_root_test.cpp33
-rw-r--r--src/mongo/db/pipeline/document_source_sample_test.cpp20
-rw-r--r--src/mongo/db/pipeline/document_source_skip.h2
-rw-r--r--src/mongo/db/pipeline/document_source_sort_by_count_test.cpp8
-rw-r--r--src/mongo/db/pipeline/document_source_sort_test.cpp12
-rw-r--r--src/mongo/db/pipeline/document_source_unwind_test.cpp25
-rw-r--r--src/mongo/db/pipeline/document_value_test.cpp23
-rw-r--r--src/mongo/db/pipeline/expression_test.cpp94
-rw-r--r--src/mongo/db/pipeline/field_path.h5
-rw-r--r--src/mongo/db/pipeline/field_path_test.cpp22
-rw-r--r--src/mongo/db/pipeline/granularity_rounder_powers_of_two_test.cpp20
-rw-r--r--src/mongo/db/pipeline/granularity_rounder_preferred_numbers_test.cpp24
-rw-r--r--src/mongo/db/pipeline/lite_parsed_document_source.h3
-rw-r--r--src/mongo/db/pipeline/lite_parsed_pipeline.h2
-rw-r--r--src/mongo/db/pipeline/parsed_add_fields_test.cpp43
-rw-r--r--src/mongo/db/pipeline/parsed_aggregation_projection.cpp4
-rw-r--r--src/mongo/db/pipeline/parsed_aggregation_projection.h2
-rw-r--r--src/mongo/db/pipeline/parsed_aggregation_projection_test.cpp165
-rw-r--r--src/mongo/db/pipeline/parsed_inclusion_projection_test.cpp4
-rw-r--r--src/mongo/db/pipeline/pipeline_test.cpp2
-rw-r--r--src/mongo/db/pipeline/tee_buffer_test.cpp6
-rw-r--r--src/mongo/db/pipeline/value.h6
41 files changed, 425 insertions, 380 deletions
diff --git a/src/mongo/db/pipeline/accumulation_statement.h b/src/mongo/db/pipeline/accumulation_statement.h
index 91a58e3a8e2..d722938032f 100644
--- a/src/mongo/db/pipeline/accumulation_statement.h
+++ b/src/mongo/db/pipeline/accumulation_statement.h
@@ -68,7 +68,7 @@ public:
* Parses a BSONElement that is an accumulated field, and returns an AccumulationStatement for
* that accumulated field.
*
- * Throws a UserException if parsing fails.
+ * Throws a AssertionException if parsing fails.
*/
static AccumulationStatement parseAccumulationStatement(
const boost::intrusive_ptr<ExpressionContext>& expCtx,
diff --git a/src/mongo/db/pipeline/aggregation_request_test.cpp b/src/mongo/db/pipeline/aggregation_request_test.cpp
index 5b5540357c7..8192e0fed3e 100644
--- a/src/mongo/db/pipeline/aggregation_request_test.cpp
+++ b/src/mongo/db/pipeline/aggregation_request_test.cpp
@@ -404,25 +404,27 @@ TEST(AggregationRequestTest, ParseNSShouldReturnAggregateOneNSIfAggregateFieldIs
TEST(AggregationRequestTest, ParseNSShouldRejectNumericNSIfAggregateFieldIsNotOne) {
const BSONObj inputBSON = fromjson("{aggregate: 2, pipeline: []}");
ASSERT_THROWS_CODE(
- AggregationRequest::parseNs("a", inputBSON), UserException, ErrorCodes::FailedToParse);
+ AggregationRequest::parseNs("a", inputBSON), AssertionException, ErrorCodes::FailedToParse);
}
TEST(AggregationRequestTest, ParseNSShouldRejectNonStringNonNumericNS) {
const BSONObj inputBSON = fromjson("{aggregate: {}, pipeline: []}");
ASSERT_THROWS_CODE(
- AggregationRequest::parseNs("a", inputBSON), UserException, ErrorCodes::TypeMismatch);
+ AggregationRequest::parseNs("a", inputBSON), AssertionException, ErrorCodes::TypeMismatch);
}
TEST(AggregationRequestTest, ParseNSShouldRejectAggregateOneStringAsCollectionName) {
const BSONObj inputBSON = fromjson("{aggregate: '$cmd.aggregate', pipeline: []}");
- ASSERT_THROWS_CODE(
- AggregationRequest::parseNs("a", inputBSON), UserException, ErrorCodes::InvalidNamespace);
+ ASSERT_THROWS_CODE(AggregationRequest::parseNs("a", inputBSON),
+ AssertionException,
+ ErrorCodes::InvalidNamespace);
}
TEST(AggregationRequestTest, ParseNSShouldRejectInvalidCollectionName) {
const BSONObj inputBSON = fromjson("{aggregate: '', pipeline: []}");
- ASSERT_THROWS_CODE(
- AggregationRequest::parseNs("a", inputBSON), UserException, ErrorCodes::InvalidNamespace);
+ ASSERT_THROWS_CODE(AggregationRequest::parseNs("a", inputBSON),
+ AssertionException,
+ ErrorCodes::InvalidNamespace);
}
TEST(AggregationRequestTest, ParseFromBSONOverloadsShouldProduceIdenticalRequests) {
diff --git a/src/mongo/db/pipeline/document.h b/src/mongo/db/pipeline/document.h
index e004f7ab982..5e5980f5a51 100644
--- a/src/mongo/db/pipeline/document.h
+++ b/src/mongo/db/pipeline/document.h
@@ -192,7 +192,8 @@ public:
/**
* Serializes this document to the BSONObj under construction in 'builder'. Metadata is not
- * included. Throws a UserException if 'recursionLevel' exceeds the maximum allowable depth.
+ * included. Throws a AssertionException if 'recursionLevel' exceeds the maximum allowable
+ * depth.
*/
void toBson(BSONObjBuilder* builder, size_t recursionLevel = 1) const;
BSONObj toBson() const;
diff --git a/src/mongo/db/pipeline/document_source_add_fields_test.cpp b/src/mongo/db/pipeline/document_source_add_fields_test.cpp
index a11b894e542..fa9b27f5d61 100644
--- a/src/mongo/db/pipeline/document_source_add_fields_test.cpp
+++ b/src/mongo/db/pipeline/document_source_add_fields_test.cpp
@@ -86,8 +86,9 @@ TEST_F(AddFieldsTest, ShouldErrorOnNonObjectSpec) {
BSONObj spec = BSON("$addFields"
<< "foo");
BSONElement specElement = spec.firstElement();
- ASSERT_THROWS_CODE(
- DocumentSourceAddFields::createFromBson(specElement, getExpCtx()), UserException, 40272);
+ ASSERT_THROWS_CODE(DocumentSourceAddFields::createFromBson(specElement, getExpCtx()),
+ AssertionException,
+ 40272);
}
TEST_F(AddFieldsTest, ShouldBeAbleToProcessMultipleDocuments) {
@@ -223,7 +224,7 @@ TEST_F(AddFieldsTest, CannotAddNestedDocumentExceedingDepthLimit) {
ASSERT_THROWS_CODE(
DocumentSourceAddFields::create(
makeAddFieldsForNestedDocument(BSONDepth::getMaxAllowableDepth() + 1), getExpCtx()),
- UserException,
+ AssertionException,
ErrorCodes::Overflow);
}
} // namespace
diff --git a/src/mongo/db/pipeline/document_source_bucket_auto_test.cpp b/src/mongo/db/pipeline/document_source_bucket_auto_test.cpp
index 7afa30e1c8b..333a130a0ae 100644
--- a/src/mongo/db/pipeline/document_source_bucket_auto_test.cpp
+++ b/src/mongo/db/pipeline/document_source_bucket_auto_test.cpp
@@ -527,103 +527,103 @@ TEST_F(BucketAutoTests, ShouldBeAbleToReParseSerializedStage) {
TEST_F(BucketAutoTests, FailsWithInvalidNumberOfBuckets) {
auto spec = fromjson("{$bucketAuto : {groupBy : '$x', buckets : 'test'}}");
- ASSERT_THROWS_CODE(createBucketAuto(spec), UserException, 40241);
+ ASSERT_THROWS_CODE(createBucketAuto(spec), AssertionException, 40241);
spec = fromjson("{$bucketAuto : {groupBy : '$x', buckets : 2147483648}}");
- ASSERT_THROWS_CODE(createBucketAuto(spec), UserException, 40242);
+ ASSERT_THROWS_CODE(createBucketAuto(spec), AssertionException, 40242);
spec = fromjson("{$bucketAuto : {groupBy : '$x', buckets : 1.5}}");
- ASSERT_THROWS_CODE(createBucketAuto(spec), UserException, 40242);
+ ASSERT_THROWS_CODE(createBucketAuto(spec), AssertionException, 40242);
spec = fromjson("{$bucketAuto : {groupBy : '$x', buckets : 0}}");
- ASSERT_THROWS_CODE(createBucketAuto(spec), UserException, 40243);
+ ASSERT_THROWS_CODE(createBucketAuto(spec), AssertionException, 40243);
spec = fromjson("{$bucketAuto : {groupBy : '$x', buckets : -1}}");
- ASSERT_THROWS_CODE(createBucketAuto(spec), UserException, 40243);
+ ASSERT_THROWS_CODE(createBucketAuto(spec), AssertionException, 40243);
// Use the create() helper.
const int numBuckets = 0;
ASSERT_THROWS_CODE(
DocumentSourceBucketAuto::create(
getExpCtx(), ExpressionConstant::create(getExpCtx(), Value(0)), numBuckets),
- UserException,
+ AssertionException,
40243);
}
TEST_F(BucketAutoTests, FailsWithNonExpressionGroupBy) {
auto spec = fromjson("{$bucketAuto : {groupBy : 'test', buckets : 1}}");
- ASSERT_THROWS_CODE(createBucketAuto(spec), UserException, 40239);
+ ASSERT_THROWS_CODE(createBucketAuto(spec), AssertionException, 40239);
spec = fromjson("{$bucketAuto : {groupBy : {test : 'test'}, buckets : 1}}");
- ASSERT_THROWS_CODE(createBucketAuto(spec), UserException, 40239);
+ ASSERT_THROWS_CODE(createBucketAuto(spec), AssertionException, 40239);
}
TEST_F(BucketAutoTests, FailsWithNonObjectArgument) {
auto spec = fromjson("{$bucketAuto : 'test'}");
- ASSERT_THROWS_CODE(createBucketAuto(spec), UserException, 40240);
+ ASSERT_THROWS_CODE(createBucketAuto(spec), AssertionException, 40240);
spec = fromjson("{$bucketAuto : [1, 2, 3]}");
- ASSERT_THROWS_CODE(createBucketAuto(spec), UserException, 40240);
+ ASSERT_THROWS_CODE(createBucketAuto(spec), AssertionException, 40240);
}
TEST_F(BucketAutoTests, FailsWithNonObjectOutput) {
auto spec = fromjson("{$bucketAuto : {groupBy : '$x', buckets : 1, output : 'test'}}");
- ASSERT_THROWS_CODE(createBucketAuto(spec), UserException, 40244);
+ ASSERT_THROWS_CODE(createBucketAuto(spec), AssertionException, 40244);
spec = fromjson("{$bucketAuto : {groupBy : '$x', buckets : 1, output : [1, 2, 3]}}");
- ASSERT_THROWS_CODE(createBucketAuto(spec), UserException, 40244);
+ ASSERT_THROWS_CODE(createBucketAuto(spec), AssertionException, 40244);
spec = fromjson("{$bucketAuto : {groupBy : '$x', buckets : 1, output : 1}}");
- ASSERT_THROWS_CODE(createBucketAuto(spec), UserException, 40244);
+ ASSERT_THROWS_CODE(createBucketAuto(spec), AssertionException, 40244);
}
TEST_F(BucketAutoTests, FailsWhenGroupByMissing) {
auto spec = fromjson("{$bucketAuto : {buckets : 1}}");
- ASSERT_THROWS_CODE(createBucketAuto(spec), UserException, 40246);
+ ASSERT_THROWS_CODE(createBucketAuto(spec), AssertionException, 40246);
}
TEST_F(BucketAutoTests, FailsWhenBucketsMissing) {
auto spec = fromjson("{$bucketAuto : {groupBy : '$x'}}");
- ASSERT_THROWS_CODE(createBucketAuto(spec), UserException, 40246);
+ ASSERT_THROWS_CODE(createBucketAuto(spec), AssertionException, 40246);
}
TEST_F(BucketAutoTests, FailsWithUnknownField) {
auto spec = fromjson("{$bucketAuto : {groupBy : '$x', buckets : 1, field : 'test'}}");
- ASSERT_THROWS_CODE(createBucketAuto(spec), UserException, 40245);
+ ASSERT_THROWS_CODE(createBucketAuto(spec), AssertionException, 40245);
}
TEST_F(BucketAutoTests, FailsWithInvalidExpressionToAccumulator) {
auto spec = fromjson(
"{$bucketAuto : {groupBy : '$x', buckets : 1, output : {avg : {$avg : ['$x', 1]}}}}");
- ASSERT_THROWS_CODE(createBucketAuto(spec), UserException, 40237);
+ ASSERT_THROWS_CODE(createBucketAuto(spec), AssertionException, 40237);
spec = fromjson(
"{$bucketAuto : {groupBy : '$x', buckets : 1, output : {test : {$avg : '$x', $sum : "
"'$x'}}}}");
- ASSERT_THROWS_CODE(createBucketAuto(spec), UserException, 40238);
+ ASSERT_THROWS_CODE(createBucketAuto(spec), AssertionException, 40238);
}
TEST_F(BucketAutoTests, FailsWithNonAccumulatorObjectOutputField) {
auto spec =
fromjson("{$bucketAuto : {groupBy : '$x', buckets : 1, output : {field : 'test'}}}");
- ASSERT_THROWS_CODE(createBucketAuto(spec), UserException, 40234);
+ ASSERT_THROWS_CODE(createBucketAuto(spec), AssertionException, 40234);
spec = fromjson("{$bucketAuto : {groupBy : '$x', buckets : 1, output : {field : 1}}}");
- ASSERT_THROWS_CODE(createBucketAuto(spec), UserException, 40234);
+ ASSERT_THROWS_CODE(createBucketAuto(spec), AssertionException, 40234);
spec = fromjson(
"{$bucketAuto : {groupBy : '$x', buckets : 1, output : {test : {field : 'test'}}}}");
- ASSERT_THROWS_CODE(createBucketAuto(spec), UserException, 40234);
+ ASSERT_THROWS_CODE(createBucketAuto(spec), AssertionException, 40234);
}
TEST_F(BucketAutoTests, FailsWithInvalidOutputFieldName) {
auto spec = fromjson(
"{$bucketAuto : {groupBy : '$x', buckets : 1, output : {'field.test' : {$avg : '$x'}}}}");
- ASSERT_THROWS_CODE(createBucketAuto(spec), UserException, 40235);
+ ASSERT_THROWS_CODE(createBucketAuto(spec), AssertionException, 40235);
spec = fromjson(
"{$bucketAuto : {groupBy : '$x', buckets : 1, output : {'$field' : {$avg : '$x'}}}}");
- ASSERT_THROWS_CODE(createBucketAuto(spec), UserException, 40236);
+ ASSERT_THROWS_CODE(createBucketAuto(spec), AssertionException, 40236);
}
void assertCannotSpillToDisk(const boost::intrusive_ptr<ExpressionContext>& expCtx) {
@@ -641,7 +641,7 @@ void assertCannotSpillToDisk(const boost::intrusive_ptr<ExpressionContext>& expC
{Document{{"a", 0}, {"largeStr", largeStr}}, Document{{"a", 1}, {"largeStr", largeStr}}});
bucketAutoStage->setSource(mock.get());
- ASSERT_THROWS_CODE(bucketAutoStage->getNext(), UserException, 16819);
+ ASSERT_THROWS_CODE(bucketAutoStage->getNext(), AssertionException, 16819);
}
TEST_F(BucketAutoTests, ShouldFailIfBufferingTooManyDocuments) {
@@ -683,7 +683,7 @@ TEST_F(BucketAutoTests, ShouldCorrectlyTrackMemoryUsageBetweenPauses) {
ASSERT_TRUE(bucketAutoStage->getNext().isPaused());
// The next should realize it's used too much memory.
- ASSERT_THROWS_CODE(bucketAutoStage->getNext(), UserException, 16819);
+ ASSERT_THROWS_CODE(bucketAutoStage->getNext(), AssertionException, 16819);
}
TEST_F(BucketAutoTests, ShouldRoundUpMaximumBoundariesWithGranularitySpecified) {
@@ -774,7 +774,7 @@ TEST_F(BucketAutoTests, ShouldFailOnNaNWhenGranularitySpecified) {
Document{{"x", std::nan("NaN")}},
Document{{"x", 1}},
Document{{"x", 1}}}),
- UserException,
+ AssertionException,
40259);
}
@@ -787,7 +787,7 @@ TEST_F(BucketAutoTests, ShouldFailOnNonNumericValuesWhenGranularitySpecified) {
Document{{"x", "test"_sd}},
Document{{"x", 1}},
Document{{"x", 1}}}),
- UserException,
+ AssertionException,
40258);
}
@@ -799,7 +799,7 @@ TEST_F(BucketAutoTests, ShouldFailOnNegativeNumbersWhenGranularitySpecified) {
getResults(
bucketAutoSpec,
{Document{{"x", 0}}, Document{{"x", -1}}, Document{{"x", 1}}, Document{{"x", 2}}}),
- UserException,
+ AssertionException,
40260);
}
} // namespace
diff --git a/src/mongo/db/pipeline/document_source_bucket_test.cpp b/src/mongo/db/pipeline/document_source_bucket_test.cpp
index 26f18c4dca9..fc7704d6a8d 100644
--- a/src/mongo/db/pipeline/document_source_bucket_test.cpp
+++ b/src/mongo/db/pipeline/document_source_bucket_test.cpp
@@ -163,107 +163,107 @@ public:
TEST_F(InvalidBucketSpec, BucketFailsWithNonObject) {
auto spec = fromjson("{$bucket : 1}");
- ASSERT_THROWS_CODE(createBucket(spec), UserException, 40201);
+ ASSERT_THROWS_CODE(createBucket(spec), AssertionException, 40201);
spec = fromjson("{$bucket : 'test'}");
- ASSERT_THROWS_CODE(createBucket(spec), UserException, 40201);
+ ASSERT_THROWS_CODE(createBucket(spec), AssertionException, 40201);
}
TEST_F(InvalidBucketSpec, BucketFailsWithUnknownField) {
const auto spec =
fromjson("{$bucket : {groupBy : '$x', boundaries : [0, 1, 2], unknown : 'field'}}");
- ASSERT_THROWS_CODE(createBucket(spec), UserException, 40197);
+ ASSERT_THROWS_CODE(createBucket(spec), AssertionException, 40197);
}
TEST_F(InvalidBucketSpec, BucketFailsWithNoGroupBy) {
const auto spec = fromjson("{$bucket : {boundaries : [0, 1, 2]}}");
- ASSERT_THROWS_CODE(createBucket(spec), UserException, 40198);
+ ASSERT_THROWS_CODE(createBucket(spec), AssertionException, 40198);
}
TEST_F(InvalidBucketSpec, BucketFailsWithNoBoundaries) {
const auto spec = fromjson("{$bucket : {groupBy : '$x'}}");
- ASSERT_THROWS_CODE(createBucket(spec), UserException, 40198);
+ ASSERT_THROWS_CODE(createBucket(spec), AssertionException, 40198);
}
TEST_F(InvalidBucketSpec, BucketFailsWithNonExpressionGroupBy) {
auto spec = fromjson("{$bucket : {groupBy : {test : 'obj'}, boundaries : [0, 1, 2]}}");
- ASSERT_THROWS_CODE(createBucket(spec), UserException, 40202);
+ ASSERT_THROWS_CODE(createBucket(spec), AssertionException, 40202);
spec = fromjson("{$bucket : {groupBy : 'test', boundaries : [0, 1, 2]}}");
- ASSERT_THROWS_CODE(createBucket(spec), UserException, 40202);
+ ASSERT_THROWS_CODE(createBucket(spec), AssertionException, 40202);
spec = fromjson("{$bucket : {groupBy : 1, boundaries : [0, 1, 2]}}");
- ASSERT_THROWS_CODE(createBucket(spec), UserException, 40202);
+ ASSERT_THROWS_CODE(createBucket(spec), AssertionException, 40202);
}
TEST_F(InvalidBucketSpec, BucketFailsWithNonArrayBoundaries) {
auto spec = fromjson("{$bucket : {groupBy : '$x', boundaries : 'test'}}");
- ASSERT_THROWS_CODE(createBucket(spec), UserException, 40200);
+ ASSERT_THROWS_CODE(createBucket(spec), AssertionException, 40200);
spec = fromjson("{$bucket : {groupBy : '$x', boundaries : 1}}");
- ASSERT_THROWS_CODE(createBucket(spec), UserException, 40200);
+ ASSERT_THROWS_CODE(createBucket(spec), AssertionException, 40200);
spec = fromjson("{$bucket : {groupBy : '$x', boundaries : {test : 'obj'}}}");
- ASSERT_THROWS_CODE(createBucket(spec), UserException, 40200);
+ ASSERT_THROWS_CODE(createBucket(spec), AssertionException, 40200);
}
TEST_F(InvalidBucketSpec, BucketFailsWithNotEnoughBoundaries) {
auto spec = fromjson("{$bucket : {groupBy : '$x', boundaries : [0]}}");
- ASSERT_THROWS_CODE(createBucket(spec), UserException, 40192);
+ ASSERT_THROWS_CODE(createBucket(spec), AssertionException, 40192);
spec = fromjson("{$bucket : {groupBy : '$x', boundaries : []}}");
- ASSERT_THROWS_CODE(createBucket(spec), UserException, 40192);
+ ASSERT_THROWS_CODE(createBucket(spec), AssertionException, 40192);
}
TEST_F(InvalidBucketSpec, BucketFailsWithNonConstantValueBoundaries) {
const auto spec = fromjson("{$bucket : {groupBy : '$x', boundaries : ['$x', '$y', '$z']}}");
- ASSERT_THROWS_CODE(createBucket(spec), UserException, 40191);
+ ASSERT_THROWS_CODE(createBucket(spec), AssertionException, 40191);
}
TEST_F(InvalidBucketSpec, BucketFailsWithMixedTypesBoundaries) {
const auto spec = fromjson("{$bucket : {groupBy : '$x', boundaries : [0, 'test']}}");
- ASSERT_THROWS_CODE(createBucket(spec), UserException, 40193);
+ ASSERT_THROWS_CODE(createBucket(spec), AssertionException, 40193);
}
TEST_F(InvalidBucketSpec, BucketFailsWithNonUniqueBoundaries) {
auto spec = fromjson("{$bucket : {groupBy : '$x', boundaries : [1, 1, 2, 3]}}");
- ASSERT_THROWS_CODE(createBucket(spec), UserException, 40194);
+ ASSERT_THROWS_CODE(createBucket(spec), AssertionException, 40194);
spec = fromjson("{$bucket : {groupBy : '$x', boundaries : ['a', 'b', 'b', 'c']}}");
- ASSERT_THROWS_CODE(createBucket(spec), UserException, 40194);
+ ASSERT_THROWS_CODE(createBucket(spec), AssertionException, 40194);
}
TEST_F(InvalidBucketSpec, BucketFailsWithNonSortedBoundaries) {
const auto spec = fromjson("{$bucket : {groupBy : '$x', boundaries : [4, 5, 3, 6]}}");
- ASSERT_THROWS_CODE(createBucket(spec), UserException, 40194);
+ ASSERT_THROWS_CODE(createBucket(spec), AssertionException, 40194);
}
TEST_F(InvalidBucketSpec, BucketFailsWithNonConstantExpressionDefault) {
const auto spec =
fromjson("{$bucket : {groupBy : '$x', boundaries : [0, 1, 2], default : '$x'}}");
- ASSERT_THROWS_CODE(createBucket(spec), UserException, 40195);
+ ASSERT_THROWS_CODE(createBucket(spec), AssertionException, 40195);
}
TEST_F(InvalidBucketSpec, BucketFailsWhenDefaultIsInBoundariesRange) {
auto spec = fromjson("{$bucket : {groupBy : '$x', boundaries : [1, 2, 4], default : 3}}");
- ASSERT_THROWS_CODE(createBucket(spec), UserException, 40199);
+ ASSERT_THROWS_CODE(createBucket(spec), AssertionException, 40199);
spec = fromjson("{$bucket : {groupBy : '$x', boundaries : [1, 2, 4], default : 1}}");
- ASSERT_THROWS_CODE(createBucket(spec), UserException, 40199);
+ ASSERT_THROWS_CODE(createBucket(spec), AssertionException, 40199);
}
TEST_F(InvalidBucketSpec, GroupFailsForBucketWithInvalidOutputField) {
auto spec = fromjson("{$bucket : {groupBy : '$x', boundaries : [1, 2, 3], output : 'test'}}");
- ASSERT_THROWS_CODE(createBucket(spec), UserException, 40196);
+ ASSERT_THROWS_CODE(createBucket(spec), AssertionException, 40196);
spec = fromjson(
"{$bucket : {groupBy : '$x', boundaries : [1, 2, 3], output : {number : 'test'}}}");
- ASSERT_THROWS_CODE(createBucket(spec), UserException, 40234);
+ ASSERT_THROWS_CODE(createBucket(spec), AssertionException, 40234);
spec = fromjson(
"{$bucket : {groupBy : '$x', boundaries : [1, 2, 3], output : {'test.test' : {$sum : "
"1}}}}");
- ASSERT_THROWS_CODE(createBucket(spec), UserException, 40235);
+ ASSERT_THROWS_CODE(createBucket(spec), AssertionException, 40235);
}
TEST_F(InvalidBucketSpec, SwitchFailsForBucketWhenNoDefaultSpecified) {
@@ -281,7 +281,7 @@ TEST_F(InvalidBucketSpec, SwitchFailsForBucketWhenNoDefaultSpecified) {
auto doc = Document{{"x", 4}};
auto source = DocumentSourceMock::create(doc);
groupStage->setSource(source.get());
- ASSERT_THROWS_CODE(groupStage->getNext(), UserException, 40066);
+ ASSERT_THROWS_CODE(groupStage->getNext(), AssertionException, 40066);
}
} // namespace
} // namespace mongo
diff --git a/src/mongo/db/pipeline/document_source_change_stream_test.cpp b/src/mongo/db/pipeline/document_source_change_stream_test.cpp
index 158de011548..4a2797349e9 100644
--- a/src/mongo/db/pipeline/document_source_change_stream_test.cpp
+++ b/src/mongo/db/pipeline/document_source_change_stream_test.cpp
@@ -138,7 +138,7 @@ TEST_F(ChangeStreamStageTest, ShouldRejectUnrecognizedOption) {
ASSERT_THROWS_CODE(
DSChangeStream::createFromBson(
BSON(DSChangeStream::kStageName << BSON("unexpected" << 4)).firstElement(), expCtx),
- UserException,
+ AssertionException,
40415);
}
@@ -149,7 +149,7 @@ TEST_F(ChangeStreamStageTest, ShouldRejectNonStringFullDocumentOption) {
DSChangeStream::createFromBson(
BSON(DSChangeStream::kStageName << BSON("fullDocument" << true)).firstElement(),
expCtx),
- UserException,
+ AssertionException,
ErrorCodes::TypeMismatch);
}
@@ -161,7 +161,7 @@ TEST_F(ChangeStreamStageTest, ShouldRejectUnrecognizedFullDocumentOption) {
<< "unrecognized"))
.firstElement(),
expCtx),
- UserException,
+ AssertionException,
40575);
}
@@ -169,7 +169,7 @@ TEST_F(ChangeStreamStageTestNoSetup, FailsWithNoReplicationCoordinator) {
const auto spec = fromjson("{$changeStream: {}}");
ASSERT_THROWS_CODE(DocumentSourceChangeStream::createFromBson(spec.firstElement(), getExpCtx()),
- UserException,
+ AssertionException,
40573);
}
diff --git a/src/mongo/db/pipeline/document_source_check_resume_token_test.cpp b/src/mongo/db/pipeline/document_source_check_resume_token_test.cpp
index 5f6d73035eb..9cf2090b5cb 100644
--- a/src/mongo/db/pipeline/document_source_check_resume_token_test.cpp
+++ b/src/mongo/db/pipeline/document_source_check_resume_token_test.cpp
@@ -164,7 +164,7 @@ TEST_F(CheckResumeTokenTest, ShouldFailIfFirstDocHasWrongResumeToken) {
Timestamp doc2Timestamp(101, 1);
addDocument(doc1Timestamp, "1");
addDocument(doc2Timestamp, "2");
- ASSERT_THROWS_CODE(checkResumeToken->getNext(), UserException, 40585);
+ ASSERT_THROWS_CODE(checkResumeToken->getNext(), AssertionException, 40585);
}
TEST_F(CheckResumeTokenTest, ShouldFailIfTokenHasWrongDocumentId) {
@@ -172,7 +172,7 @@ TEST_F(CheckResumeTokenTest, ShouldFailIfTokenHasWrongDocumentId) {
auto checkResumeToken = createCheckResumeToken(resumeTimestamp, "0");
addDocument(resumeTimestamp, "1");
- ASSERT_THROWS_CODE(checkResumeToken->getNext(), UserException, 40585);
+ ASSERT_THROWS_CODE(checkResumeToken->getNext(), AssertionException, 40585);
}
TEST_F(CheckResumeTokenTest, ShouldFailIfTokenHasWrongNamespace) {
@@ -180,7 +180,7 @@ TEST_F(CheckResumeTokenTest, ShouldFailIfTokenHasWrongNamespace) {
auto checkResumeToken = createCheckResumeToken(resumeTimestamp, "1", "test1.ns");
addDocument(resumeTimestamp, "1", "test2.ns");
- ASSERT_THROWS_CODE(checkResumeToken->getNext(), UserException, 40585);
+ ASSERT_THROWS_CODE(checkResumeToken->getNext(), AssertionException, 40585);
}
/**
@@ -190,7 +190,7 @@ TEST_F(CheckResumeTokenTest, ShouldFailWithNoDocuments) {
Timestamp resumeTimestamp(100, 1);
auto checkResumeToken = createCheckResumeToken(resumeTimestamp, "0");
- ASSERT_THROWS_CODE(checkResumeToken->getNext(), UserException, 40584);
+ ASSERT_THROWS_CODE(checkResumeToken->getNext(), AssertionException, 40584);
}
} // namespace
diff --git a/src/mongo/db/pipeline/document_source_count_test.cpp b/src/mongo/db/pipeline/document_source_count_test.cpp
index 254f011ff1d..b0e5050e0ff 100644
--- a/src/mongo/db/pipeline/document_source_count_test.cpp
+++ b/src/mongo/db/pipeline/document_source_count_test.cpp
@@ -103,35 +103,35 @@ public:
TEST_F(InvalidCountSpec, NonStringSpec) {
BSONObj spec = BSON("$count" << 1);
- ASSERT_THROWS_CODE(createCount(spec), UserException, 40156);
+ ASSERT_THROWS_CODE(createCount(spec), AssertionException, 40156);
spec = BSON("$count" << BSON("field1"
<< "test"));
- ASSERT_THROWS_CODE(createCount(spec), UserException, 40156);
+ ASSERT_THROWS_CODE(createCount(spec), AssertionException, 40156);
}
TEST_F(InvalidCountSpec, EmptyStringSpec) {
BSONObj spec = BSON("$count"
<< "");
- ASSERT_THROWS_CODE(createCount(spec), UserException, 40157);
+ ASSERT_THROWS_CODE(createCount(spec), AssertionException, 40157);
}
TEST_F(InvalidCountSpec, FieldPathSpec) {
BSONObj spec = BSON("$count"
<< "$x");
- ASSERT_THROWS_CODE(createCount(spec), UserException, 40158);
+ ASSERT_THROWS_CODE(createCount(spec), AssertionException, 40158);
}
TEST_F(InvalidCountSpec, EmbeddedNullByteSpec) {
BSONObj spec = BSON("$count"
<< "te\0st"_sd);
- ASSERT_THROWS_CODE(createCount(spec), UserException, 40159);
+ ASSERT_THROWS_CODE(createCount(spec), AssertionException, 40159);
}
TEST_F(InvalidCountSpec, PeriodInStringSpec) {
BSONObj spec = BSON("$count"
<< "test.string");
- ASSERT_THROWS_CODE(createCount(spec), UserException, 40160);
+ ASSERT_THROWS_CODE(createCount(spec), AssertionException, 40160);
}
} // namespace
} // namespace mongo
diff --git a/src/mongo/db/pipeline/document_source_current_op_test.cpp b/src/mongo/db/pipeline/document_source_current_op_test.cpp
index 6afbc9e24dc..b852c94ffbe 100644
--- a/src/mongo/db/pipeline/document_source_current_op_test.cpp
+++ b/src/mongo/db/pipeline/document_source_current_op_test.cpp
@@ -86,7 +86,7 @@ private:
TEST_F(DocumentSourceCurrentOpTest, ShouldFailToParseIfSpecIsNotObject) {
const auto specObj = fromjson("{$currentOp:1}");
ASSERT_THROWS_CODE(DocumentSourceCurrentOp::createFromBson(specObj.firstElement(), getExpCtx()),
- UserException,
+ AssertionException,
ErrorCodes::FailedToParse);
}
@@ -94,7 +94,7 @@ TEST_F(DocumentSourceCurrentOpTest, ShouldFailToParseIfNotRunOnAdmin) {
const auto specObj = fromjson("{$currentOp:{}}");
getExpCtx()->ns = NamespaceString::makeCollectionlessAggregateNSS("foo");
ASSERT_THROWS_CODE(DocumentSourceCurrentOp::createFromBson(specObj.firstElement(), getExpCtx()),
- UserException,
+ AssertionException,
ErrorCodes::InvalidNamespace);
}
@@ -102,35 +102,35 @@ TEST_F(DocumentSourceCurrentOpTest, ShouldFailToParseIfNotRunWithAggregateOne) {
const auto specObj = fromjson("{$currentOp:{}}");
getExpCtx()->ns = NamespaceString("admin.foo");
ASSERT_THROWS_CODE(DocumentSourceCurrentOp::createFromBson(specObj.firstElement(), getExpCtx()),
- UserException,
+ AssertionException,
ErrorCodes::InvalidNamespace);
}
TEST_F(DocumentSourceCurrentOpTest, ShouldFailToParseIdleConnectionsIfNotBoolean) {
const auto specObj = fromjson("{$currentOp:{idleConnections:1}}");
ASSERT_THROWS_CODE(DocumentSourceCurrentOp::createFromBson(specObj.firstElement(), getExpCtx()),
- UserException,
+ AssertionException,
ErrorCodes::FailedToParse);
}
TEST_F(DocumentSourceCurrentOpTest, ShouldFailToParseAllUsersIfNotBoolean) {
const auto specObj = fromjson("{$currentOp:{allUsers:1}}");
ASSERT_THROWS_CODE(DocumentSourceCurrentOp::createFromBson(specObj.firstElement(), getExpCtx()),
- UserException,
+ AssertionException,
ErrorCodes::FailedToParse);
}
TEST_F(DocumentSourceCurrentOpTest, ShouldFailToParseTruncateOpsIfNotBoolean) {
const auto specObj = fromjson("{$currentOp:{truncateOps:1}}");
ASSERT_THROWS_CODE(DocumentSourceCurrentOp::createFromBson(specObj.firstElement(), getExpCtx()),
- UserException,
+ AssertionException,
ErrorCodes::FailedToParse);
}
TEST_F(DocumentSourceCurrentOpTest, ShouldFailToParseIfUnrecognisedParameterSpecified) {
const auto specObj = fromjson("{$currentOp:{foo:true}}");
ASSERT_THROWS_CODE(DocumentSourceCurrentOp::createFromBson(specObj.firstElement(), getExpCtx()),
- UserException,
+ AssertionException,
ErrorCodes::FailedToParse);
}
@@ -231,7 +231,7 @@ TEST_F(DocumentSourceCurrentOpTest, ShouldFailIfNoShardNameAvailableForShardedRe
const auto currentOp = DocumentSourceCurrentOp::create(getExpCtx());
currentOp->injectMongodInterface(mongod);
- ASSERT_THROWS_CODE(currentOp->getNext(), UserException, 40465);
+ ASSERT_THROWS_CODE(currentOp->getNext(), AssertionException, 40465);
}
TEST_F(DocumentSourceCurrentOpTest, ShouldFailIfOpIDIsNonNumericWhenModifyingInShardedContext) {
@@ -243,7 +243,7 @@ TEST_F(DocumentSourceCurrentOpTest, ShouldFailIfOpIDIsNonNumericWhenModifyingInS
const auto currentOp = DocumentSourceCurrentOp::create(getExpCtx());
currentOp->injectMongodInterface(mongod);
- ASSERT_THROWS_CODE(currentOp->getNext(), UserException, ErrorCodes::TypeMismatch);
+ ASSERT_THROWS_CODE(currentOp->getNext(), AssertionException, ErrorCodes::TypeMismatch);
}
} // namespace
diff --git a/src/mongo/db/pipeline/document_source_facet.cpp b/src/mongo/db/pipeline/document_source_facet.cpp
index e553ea2fa62..3c8cf9db359 100644
--- a/src/mongo/db/pipeline/document_source_facet.cpp
+++ b/src/mongo/db/pipeline/document_source_facet.cpp
@@ -72,7 +72,7 @@ namespace {
* Extracts the names of the facets and the vectors of raw BSONObjs representing the stages within
* that facet's pipeline.
*
- * Throws a UserException if it fails to parse for any reason.
+ * Throws a AssertionException if it fails to parse for any reason.
*/
vector<pair<string, vector<BSONObj>>> extractRawPipelines(const BSONElement& elem) {
uassert(40169,
diff --git a/src/mongo/db/pipeline/document_source_facet_test.cpp b/src/mongo/db/pipeline/document_source_facet_test.cpp
index d8798a5c70e..be05268fb7b 100644
--- a/src/mongo/db/pipeline/document_source_facet_test.cpp
+++ b/src/mongo/db/pipeline/document_source_facet_test.cpp
@@ -66,49 +66,60 @@ TEST_F(DocumentSourceFacetTest, ShouldRejectNonObjectSpec) {
auto ctx = getExpCtx();
auto spec = BSON("$facet"
<< "string");
- ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx), UserException);
+ ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx),
+ AssertionException);
spec = BSON("$facet" << 1);
- ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx), UserException);
+ ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx),
+ AssertionException);
spec = BSON("$facet" << BSON_ARRAY(1 << 2));
- ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx), UserException);
+ ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx),
+ AssertionException);
}
TEST_F(DocumentSourceFacetTest, ShouldRejectEmptyObject) {
auto ctx = getExpCtx();
auto spec = BSON("$facet" << BSONObj());
- ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx), UserException);
+ ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx),
+ AssertionException);
}
TEST_F(DocumentSourceFacetTest, ShouldRejectFacetsWithInvalidNames) {
auto ctx = getExpCtx();
auto spec = BSON("$facet" << BSON("" << BSON_ARRAY(BSON("$skip" << 4))));
- ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx), UserException);
+ ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx),
+ AssertionException);
spec = BSON("$facet" << BSON("a.b" << BSON_ARRAY(BSON("$skip" << 4))));
- ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx), UserException);
+ ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx),
+ AssertionException);
spec = BSON("$facet" << BSON("$a" << BSON_ARRAY(BSON("$skip" << 4))));
- ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx), UserException);
+ ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx),
+ AssertionException);
}
TEST_F(DocumentSourceFacetTest, ShouldRejectNonArrayFacets) {
auto ctx = getExpCtx();
auto spec = BSON("$facet" << BSON("a" << 1));
- ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx), UserException);
+ ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx),
+ AssertionException);
spec = BSON("$facet" << BSON("a" << BSON_ARRAY(BSON("$skip" << 4)) << "b" << 2));
- ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx), UserException);
+ ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx),
+ AssertionException);
}
TEST_F(DocumentSourceFacetTest, ShouldRejectEmptyPipelines) {
auto ctx = getExpCtx();
auto spec = BSON("$facet" << BSON("a" << BSONArray()));
- ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx), UserException);
+ ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx),
+ AssertionException);
spec = BSON("$facet" << BSON("a" << BSON_ARRAY(BSON("$skip" << 4)) << "b" << BSONArray()));
- ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx), UserException);
+ ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx),
+ AssertionException);
}
TEST_F(DocumentSourceFacetTest, ShouldSucceedWhenNamespaceIsCollectionless) {
@@ -124,29 +135,35 @@ TEST_F(DocumentSourceFacetTest, ShouldRejectFacetsContainingAnOutStage) {
auto ctx = getExpCtx();
auto spec = BSON("$facet" << BSON("a" << BSON_ARRAY(BSON("$out"
<< "out_collection"))));
- ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx), UserException);
+ ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx),
+ AssertionException);
spec =
BSON("$facet" << BSON("a" << BSON_ARRAY(BSON("$skip" << 1) << BSON("$out"
<< "out_collection"))));
- ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx), UserException);
+ ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx),
+ AssertionException);
spec = BSON("$facet" << BSON("a" << BSON_ARRAY(BSON("$out"
<< "out_collection")
<< BSON("$skip" << 1))));
- ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx), UserException);
+ ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx),
+ AssertionException);
}
TEST_F(DocumentSourceFacetTest, ShouldRejectFacetsContainingAFacetStage) {
auto ctx = getExpCtx();
auto spec = fromjson("{$facet: {a: [{$facet: {a: [{$skip: 2}]}}]}}");
- ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx), UserException);
+ ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx),
+ AssertionException);
spec = fromjson("{$facet: {a: [{$skip: 2}, {$facet: {a: [{$skip: 2}]}}]}}");
- ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx), UserException);
+ ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx),
+ AssertionException);
spec = fromjson("{$facet: {a: [{$skip: 2}], b: [{$facet: {a: [{$skip: 2}]}}]}}");
- ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx), UserException);
+ ASSERT_THROWS(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx),
+ AssertionException);
}
TEST_F(DocumentSourceFacetTest, ShouldAcceptLegalSpecification) {
@@ -599,7 +616,7 @@ TEST_F(DocumentSourceFacetTest, ShouldThrowIfAnyPipelineRequiresTextScoreButItIs
auto facetStage = DocumentSourceFacet::create(std::move(facets), ctx);
DepsTracker deps(DepsTracker::MetadataAvailable::kNoMetadata);
- ASSERT_THROWS(facetStage->getDependencies(&deps), UserException);
+ ASSERT_THROWS(facetStage->getDependencies(&deps), AssertionException);
}
/**
diff --git a/src/mongo/db/pipeline/document_source_graph_lookup_test.cpp b/src/mongo/db/pipeline/document_source_graph_lookup_test.cpp
index 0d693d81e25..feba9110eeb 100644
--- a/src/mongo/db/pipeline/document_source_graph_lookup_test.cpp
+++ b/src/mongo/db/pipeline/document_source_graph_lookup_test.cpp
@@ -105,7 +105,7 @@ TEST_F(DocumentSourceGraphLookUpTest,
graphLookupStage->injectMongodInterface(
std::make_shared<MockMongodImplementation>(std::move(fromContents)));
- ASSERT_THROWS_CODE(graphLookupStage->getNext(), UserException, 40271);
+ ASSERT_THROWS_CODE(graphLookupStage->getNext(), AssertionException, 40271);
}
TEST_F(DocumentSourceGraphLookUpTest,
@@ -135,7 +135,7 @@ TEST_F(DocumentSourceGraphLookUpTest,
graphLookupStage->injectMongodInterface(
std::make_shared<MockMongodImplementation>(std::move(fromContents)));
- ASSERT_THROWS_CODE(graphLookupStage->getNext(), UserException, 40271);
+ ASSERT_THROWS_CODE(graphLookupStage->getNext(), AssertionException, 40271);
}
TEST_F(DocumentSourceGraphLookUpTest,
@@ -165,7 +165,7 @@ TEST_F(DocumentSourceGraphLookUpTest,
std::make_shared<MockMongodImplementation>(std::move(fromContents)));
graphLookupStage->setSource(inputMock.get());
- ASSERT_THROWS_CODE(graphLookupStage->getNext(), UserException, 40271);
+ ASSERT_THROWS_CODE(graphLookupStage->getNext(), AssertionException, 40271);
}
bool arrayContains(const boost::intrusive_ptr<ExpressionContext>& expCtx,
diff --git a/src/mongo/db/pipeline/document_source_group.h b/src/mongo/db/pipeline/document_source_group.h
index 8b8094c94ee..cf108c15f24 100644
--- a/src/mongo/db/pipeline/document_source_group.h
+++ b/src/mongo/db/pipeline/document_source_group.h
@@ -63,7 +63,7 @@ public:
size_t maxMemoryUsageBytes = kDefaultMaxMemoryUsageBytes);
/**
- * Parses 'elem' into a $group stage, or throws a UserException if 'elem' was an invalid
+ * Parses 'elem' into a $group stage, or throws a AssertionException if 'elem' was an invalid
* specification.
*/
static boost::intrusive_ptr<DocumentSource> createFromBson(
diff --git a/src/mongo/db/pipeline/document_source_group_test.cpp b/src/mongo/db/pipeline/document_source_group_test.cpp
index 752312847ec..34e5a753e7a 100644
--- a/src/mongo/db/pipeline/document_source_group_test.cpp
+++ b/src/mongo/db/pipeline/document_source_group_test.cpp
@@ -158,7 +158,7 @@ TEST_F(DocumentSourceGroupTest, ShouldErrorIfNotAllowedToSpillToDiskAndResultSet
Document{{"_id", 1}, {"largeStr", largeStr}}});
group->setSource(mock.get());
- ASSERT_THROWS_CODE(group->getNext(), UserException, 16945);
+ ASSERT_THROWS_CODE(group->getNext(), AssertionException, 16945);
}
TEST_F(DocumentSourceGroupTest, ShouldCorrectlyTrackMemoryUsageBetweenPauses) {
@@ -186,7 +186,7 @@ TEST_F(DocumentSourceGroupTest, ShouldCorrectlyTrackMemoryUsageBetweenPauses) {
ASSERT_TRUE(group->getNext().isPaused());
// The next should realize it's used too much memory.
- ASSERT_THROWS_CODE(group->getNext(), UserException, 16945);
+ ASSERT_THROWS_CODE(group->getNext(), AssertionException, 16945);
}
BSONObj toBson(const intrusive_ptr<DocumentSource>& source) {
@@ -258,7 +258,7 @@ class ParseErrorBase : public Base {
public:
virtual ~ParseErrorBase() {}
void run() {
- ASSERT_THROWS(createGroup(spec()), UserException);
+ ASSERT_THROWS(createGroup(spec()), AssertionException);
}
protected:
@@ -302,7 +302,7 @@ public:
BSONObj spec = BSON("$group"
<< "foo");
BSONElement specElement = spec.firstElement();
- ASSERT_THROWS(DocumentSourceGroup::createFromBson(specElement, ctx()), UserException);
+ ASSERT_THROWS(DocumentSourceGroup::createFromBson(specElement, ctx()), AssertionException);
}
};
@@ -1101,7 +1101,7 @@ class ArrayConstantAccumulatorExpression : public CheckResultsBase {
public:
void run() {
// A parse exception is thrown when a raw array is provided to an accumulator.
- ASSERT_THROWS(createGroup(fromjson("{_id:1,a:{$push:[4,5,6]}}")), UserException);
+ ASSERT_THROWS(createGroup(fromjson("{_id:1,a:{$push:[4,5,6]}}")), AssertionException);
// Run standard base tests.
CheckResultsBase::run();
}
diff --git a/src/mongo/db/pipeline/document_source_lookup_change_post_image.h b/src/mongo/db/pipeline/document_source_lookup_change_post_image.h
index 5df6d7403d6..b11c79e44d3 100644
--- a/src/mongo/db/pipeline/document_source_lookup_change_post_image.h
+++ b/src/mongo/db/pipeline/document_source_lookup_change_post_image.h
@@ -106,7 +106,7 @@ private:
Value lookupPostImage(const Document& updateOp) const;
/**
- * Throws a UserException if the namespace found in 'inputDoc' doesn't match the one on the
+ * Throws a AssertionException if the namespace found in 'inputDoc' doesn't match the one on the
* ExpressionContext.
*/
NamespaceString assertNamespaceMatches(const Document& inputDoc) const;
diff --git a/src/mongo/db/pipeline/document_source_lookup_change_post_image_test.cpp b/src/mongo/db/pipeline/document_source_lookup_change_post_image_test.cpp
index c1d0c6d10fa..fdeea5bffc6 100644
--- a/src/mongo/db/pipeline/document_source_lookup_change_post_image_test.cpp
+++ b/src/mongo/db/pipeline/document_source_lookup_change_post_image_test.cpp
@@ -102,7 +102,7 @@ TEST_F(DocumentSourceLookupChangePostImageTest, ShouldErrorIfMissingDocumentKeyO
lookupChangeStage->injectMongodInterface(
std::make_shared<MockMongodInterface>(deque<DocumentSource::GetNextResult>{}));
- ASSERT_THROWS_CODE(lookupChangeStage->getNext(), UserException, 40578);
+ ASSERT_THROWS_CODE(lookupChangeStage->getNext(), AssertionException, 40578);
}
TEST_F(DocumentSourceLookupChangePostImageTest, ShouldErrorIfMissingOperationType) {
@@ -123,7 +123,7 @@ TEST_F(DocumentSourceLookupChangePostImageTest, ShouldErrorIfMissingOperationTyp
lookupChangeStage->injectMongodInterface(
std::make_shared<MockMongodInterface>(deque<DocumentSource::GetNextResult>{}));
- ASSERT_THROWS_CODE(lookupChangeStage->getNext(), UserException, 40578);
+ ASSERT_THROWS_CODE(lookupChangeStage->getNext(), AssertionException, 40578);
}
TEST_F(DocumentSourceLookupChangePostImageTest, ShouldErrorIfMissingNamespace) {
@@ -143,7 +143,7 @@ TEST_F(DocumentSourceLookupChangePostImageTest, ShouldErrorIfMissingNamespace) {
lookupChangeStage->injectMongodInterface(
std::make_shared<MockMongodInterface>(deque<DocumentSource::GetNextResult>{}));
- ASSERT_THROWS_CODE(lookupChangeStage->getNext(), UserException, 40578);
+ ASSERT_THROWS_CODE(lookupChangeStage->getNext(), AssertionException, 40578);
}
TEST_F(DocumentSourceLookupChangePostImageTest, ShouldErrorIfNsFieldHasWrongType) {
@@ -162,7 +162,7 @@ TEST_F(DocumentSourceLookupChangePostImageTest, ShouldErrorIfNsFieldHasWrongType
lookupChangeStage->injectMongodInterface(
std::make_shared<MockMongodInterface>(deque<DocumentSource::GetNextResult>{}));
- ASSERT_THROWS_CODE(lookupChangeStage->getNext(), UserException, 40578);
+ ASSERT_THROWS_CODE(lookupChangeStage->getNext(), AssertionException, 40578);
}
TEST_F(DocumentSourceLookupChangePostImageTest, ShouldErrorIfNsFieldDoesNotMatchPipeline) {
@@ -183,7 +183,7 @@ TEST_F(DocumentSourceLookupChangePostImageTest, ShouldErrorIfNsFieldDoesNotMatch
lookupChangeStage->injectMongodInterface(
std::make_shared<MockMongodInterface>(deque<DocumentSource::GetNextResult>{}));
- ASSERT_THROWS_CODE(lookupChangeStage->getNext(), UserException, 40579);
+ ASSERT_THROWS_CODE(lookupChangeStage->getNext(), AssertionException, 40579);
}
TEST_F(DocumentSourceLookupChangePostImageTest, ShouldErrorIfDocumentKeyIsNotUnique) {
@@ -206,7 +206,7 @@ TEST_F(DocumentSourceLookupChangePostImageTest, ShouldErrorIfDocumentKeyIsNotUni
lookupChangeStage->injectMongodInterface(
std::make_shared<MockMongodInterface>(std::move(foreignCollection)));
- ASSERT_THROWS_CODE(lookupChangeStage->getNext(), UserException, 40580);
+ ASSERT_THROWS_CODE(lookupChangeStage->getNext(), AssertionException, 40580);
}
TEST_F(DocumentSourceLookupChangePostImageTest, ShouldPropagatePauses) {
diff --git a/src/mongo/db/pipeline/document_source_lookup_test.cpp b/src/mongo/db/pipeline/document_source_lookup_test.cpp
index f9aa416cac6..2f7ac7852e4 100644
--- a/src/mongo/db/pipeline/document_source_lookup_test.cpp
+++ b/src/mongo/db/pipeline/document_source_lookup_test.cpp
@@ -223,7 +223,7 @@ TEST_F(DocumentSourceLookUpTest, RejectsLocalFieldForeignFieldWhenPipelineIsSpec
<< "Expected creation of the "
<< lookupStage->getSourceName()
<< " stage to uassert on mix of localField/foreignField and pipeline options");
- } catch (const UserException& ex) {
+ } catch (const AssertionException& ex) {
ASSERT_EQ(ErrorCodes::FailedToParse, ex.code());
}
}
@@ -246,7 +246,7 @@ TEST_F(DocumentSourceLookUpTest, RejectsLocalFieldForeignFieldWhenLetIsSpecified
<< "as"))
.firstElement(),
expCtx),
- UserException,
+ AssertionException,
ErrorCodes::FailedToParse);
}
@@ -267,7 +267,7 @@ TEST_F(DocumentSourceLookUpTest, RejectsInvalidLetVariableName) {
<< "as"))
.firstElement(),
expCtx),
- UserException,
+ AssertionException,
16866);
ASSERT_THROWS_CODE(DocumentSourceLookUp::createFromBson(
@@ -282,7 +282,7 @@ TEST_F(DocumentSourceLookUpTest, RejectsInvalidLetVariableName) {
<< "as"))
.firstElement(),
expCtx),
- UserException,
+ AssertionException,
16867);
ASSERT_THROWS_CODE(DocumentSourceLookUp::createFromBson(
@@ -297,7 +297,7 @@ TEST_F(DocumentSourceLookUpTest, RejectsInvalidLetVariableName) {
<< "as"))
.firstElement(),
expCtx),
- UserException,
+ AssertionException,
16868);
}
diff --git a/src/mongo/db/pipeline/document_source_project_test.cpp b/src/mongo/db/pipeline/document_source_project_test.cpp
index 7512600ae73..5688d343675 100644
--- a/src/mongo/db/pipeline/document_source_project_test.cpp
+++ b/src/mongo/db/pipeline/document_source_project_test.cpp
@@ -88,7 +88,8 @@ TEST_F(ProjectStageTest, ShouldErrorOnNonObjectSpec) {
BSONObj spec = BSON("$project"
<< "foo");
BSONElement specElement = spec.firstElement();
- ASSERT_THROWS(DocumentSourceProject::createFromBson(specElement, getExpCtx()), UserException);
+ ASSERT_THROWS(DocumentSourceProject::createFromBson(specElement, getExpCtx()),
+ AssertionException);
}
/**
@@ -290,7 +291,7 @@ TEST_F(ProjectStageTest, CannotAddNestedDocumentExceedingDepthLimit) {
ASSERT_THROWS_CODE(
DocumentSourceProject::create(
makeProjectForNestedDocument(BSONDepth::getMaxAllowableDepth() + 1), getExpCtx()),
- UserException,
+ AssertionException,
ErrorCodes::Overflow);
}
} // namespace
diff --git a/src/mongo/db/pipeline/document_source_replace_root_test.cpp b/src/mongo/db/pipeline/document_source_replace_root_test.cpp
index 51411531022..321afbc8220 100644
--- a/src/mongo/db/pipeline/document_source_replace_root_test.cpp
+++ b/src/mongo/db/pipeline/document_source_replace_root_test.cpp
@@ -213,18 +213,18 @@ TEST_F(ReplaceRootBasics, ErrorsWhenNewRootDoesNotEvaluateToAnObject) {
// A string is not an object.
auto mock = DocumentSourceMock::create(Document{{"a", "hello"_sd}});
replaceRoot->setSource(mock.get());
- ASSERT_THROWS_CODE(replaceRoot->getNext(), UserException, 40228);
+ ASSERT_THROWS_CODE(replaceRoot->getNext(), AssertionException, 40228);
// An integer is not an object.
mock = DocumentSourceMock::create(Document{{"a", 5}});
replaceRoot->setSource(mock.get());
- ASSERT_THROWS_CODE(replaceRoot->getNext(), UserException, 40228);
+ ASSERT_THROWS_CODE(replaceRoot->getNext(), AssertionException, 40228);
// Literals are not objects.
replaceRoot = createReplaceRoot(BSON("newRoot" << BSON("$literal" << 1)));
mock = DocumentSourceMock::create(Document());
replaceRoot->setSource(mock.get());
- ASSERT_THROWS_CODE(replaceRoot->getNext(), UserException, 40228);
+ ASSERT_THROWS_CODE(replaceRoot->getNext(), AssertionException, 40228);
assertExhausted(replaceRoot);
// Most operator expressions do not resolve to objects.
@@ -232,7 +232,7 @@ TEST_F(ReplaceRootBasics, ErrorsWhenNewRootDoesNotEvaluateToAnObject) {
<< "$a")));
mock = DocumentSourceMock::create(Document{{"a", true}});
replaceRoot->setSource(mock.get());
- ASSERT_THROWS_CODE(replaceRoot->getNext(), UserException, 40228);
+ ASSERT_THROWS_CODE(replaceRoot->getNext(), AssertionException, 40228);
assertExhausted(replaceRoot);
}
@@ -244,12 +244,12 @@ TEST_F(ReplaceRootBasics, ErrorsIfNewRootFieldPathDoesNotExist) {
auto mock = DocumentSourceMock::create(Document());
replaceRoot->setSource(mock.get());
- ASSERT_THROWS_CODE(replaceRoot->getNext(), UserException, 40228);
+ ASSERT_THROWS_CODE(replaceRoot->getNext(), AssertionException, 40228);
assertExhausted(replaceRoot);
mock = DocumentSourceMock::create(Document{{"e", Document{{"b", Document{{"c", 3}}}}}});
replaceRoot->setSource(mock.get());
- ASSERT_THROWS_CODE(replaceRoot->getNext(), UserException, 40228);
+ ASSERT_THROWS_CODE(replaceRoot->getNext(), AssertionException, 40228);
assertExhausted(replaceRoot);
}
@@ -286,7 +286,7 @@ TEST_F(ReplaceRootBasics, ReplaceRootWithRemoveSystemVariableThrows) {
auto mock = DocumentSourceMock::create({inputDoc});
replaceRoot->setSource(mock.get());
- ASSERT_THROWS_CODE(replaceRoot->getNext(), UserException, 40228);
+ ASSERT_THROWS_CODE(replaceRoot->getNext(), AssertionException, 40228);
}
/**
@@ -310,10 +310,10 @@ public:
// Verify that the creation of a $replaceRoot stage requires an object specification
TEST_F(ReplaceRootSpec, CreationRequiresObjectSpecification) {
- ASSERT_THROWS_CODE(createReplaceRoot(BSON("$replaceRoot" << 1)), UserException, 40229);
+ ASSERT_THROWS_CODE(createReplaceRoot(BSON("$replaceRoot" << 1)), AssertionException, 40229);
ASSERT_THROWS_CODE(createReplaceRoot(BSON("$replaceRoot"
<< "string")),
- UserException,
+ AssertionException,
40229);
}
@@ -323,30 +323,31 @@ TEST_F(ReplaceRootSpec, OnlyValidOptionInObjectSpecIsNewRoot) {
<< "$a"
<< "root"
<< 2))),
- UserException,
+ AssertionException,
40230);
ASSERT_THROWS_CODE(createReplaceRoot(createSpec(BSON("newRoot"
<< "$a"
<< "path"
<< 2))),
- UserException,
+ AssertionException,
40230);
ASSERT_THROWS_CODE(createReplaceRoot(createSpec(BSON("path"
<< "$a"))),
- UserException,
+ AssertionException,
40230);
}
// Verify that $replaceRoot requires a valid expression as input to the newRoot option.
TEST_F(ReplaceRootSpec, RequiresExpressionForNewRootOption) {
- ASSERT_THROWS_CODE(createReplaceRoot(createSpec(BSONObj())), UserException, 40231);
+ ASSERT_THROWS_CODE(createReplaceRoot(createSpec(BSONObj())), AssertionException, 40231);
ASSERT_THROWS(createReplaceRoot(createSpec(BSON("newRoot"
<< "$$$a"))),
- UserException);
+ AssertionException);
ASSERT_THROWS(createReplaceRoot(createSpec(BSON("newRoot"
<< "$$a"))),
- UserException);
- ASSERT_THROWS(createReplaceRoot(createFullSpec(BSON("$map" << BSON("a" << 1)))), UserException);
+ AssertionException);
+ ASSERT_THROWS(createReplaceRoot(createFullSpec(BSON("$map" << BSON("a" << 1)))),
+ AssertionException);
}
// Verify that newRoot accepts all types of expressions.
diff --git a/src/mongo/db/pipeline/document_source_sample_test.cpp b/src/mongo/db/pipeline/document_source_sample_test.cpp
index 528676cb294..417a2ff5a34 100644
--- a/src/mongo/db/pipeline/document_source_sample_test.cpp
+++ b/src/mongo/db/pipeline/document_source_sample_test.cpp
@@ -220,32 +220,32 @@ public:
};
TEST_F(InvalidSampleSpec, NonObject) {
- ASSERT_THROWS_CODE(createSample(BSON("$sample" << 1)), UserException, 28745);
+ ASSERT_THROWS_CODE(createSample(BSON("$sample" << 1)), AssertionException, 28745);
ASSERT_THROWS_CODE(createSample(BSON("$sample"
<< "string")),
- UserException,
+ AssertionException,
28745);
}
TEST_F(InvalidSampleSpec, NonNumericSize) {
ASSERT_THROWS_CODE(createSample(createSpec(BSON("size"
<< "string"))),
- UserException,
+ AssertionException,
28746);
}
TEST_F(InvalidSampleSpec, NegativeSize) {
- ASSERT_THROWS_CODE(createSample(createSpec(BSON("size" << -1))), UserException, 28747);
- ASSERT_THROWS_CODE(createSample(createSpec(BSON("size" << -1.0))), UserException, 28747);
+ ASSERT_THROWS_CODE(createSample(createSpec(BSON("size" << -1))), AssertionException, 28747);
+ ASSERT_THROWS_CODE(createSample(createSpec(BSON("size" << -1.0))), AssertionException, 28747);
}
TEST_F(InvalidSampleSpec, ExtraOption) {
ASSERT_THROWS_CODE(
- createSample(createSpec(BSON("size" << 1 << "extra" << 2))), UserException, 28748);
+ createSample(createSpec(BSON("size" << 1 << "extra" << 2))), AssertionException, 28748);
}
TEST_F(InvalidSampleSpec, MissingSize) {
- ASSERT_THROWS_CODE(createSample(createSpec(BSONObj())), UserException, 28749);
+ ASSERT_THROWS_CODE(createSample(createSpec(BSONObj())), AssertionException, 28749);
}
//
@@ -344,7 +344,7 @@ TEST_F(SampleFromRandomCursorBasics, TooManyDups) {
ASSERT_TRUE(sample()->getNext().isAdvanced());
// The rest are duplicates, should error.
- ASSERT_THROWS_CODE(sample()->getNext(), UserException, 28799);
+ ASSERT_THROWS_CODE(sample()->getNext(), AssertionException, 28799);
}
/**
@@ -354,7 +354,7 @@ TEST_F(SampleFromRandomCursorBasics, MissingIdField) {
// Once with only a bad document.
createSample(2); // _idField is '_id'.
source()->queue.push_back(DOC("non_id" << 2));
- ASSERT_THROWS_CODE(sample()->getNext(), UserException, 28793);
+ ASSERT_THROWS_CODE(sample()->getNext(), AssertionException, 28793);
// Again, with some regular documents before a bad one.
createSample(2); // _idField is '_id'.
@@ -365,7 +365,7 @@ TEST_F(SampleFromRandomCursorBasics, MissingIdField) {
// First should be successful.
ASSERT_TRUE(sample()->getNext().isAdvanced());
- ASSERT_THROWS_CODE(sample()->getNext(), UserException, 28793);
+ ASSERT_THROWS_CODE(sample()->getNext(), AssertionException, 28793);
}
/**
diff --git a/src/mongo/db/pipeline/document_source_skip.h b/src/mongo/db/pipeline/document_source_skip.h
index a69f5e59eb5..8fc27a59f87 100644
--- a/src/mongo/db/pipeline/document_source_skip.h
+++ b/src/mongo/db/pipeline/document_source_skip.h
@@ -86,7 +86,7 @@ public:
/**
* Parses the user-supplied BSON into a $skip stage.
*
- * Throws a UserException if 'elem' is an invalid $skip specification.
+ * Throws a AssertionException if 'elem' is an invalid $skip specification.
*/
static boost::intrusive_ptr<DocumentSource> createFromBson(
BSONElement elem, const boost::intrusive_ptr<ExpressionContext>& pExpCtx);
diff --git a/src/mongo/db/pipeline/document_source_sort_by_count_test.cpp b/src/mongo/db/pipeline/document_source_sort_by_count_test.cpp
index 12975e96149..1bc21c0eab5 100644
--- a/src/mongo/db/pipeline/document_source_sort_by_count_test.cpp
+++ b/src/mongo/db/pipeline/document_source_sort_by_count_test.cpp
@@ -120,22 +120,22 @@ public:
TEST_F(InvalidSortByCountSpec, NonObjectNonStringSpec) {
BSONObj spec = BSON("$sortByCount" << 1);
- ASSERT_THROWS_CODE(createSortByCount(spec), UserException, 40149);
+ ASSERT_THROWS_CODE(createSortByCount(spec), AssertionException, 40149);
spec = BSON("$sortByCount" << BSONNULL);
- ASSERT_THROWS_CODE(createSortByCount(spec), UserException, 40149);
+ ASSERT_THROWS_CODE(createSortByCount(spec), AssertionException, 40149);
}
TEST_F(InvalidSortByCountSpec, NonExpressionInObjectSpec) {
BSONObj spec = BSON("$sortByCount" << BSON("field1"
<< "$x"));
- ASSERT_THROWS_CODE(createSortByCount(spec), UserException, 40147);
+ ASSERT_THROWS_CODE(createSortByCount(spec), AssertionException, 40147);
}
TEST_F(InvalidSortByCountSpec, NonFieldPathStringSpec) {
BSONObj spec = BSON("$sortByCount"
<< "test");
- ASSERT_THROWS_CODE(createSortByCount(spec), UserException, 40148);
+ ASSERT_THROWS_CODE(createSortByCount(spec), AssertionException, 40148);
}
} // namespace
diff --git a/src/mongo/db/pipeline/document_source_sort_test.cpp b/src/mongo/db/pipeline/document_source_sort_test.cpp
index 92b0f4dd07c..25362138a9c 100644
--- a/src/mongo/db/pipeline/document_source_sort_test.cpp
+++ b/src/mongo/db/pipeline/document_source_sort_test.cpp
@@ -95,26 +95,26 @@ private:
TEST_F(DocumentSourceSortTest, RejectsNonObjectSpec) {
BSONObj spec = BSON("$sort" << 1);
BSONElement specElement = spec.firstElement();
- ASSERT_THROWS(DocumentSourceSort::createFromBson(specElement, getExpCtx()), UserException);
+ ASSERT_THROWS(DocumentSourceSort::createFromBson(specElement, getExpCtx()), AssertionException);
}
TEST_F(DocumentSourceSortTest, RejectsEmptyObjectSpec) {
BSONObj spec = BSON("$sort" << BSONObj());
BSONElement specElement = spec.firstElement();
- ASSERT_THROWS(DocumentSourceSort::createFromBson(specElement, getExpCtx()), UserException);
+ ASSERT_THROWS(DocumentSourceSort::createFromBson(specElement, getExpCtx()), AssertionException);
}
TEST_F(DocumentSourceSortTest, RejectsSpecWithNonNumericValues) {
BSONObj spec = BSON("$sort" << BSON("a"
<< "b"));
BSONElement specElement = spec.firstElement();
- ASSERT_THROWS(DocumentSourceSort::createFromBson(specElement, getExpCtx()), UserException);
+ ASSERT_THROWS(DocumentSourceSort::createFromBson(specElement, getExpCtx()), AssertionException);
}
TEST_F(DocumentSourceSortTest, RejectsSpecWithZeroAsValue) {
BSONObj spec = BSON("$sort" << BSON("a" << 0));
BSONElement specElement = spec.firstElement();
- ASSERT_THROWS(DocumentSourceSort::createFromBson(specElement, getExpCtx()), UserException);
+ ASSERT_THROWS(DocumentSourceSort::createFromBson(specElement, getExpCtx()), AssertionException);
}
TEST_F(DocumentSourceSortTest, SortWithLimit) {
@@ -446,7 +446,7 @@ TEST_F(DocumentSourceSortExecutionTest,
Document{{"_id", 1}, {"largeStr", largeStr}}});
sort->setSource(mock.get());
- ASSERT_THROWS_CODE(sort->getNext(), UserException, 16819);
+ ASSERT_THROWS_CODE(sort->getNext(), AssertionException, 16819);
}
TEST_F(DocumentSourceSortExecutionTest, ShouldCorrectlyTrackMemoryUsageBetweenPauses) {
@@ -467,7 +467,7 @@ TEST_F(DocumentSourceSortExecutionTest, ShouldCorrectlyTrackMemoryUsageBetweenPa
ASSERT_TRUE(sort->getNext().isPaused());
// The next should realize it's used too much memory.
- ASSERT_THROWS_CODE(sort->getNext(), UserException, 16819);
+ ASSERT_THROWS_CODE(sort->getNext(), AssertionException, 16819);
}
} // namespace
diff --git a/src/mongo/db/pipeline/document_source_unwind_test.cpp b/src/mongo/db/pipeline/document_source_unwind_test.cpp
index 8dcf1ed9a32..8c01c50bde9 100644
--- a/src/mongo/db/pipeline/document_source_unwind_test.cpp
+++ b/src/mongo/db/pipeline/document_source_unwind_test.cpp
@@ -749,25 +749,26 @@ TEST_F(UnwindStageTest, UnwindIncludesIndexPathWhenIncludingIndex) {
//
TEST_F(UnwindStageTest, ShouldRejectNonObjectNonString) {
- ASSERT_THROWS_CODE(createUnwind(BSON("$unwind" << 1)), UserException, 15981);
+ ASSERT_THROWS_CODE(createUnwind(BSON("$unwind" << 1)), AssertionException, 15981);
}
TEST_F(UnwindStageTest, ShouldRejectSpecWithoutPath) {
- ASSERT_THROWS_CODE(createUnwind(BSON("$unwind" << BSONObj())), UserException, 28812);
+ ASSERT_THROWS_CODE(createUnwind(BSON("$unwind" << BSONObj())), AssertionException, 28812);
}
TEST_F(UnwindStageTest, ShouldRejectNonStringPath) {
- ASSERT_THROWS_CODE(createUnwind(BSON("$unwind" << BSON("path" << 2))), UserException, 28808);
+ ASSERT_THROWS_CODE(
+ createUnwind(BSON("$unwind" << BSON("path" << 2))), AssertionException, 28808);
}
TEST_F(UnwindStageTest, ShouldRejectNonDollarPrefixedPath) {
ASSERT_THROWS_CODE(createUnwind(BSON("$unwind"
<< "somePath")),
- UserException,
+ AssertionException,
28818);
ASSERT_THROWS_CODE(createUnwind(BSON("$unwind" << BSON("path"
<< "somePath"))),
- UserException,
+ AssertionException,
28818);
}
@@ -776,7 +777,7 @@ TEST_F(UnwindStageTest, ShouldRejectNonBoolPreserveNullAndEmptyArrays) {
<< "$x"
<< "preserveNullAndEmptyArrays"
<< 2))),
- UserException,
+ AssertionException,
28809);
}
@@ -785,7 +786,7 @@ TEST_F(UnwindStageTest, ShouldRejectNonStringIncludeArrayIndex) {
<< "$x"
<< "includeArrayIndex"
<< 2))),
- UserException,
+ AssertionException,
28810);
}
@@ -794,7 +795,7 @@ TEST_F(UnwindStageTest, ShouldRejectEmptyStringIncludeArrayIndex) {
<< "$x"
<< "includeArrayIndex"
<< ""))),
- UserException,
+ AssertionException,
28810);
}
@@ -803,13 +804,13 @@ TEST_F(UnwindStageTest, ShoudlRejectDollarPrefixedIncludeArrayIndex) {
<< "$x"
<< "includeArrayIndex"
<< "$"))),
- UserException,
+ AssertionException,
28822);
ASSERT_THROWS_CODE(createUnwind(BSON("$unwind" << BSON("path"
<< "$x"
<< "includeArrayIndex"
<< "$path"))),
- UserException,
+ AssertionException,
28822);
}
@@ -820,13 +821,13 @@ TEST_F(UnwindStageTest, ShouldRejectUnrecognizedOption) {
<< true
<< "foo"
<< 3))),
- UserException,
+ AssertionException,
28811);
ASSERT_THROWS_CODE(createUnwind(BSON("$unwind" << BSON("path"
<< "$x"
<< "foo"
<< 3))),
- UserException,
+ AssertionException,
28811);
}
diff --git a/src/mongo/db/pipeline/document_value_test.cpp b/src/mongo/db/pipeline/document_value_test.cpp
index 4cc91d023e1..34f993f1180 100644
--- a/src/mongo/db/pipeline/document_value_test.cpp
+++ b/src/mongo/db/pipeline/document_value_test.cpp
@@ -143,7 +143,7 @@ TEST(DocumentSerialization, CannotSerializeDocumentThatExceedsDepthLimit) {
Document doc(builder.obj());
BSONObjBuilder throwaway;
- ASSERT_THROWS_CODE(doc.toBson(&throwaway), UserException, ErrorCodes::Overflow);
+ ASSERT_THROWS_CODE(doc.toBson(&throwaway), AssertionException, ErrorCodes::Overflow);
throwaway.abandon();
}
@@ -582,7 +582,7 @@ TEST(MetaFields, BadSerialization) {
BufReader reader(bb.buf(), bb.len());
ASSERT_THROWS_CODE(
Document::deserializeForSorter(reader, Document::SorterDeserializeSettings()),
- UserException,
+ AssertionException,
28744);
}
} // namespace MetaFields
@@ -1035,7 +1035,7 @@ public:
virtual ~ToIntBase() {}
void run() {
if (asserts())
- ASSERT_THROWS(value().coerceToInt(), UserException);
+ ASSERT_THROWS(value().coerceToInt(), AssertionException);
else
ASSERT_EQUALS(expected(), value().coerceToInt());
}
@@ -1104,7 +1104,7 @@ class UndefinedToInt : public ToIntBase {
class StringToInt {
public:
void run() {
- ASSERT_THROWS(Value(StringData()).coerceToInt(), UserException);
+ ASSERT_THROWS(Value(StringData()).coerceToInt(), AssertionException);
}
};
@@ -1113,7 +1113,7 @@ public:
virtual ~ToLongBase() {}
void run() {
if (asserts())
- ASSERT_THROWS(value().coerceToLong(), UserException);
+ ASSERT_THROWS(value().coerceToLong(), AssertionException);
else
ASSERT_EQUALS(expected(), value().coerceToLong());
}
@@ -1182,7 +1182,7 @@ class UndefinedToLong : public ToLongBase {
class StringToLong {
public:
void run() {
- ASSERT_THROWS(Value(StringData()).coerceToLong(), UserException);
+ ASSERT_THROWS(Value(StringData()).coerceToLong(), AssertionException);
}
};
@@ -1191,7 +1191,7 @@ public:
virtual ~ToDoubleBase() {}
void run() {
if (asserts())
- ASSERT_THROWS(value().coerceToDouble(), UserException);
+ ASSERT_THROWS(value().coerceToDouble(), AssertionException);
else
ASSERT_EQUALS(expected(), value().coerceToDouble());
}
@@ -1261,7 +1261,7 @@ class UndefinedToDouble : public ToDoubleBase {
class StringToDouble {
public:
void run() {
- ASSERT_THROWS(Value(StringData()).coerceToDouble(), UserException);
+ ASSERT_THROWS(Value(StringData()).coerceToDouble(), AssertionException);
}
};
@@ -1304,7 +1304,7 @@ class TimestampToDate : public ToDateBase {
class StringToDate {
public:
void run() {
- ASSERT_THROWS(Value(StringData()).coerceToDate(), UserException);
+ ASSERT_THROWS(Value(StringData()).coerceToDate(), AssertionException);
}
};
@@ -1400,7 +1400,7 @@ class UndefinedToString : public ToStringBase {
class DocumentToString {
public:
void run() {
- ASSERT_THROWS(Value(mongo::Document()).coerceToString(), UserException);
+ ASSERT_THROWS(Value(mongo::Document()).coerceToString(), AssertionException);
}
};
@@ -1417,7 +1417,8 @@ public:
class DateToTimestamp {
public:
void run() {
- ASSERT_THROWS(Value(Date_t::fromMillisSinceEpoch(1010)).coerceToTimestamp(), UserException);
+ ASSERT_THROWS(Value(Date_t::fromMillisSinceEpoch(1010)).coerceToTimestamp(),
+ AssertionException);
}
};
diff --git a/src/mongo/db/pipeline/expression_test.cpp b/src/mongo/db/pipeline/expression_test.cpp
index b05a1bc1515..bd3abd1ffc3 100644
--- a/src/mongo/db/pipeline/expression_test.cpp
+++ b/src/mongo/db/pipeline/expression_test.cpp
@@ -980,7 +980,7 @@ public:
intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
intrusive_ptr<ExpressionNary> expression = new ExpressionAdd(expCtx);
expression->addOperand(ExpressionConstant::create(expCtx, Value("a"_sd)));
- ASSERT_THROWS(expression->evaluate(Document()), UserException);
+ ASSERT_THROWS(expression->evaluate(Document()), AssertionException);
}
};
@@ -991,7 +991,7 @@ public:
intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
intrusive_ptr<ExpressionNary> expression = new ExpressionAdd(expCtx);
expression->addOperand(ExpressionConstant::create(expCtx, Value(true)));
- ASSERT_THROWS(expression->evaluate(Document()), UserException);
+ ASSERT_THROWS(expression->evaluate(Document()), AssertionException);
}
};
@@ -1680,7 +1680,7 @@ public:
BSONObj specObject = BSON("" << spec());
BSONElement specElement = specObject.firstElement();
VariablesParseState vps = expCtx->variablesParseState;
- ASSERT_THROWS(Expression::parseOperand(expCtx, specElement, vps), UserException);
+ ASSERT_THROWS(Expression::parseOperand(expCtx, specElement, vps), AssertionException);
}
protected:
@@ -2186,7 +2186,7 @@ class Invalid {
public:
void run() {
intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
- ASSERT_THROWS(ExpressionFieldPath::create(expCtx, ""), UserException);
+ ASSERT_THROWS(ExpressionFieldPath::create(expCtx, ""), AssertionException);
}
};
@@ -2525,34 +2525,35 @@ TEST(ObjectParsing, ShouldAcceptExpressionAsValue) {
TEST(ExpressionObjectParse, ShouldRejectDottedFieldNames) {
intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
VariablesParseState vps = expCtx->variablesParseState;
- ASSERT_THROWS(ExpressionObject::parse(expCtx, BSON("a.b" << 1), vps), UserException);
+ ASSERT_THROWS(ExpressionObject::parse(expCtx, BSON("a.b" << 1), vps), AssertionException);
ASSERT_THROWS(ExpressionObject::parse(expCtx, BSON("c" << 3 << "a.b" << 1), vps),
- UserException);
+ AssertionException);
ASSERT_THROWS(ExpressionObject::parse(expCtx, BSON("a.b" << 1 << "c" << 3), vps),
- UserException);
+ AssertionException);
}
TEST(ExpressionObjectParse, ShouldRejectDuplicateFieldNames) {
intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
VariablesParseState vps = expCtx->variablesParseState;
- ASSERT_THROWS(ExpressionObject::parse(expCtx, BSON("a" << 1 << "a" << 1), vps), UserException);
+ ASSERT_THROWS(ExpressionObject::parse(expCtx, BSON("a" << 1 << "a" << 1), vps),
+ AssertionException);
ASSERT_THROWS(ExpressionObject::parse(expCtx, BSON("a" << 1 << "b" << 2 << "a" << 1), vps),
- UserException);
+ AssertionException);
ASSERT_THROWS(
ExpressionObject::parse(expCtx, BSON("a" << BSON("c" << 1) << "b" << 2 << "a" << 1), vps),
- UserException);
+ AssertionException);
ASSERT_THROWS(
ExpressionObject::parse(expCtx, BSON("a" << 1 << "b" << 2 << "a" << BSON("c" << 1)), vps),
- UserException);
+ AssertionException);
}
TEST(ExpressionObjectParse, ShouldRejectInvalidFieldName) {
intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
VariablesParseState vps = expCtx->variablesParseState;
- ASSERT_THROWS(ExpressionObject::parse(expCtx, BSON("$a" << 1), vps), UserException);
- ASSERT_THROWS(ExpressionObject::parse(expCtx, BSON("" << 1), vps), UserException);
+ ASSERT_THROWS(ExpressionObject::parse(expCtx, BSON("$a" << 1), vps), AssertionException);
+ ASSERT_THROWS(ExpressionObject::parse(expCtx, BSON("" << 1), vps), AssertionException);
ASSERT_THROWS(ExpressionObject::parse(expCtx, BSON(std::string("a\0b", 3) << 1), vps),
- UserException);
+ AssertionException);
}
TEST(ExpressionObjectParse, ShouldRejectInvalidFieldPathAsValue) {
@@ -2562,7 +2563,7 @@ TEST(ExpressionObjectParse, ShouldRejectInvalidFieldPathAsValue) {
BSON("a"
<< "$field."),
vps),
- UserException);
+ AssertionException);
}
TEST(ParseObject, ShouldRejectExpressionAsTheSecondField) {
@@ -2571,7 +2572,7 @@ TEST(ParseObject, ShouldRejectExpressionAsTheSecondField) {
ASSERT_THROWS(
ExpressionObject::parse(
expCtx, BSON("a" << BSON("$and" << BSONArray()) << "$or" << BSONArray()), vps),
- UserException);
+ AssertionException);
}
//
@@ -3043,27 +3044,27 @@ TEST(ParseExpression, ShouldRecognizeConstExpression) {
}
TEST(ParseExpression, ShouldRejectUnknownExpression) {
- ASSERT_THROWS(parseExpression(BSON("$invalid" << 1)), UserException);
+ ASSERT_THROWS(parseExpression(BSON("$invalid" << 1)), AssertionException);
}
TEST(ParseExpression, ShouldRejectExpressionArgumentsWhichAreNotInArray) {
ASSERT_THROWS(parseExpression(BSON("$strcasecmp"
<< "foo")),
- UserException);
+ AssertionException);
}
TEST(ParseExpression, ShouldRejectExpressionWithWrongNumberOfArguments) {
- ASSERT_THROWS(parseExpression(BSON("$strcasecmp" << BSON_ARRAY("foo"))), UserException);
+ ASSERT_THROWS(parseExpression(BSON("$strcasecmp" << BSON_ARRAY("foo"))), AssertionException);
}
TEST(ParseExpression, ShouldRejectObjectWithTwoTopLevelExpressions) {
ASSERT_THROWS(parseExpression(BSON("$and" << BSONArray() << "$or" << BSONArray())),
- UserException);
+ AssertionException);
}
TEST(ParseExpression, ShouldRejectExpressionIfItsNotTheOnlyField) {
ASSERT_THROWS(parseExpression(BSON("$and" << BSONArray() << "a" << BSON("$or" << BSONArray()))),
- UserException);
+ AssertionException);
}
TEST(ParseExpression, ShouldParseExpressionWithMultipleArguments) {
@@ -3242,7 +3243,7 @@ public:
Expression::parseExpression(expCtx, obj, vps);
expr->evaluate(Document());
},
- UserException);
+ AssertionException);
}
}
}
@@ -3754,7 +3755,7 @@ TEST(ExpressionSubstrCPTest, DoesThrowWithBadContinuationByte) {
const auto continuationByte = "\x80\x00"_sd;
const auto expr = Expression::parseExpression(
expCtx, BSON("$substrCP" << BSON_ARRAY(continuationByte << 0 << 1)), vps);
- ASSERT_THROWS({ expr->evaluate(Document()); }, UserException);
+ ASSERT_THROWS({ expr->evaluate(Document()); }, AssertionException);
}
TEST(ExpressionSubstrCPTest, DoesThrowWithInvalidLeadingByte) {
@@ -3764,7 +3765,7 @@ TEST(ExpressionSubstrCPTest, DoesThrowWithInvalidLeadingByte) {
const auto leadingByte = "\xFF\x00"_sd;
const auto expr = Expression::parseExpression(
expCtx, BSON("$substrCP" << BSON_ARRAY(leadingByte << 0 << 1)), vps);
- ASSERT_THROWS({ expr->evaluate(Document()); }, UserException);
+ ASSERT_THROWS({ expr->evaluate(Document()); }, AssertionException);
}
TEST(ExpressionSubstrCPTest, WithStandardValue) {
@@ -3991,25 +3992,26 @@ TEST(ExpressionMergeObjects, MergingSingleArgumentArrayShouldUnwindAndMerge) {
TEST(ExpressionMergeObjects, MergingArrayWithDocumentShouldThrowException) {
std::vector<Document> first = {Document({{"a", 1}}), Document({{"a", 2}})};
auto second = Document({{"b", 2}});
- ASSERT_THROWS_CODE(evaluateExpression("$mergeObjects", {first, second}), UserException, 40400);
+ ASSERT_THROWS_CODE(
+ evaluateExpression("$mergeObjects", {first, second}), AssertionException, 40400);
}
TEST(ExpressionMergeObjects, MergingArrayContainingInvalidTypesShouldThrowException) {
std::vector<Value> first = {Value(Document({{"validType", 1}})), Value("invalidType"_sd)};
- ASSERT_THROWS_CODE(evaluateExpression("$mergeObjects", {first}), UserException, 40400);
+ ASSERT_THROWS_CODE(evaluateExpression("$mergeObjects", {first}), AssertionException, 40400);
}
TEST(ExpressionMergeObjects, MergingNonObjectsShouldThrowException) {
ASSERT_THROWS_CODE(
- evaluateExpression("$mergeObjects", {"invalidArg"_sd}), UserException, 40400);
+ evaluateExpression("$mergeObjects", {"invalidArg"_sd}), AssertionException, 40400);
ASSERT_THROWS_CODE(
evaluateExpression("$mergeObjects", {"invalidArg"_sd, Document({{"validArg", 1}})}),
- UserException,
+ AssertionException,
40400);
ASSERT_THROWS_CODE(evaluateExpression("$mergeObjects", {1, Document({{"validArg", 1}})}),
- UserException,
+ AssertionException,
40400);
}
@@ -4173,7 +4175,7 @@ public:
Expression::parseExpression(expCtx, obj, vps);
expr->evaluate(Document());
},
- UserException);
+ AssertionException);
}
}
}
@@ -4650,7 +4652,7 @@ TEST_F(DateExpressionTest, ParsingRejectsUnrecognizedFieldsInObjectSpecification
<< "extra"
<< 4));
ASSERT_THROWS_CODE(Expression::parseExpression(expCtx, spec, expCtx->variablesParseState),
- UserException,
+ AssertionException,
40535);
}
}
@@ -4660,7 +4662,7 @@ TEST_F(DateExpressionTest, ParsingRejectsEmptyObjectSpecification) {
for (auto&& expName : dateExpressions) {
BSONObj spec = BSON(expName << BSONObj());
ASSERT_THROWS_CODE(Expression::parseExpression(expCtx, spec, expCtx->variablesParseState),
- UserException,
+ AssertionException,
40539);
}
}
@@ -4671,7 +4673,7 @@ TEST_F(DateExpressionTest, RejectsEmptyArray) {
BSONObj spec = BSON(expName << BSONArray());
// It will parse as an ExpressionArray, and fail at runtime.
ASSERT_THROWS_CODE(Expression::parseExpression(expCtx, spec, expCtx->variablesParseState),
- UserException,
+ AssertionException,
40536);
}
}
@@ -4683,7 +4685,7 @@ TEST_F(DateExpressionTest, RejectsArraysWithMoreThanOneElement) {
<< "$tz"));
// It will parse as an ExpressionArray, and fail at runtime.
ASSERT_THROWS_CODE(Expression::parseExpression(expCtx, spec, expCtx->variablesParseState),
- UserException,
+ AssertionException,
40536);
}
}
@@ -4696,14 +4698,14 @@ TEST_F(DateExpressionTest, RejectsArraysWithinObjectSpecification) {
// It will parse as an ExpressionArray, and fail at runtime.
auto dateExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState);
auto contextDoc = Document{{"_id", 0}};
- ASSERT_THROWS_CODE(dateExp->evaluate(contextDoc), UserException, 16006);
+ ASSERT_THROWS_CODE(dateExp->evaluate(contextDoc), AssertionException, 16006);
// Test that it rejects an array for the timezone option.
spec =
BSON(expName << BSON("date" << Date_t{} << "timezone" << BSON_ARRAY("Europe/London")));
dateExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState);
contextDoc = Document{{"_id", 0}};
- ASSERT_THROWS_CODE(dateExp->evaluate(contextDoc), UserException, 40533);
+ ASSERT_THROWS_CODE(dateExp->evaluate(contextDoc), AssertionException, 40533);
}
}
@@ -4713,7 +4715,7 @@ TEST_F(DateExpressionTest, RejectsTypesThatCannotCoerceToDate) {
BSONObj spec = BSON(expName << "$stringField");
auto dateExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState);
auto contextDoc = Document{{"stringField", "string"_sd}};
- ASSERT_THROWS_CODE(dateExp->evaluate(contextDoc), UserException, 16006);
+ ASSERT_THROWS_CODE(dateExp->evaluate(contextDoc), AssertionException, 16006);
}
}
@@ -4744,7 +4746,7 @@ TEST_F(DateExpressionTest, RejectsNonStringTimezone) {
<< "$intField"));
auto dateExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState);
auto contextDoc = Document{{"intField", 4}};
- ASSERT_THROWS_CODE(dateExp->evaluate(contextDoc), UserException, 40533);
+ ASSERT_THROWS_CODE(dateExp->evaluate(contextDoc), AssertionException, 40533);
}
}
@@ -4755,7 +4757,7 @@ TEST_F(DateExpressionTest, RejectsUnrecognizedTimeZoneSpecification) {
<< "UNRECOGNIZED!"));
auto dateExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState);
auto contextDoc = Document{{"_id", 0}};
- ASSERT_THROWS_CODE(dateExp->evaluate(contextDoc), UserException, 40485);
+ ASSERT_THROWS_CODE(dateExp->evaluate(contextDoc), AssertionException, 40485);
}
}
@@ -5078,7 +5080,7 @@ TEST_F(ExpressionDateFromStringTest, RejectsUnparsableString) {
auto spec = BSON("$dateFromString" << BSON("dateString"
<< "60.Monday1770/06:59"));
auto dateExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState);
- ASSERT_THROWS_CODE(dateExp->evaluate({}), UserException, 40553);
+ ASSERT_THROWS_CODE(dateExp->evaluate({}), AssertionException, 40553);
}
TEST_F(ExpressionDateFromStringTest, RejectsTimeZoneInString) {
@@ -5087,12 +5089,12 @@ TEST_F(ExpressionDateFromStringTest, RejectsTimeZoneInString) {
auto spec = BSON("$dateFromString" << BSON("dateString"
<< "2017-07-13T10:02:57 Europe/London"));
auto dateExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState);
- ASSERT_THROWS_CODE(dateExp->evaluate({}), UserException, 40553);
+ ASSERT_THROWS_CODE(dateExp->evaluate({}), AssertionException, 40553);
spec = BSON("$dateFromString" << BSON("dateString"
<< "July 4, 2017 Europe/London"));
dateExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState);
- ASSERT_THROWS_CODE(dateExp->evaluate({}), UserException, 40553);
+ ASSERT_THROWS_CODE(dateExp->evaluate({}), AssertionException, 40553);
}
TEST_F(ExpressionDateFromStringTest, RejectsTimeZoneInStringAndArgument) {
@@ -5104,7 +5106,7 @@ TEST_F(ExpressionDateFromStringTest, RejectsTimeZoneInStringAndArgument) {
<< "timezone"
<< "Europe/London"));
auto dateExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState);
- ASSERT_THROWS_CODE(dateExp->evaluate({}), UserException, 40551);
+ ASSERT_THROWS_CODE(dateExp->evaluate({}), AssertionException, 40551);
// Test with timezone abbreviation and timezone
spec = BSON("$dateFromString" << BSON("dateString"
@@ -5112,7 +5114,7 @@ TEST_F(ExpressionDateFromStringTest, RejectsTimeZoneInStringAndArgument) {
<< "timezone"
<< "Europe/London"));
dateExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState);
- ASSERT_THROWS_CODE(dateExp->evaluate({}), UserException, 40551);
+ ASSERT_THROWS_CODE(dateExp->evaluate({}), AssertionException, 40551);
// Test with GMT offset and timezone
spec = BSON("$dateFromString" << BSON("dateString"
@@ -5120,7 +5122,7 @@ TEST_F(ExpressionDateFromStringTest, RejectsTimeZoneInStringAndArgument) {
<< "timezone"
<< "Europe/London"));
dateExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState);
- ASSERT_THROWS_CODE(dateExp->evaluate({}), UserException, 40554);
+ ASSERT_THROWS_CODE(dateExp->evaluate({}), AssertionException, 40554);
// Test with GMT offset and GMT timezone
spec = BSON("$dateFromString" << BSON("dateString"
@@ -5128,7 +5130,7 @@ TEST_F(ExpressionDateFromStringTest, RejectsTimeZoneInStringAndArgument) {
<< "timezone"
<< "GMT"));
dateExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState);
- ASSERT_THROWS_CODE(dateExp->evaluate({}), UserException, 40554);
+ ASSERT_THROWS_CODE(dateExp->evaluate({}), AssertionException, 40554);
}
TEST_F(ExpressionDateFromStringTest, ReadWithUTCOffset) {
diff --git a/src/mongo/db/pipeline/field_path.h b/src/mongo/db/pipeline/field_path.h
index 2a93e607078..171bf89a5a3 100644
--- a/src/mongo/db/pipeline/field_path.h
+++ b/src/mongo/db/pipeline/field_path.h
@@ -42,7 +42,7 @@ namespace mongo {
class FieldPath {
public:
/**
- * Throws a UserException if a field name does not pass validation.
+ * Throws a AssertionException if a field name does not pass validation.
*/
static void uassertValidFieldName(StringData fieldName);
@@ -60,7 +60,8 @@ public:
}
/**
- * Throws a UserException if the string is empty or if any of the field names fail validation.
+ * Throws a AssertionException if the string is empty or if any of the field names fail
+ * validation.
*
* Field names are validated using uassertValidFieldName().
*/
diff --git a/src/mongo/db/pipeline/field_path_test.cpp b/src/mongo/db/pipeline/field_path_test.cpp
index 49d22eab885..5b586c84172 100644
--- a/src/mongo/db/pipeline/field_path_test.cpp
+++ b/src/mongo/db/pipeline/field_path_test.cpp
@@ -41,7 +41,7 @@ using std::vector;
/** FieldPath constructed from empty string. */
TEST(FieldPathTest, Empty) {
- ASSERT_THROWS(FieldPath path(""), UserException);
+ ASSERT_THROWS(FieldPath path(""), AssertionException);
}
/** FieldPath constructed from a simple string (without dots). */
@@ -55,12 +55,12 @@ TEST(FieldPathTest, Simple) {
/** FieldPath consisting of a '$' character. */
TEST(FieldPathTest, DollarSign) {
- ASSERT_THROWS(FieldPath path("$"), UserException);
+ ASSERT_THROWS(FieldPath path("$"), AssertionException);
}
/** FieldPath with a '$' prefix. */
TEST(FieldPathTest, DollarSignPrefix) {
- ASSERT_THROWS(FieldPath path("$a"), UserException);
+ ASSERT_THROWS(FieldPath path("$a"), AssertionException);
}
/** FieldPath constructed from a string with one dot. */
@@ -75,7 +75,7 @@ TEST(FieldPathTest, Dotted) {
/** FieldPath with a '$' prefix in the second field. */
TEST(FieldPathTest, DollarSignPrefixSecondField) {
- ASSERT_THROWS(FieldPath path("a.$b"), UserException);
+ ASSERT_THROWS(FieldPath path("a.$b"), AssertionException);
}
/** FieldPath constructed from a string with two dots. */
@@ -90,22 +90,22 @@ TEST(FieldPathTest, TwoDotted) {
/** FieldPath constructed from a string ending in a dot. */
TEST(FieldPathTest, TerminalDot) {
- ASSERT_THROWS(FieldPath path("foo."), UserException);
+ ASSERT_THROWS(FieldPath path("foo."), AssertionException);
}
/** FieldPath constructed from a string beginning with a dot. */
TEST(FieldPathTest, PrefixDot) {
- ASSERT_THROWS(FieldPath path(".foo"), UserException);
+ ASSERT_THROWS(FieldPath path(".foo"), AssertionException);
}
/** FieldPath constructed from a string with adjacent dots. */
TEST(FieldPathTest, AdjacentDots) {
- ASSERT_THROWS(FieldPath path("foo..bar"), UserException);
+ ASSERT_THROWS(FieldPath path("foo..bar"), AssertionException);
}
/** FieldPath constructed with only dots. */
TEST(FieldPathTest, OnlyDots) {
- ASSERT_THROWS(FieldPath path("..."), UserException);
+ ASSERT_THROWS(FieldPath path("..."), AssertionException);
}
/** FieldPath constructed from a string with one letter between two dots. */
@@ -117,7 +117,7 @@ TEST(FieldPathTest, LetterBetweenDots) {
/** FieldPath containing a null character. */
TEST(FieldPathTest, NullCharacter) {
- ASSERT_THROWS(FieldPath path(string("foo.b\0r", 7)), UserException);
+ ASSERT_THROWS(FieldPath path(string("foo.b\0r", 7)), AssertionException);
}
/** Tail of a FieldPath. */
@@ -157,7 +157,7 @@ TEST(FieldPathTest, CanConstructFieldPathAtOrUnderDepthLimit) {
// Tests that a FieldPath can't be constructed if the path is too deeply nested.
TEST(FieldPathTest, ConstructorAssertsOnDeeplyNestedPath) {
ASSERT_THROWS_CODE(FieldPath(makeFieldPathOfDepth(BSONDepth::getMaxAllowableDepth() + 1)),
- UserException,
+ AssertionException,
ErrorCodes::Overflow);
}
@@ -184,7 +184,7 @@ TEST(FieldPathTest, CanConstructArrayFieldPathAtOrUnderDepthLimit) {
// Tests that a FieldPath can't be constructed if an array path is too deeply nested.
TEST(FieldPathTest, ConstructorAssertsOnDeeplyNestedArrayPath) {
ASSERT_THROWS_CODE(makeArrayFieldPathOfDepth(BSONDepth::getMaxAllowableDepth() + 1),
- UserException,
+ AssertionException,
ErrorCodes::Overflow);
}
} // namespace
diff --git a/src/mongo/db/pipeline/granularity_rounder_powers_of_two_test.cpp b/src/mongo/db/pipeline/granularity_rounder_powers_of_two_test.cpp
index eefcdb749e5..4825682d6d7 100644
--- a/src/mongo/db/pipeline/granularity_rounder_powers_of_two_test.cpp
+++ b/src/mongo/db/pipeline/granularity_rounder_powers_of_two_test.cpp
@@ -225,8 +225,8 @@ TEST(GranularityRounderPowersOfTwoTest, ShouldFailOnRoundingNonNumericValues) {
// Make sure that each GranularityRounder fails when rounding a non-numeric value.
Value stringValue = Value("test"_sd);
- ASSERT_THROWS_CODE(rounder->roundUp(stringValue), UserException, 40265);
- ASSERT_THROWS_CODE(rounder->roundDown(stringValue), UserException, 40265);
+ ASSERT_THROWS_CODE(rounder->roundUp(stringValue), AssertionException, 40265);
+ ASSERT_THROWS_CODE(rounder->roundDown(stringValue), AssertionException, 40265);
}
TEST(GranularityRounderPowersOfTwoTest, ShouldFailOnRoundingNaN) {
@@ -234,15 +234,15 @@ TEST(GranularityRounderPowersOfTwoTest, ShouldFailOnRoundingNaN) {
GranularityRounder::getGranularityRounder(new ExpressionContextForTest(), "POWERSOF2");
Value nan = Value(std::nan("NaN"));
- ASSERT_THROWS_CODE(rounder->roundUp(nan), UserException, 40266);
- ASSERT_THROWS_CODE(rounder->roundDown(nan), UserException, 40266);
+ ASSERT_THROWS_CODE(rounder->roundUp(nan), AssertionException, 40266);
+ ASSERT_THROWS_CODE(rounder->roundDown(nan), AssertionException, 40266);
Value positiveNan = Value(Decimal128::kPositiveNaN);
Value negativeNan = Value(Decimal128::kNegativeNaN);
- ASSERT_THROWS_CODE(rounder->roundUp(positiveNan), UserException, 40266);
- ASSERT_THROWS_CODE(rounder->roundDown(positiveNan), UserException, 40266);
- ASSERT_THROWS_CODE(rounder->roundUp(negativeNan), UserException, 40266);
- ASSERT_THROWS_CODE(rounder->roundDown(negativeNan), UserException, 40266);
+ ASSERT_THROWS_CODE(rounder->roundUp(positiveNan), AssertionException, 40266);
+ ASSERT_THROWS_CODE(rounder->roundDown(positiveNan), AssertionException, 40266);
+ ASSERT_THROWS_CODE(rounder->roundUp(negativeNan), AssertionException, 40266);
+ ASSERT_THROWS_CODE(rounder->roundDown(negativeNan), AssertionException, 40266);
}
TEST(GranularityRounderPowersOfTwoTest, ShouldFailOnRoundingNegativeNumber) {
@@ -250,8 +250,8 @@ TEST(GranularityRounderPowersOfTwoTest, ShouldFailOnRoundingNegativeNumber) {
GranularityRounder::getGranularityRounder(new ExpressionContextForTest(), "POWERSOF2");
Value negativeNumber = Value(-1);
- ASSERT_THROWS_CODE(rounder->roundUp(negativeNumber), UserException, 40267);
- ASSERT_THROWS_CODE(rounder->roundDown(negativeNumber), UserException, 40267);
+ ASSERT_THROWS_CODE(rounder->roundUp(negativeNumber), AssertionException, 40267);
+ ASSERT_THROWS_CODE(rounder->roundDown(negativeNumber), AssertionException, 40267);
}
} // namespace
} // namespace mongo
diff --git a/src/mongo/db/pipeline/granularity_rounder_preferred_numbers_test.cpp b/src/mongo/db/pipeline/granularity_rounder_preferred_numbers_test.cpp
index 89df39621ad..f80281f8fe0 100644
--- a/src/mongo/db/pipeline/granularity_rounder_preferred_numbers_test.cpp
+++ b/src/mongo/db/pipeline/granularity_rounder_preferred_numbers_test.cpp
@@ -532,8 +532,8 @@ TEST(GranularityRounderPreferredNumbersTest, ShouldFailOnRoundingNonNumericValue
// Make sure that each GranularityRounder fails when rounding a non-numeric value.
Value stringValue = Value("test"_sd);
- ASSERT_THROWS_CODE(rounder->roundUp(stringValue), UserException, 40262);
- ASSERT_THROWS_CODE(rounder->roundDown(stringValue), UserException, 40262);
+ ASSERT_THROWS_CODE(rounder->roundUp(stringValue), AssertionException, 40262);
+ ASSERT_THROWS_CODE(rounder->roundDown(stringValue), AssertionException, 40262);
}
}
@@ -544,15 +544,15 @@ TEST(GranularityRounderPreferredNumbersTest, ShouldFailOnRoundingNaN) {
// Make sure that each GranularityRounder fails when rounding NaN.
Value nan = Value(std::nan("NaN"));
- ASSERT_THROWS_CODE(rounder->roundUp(nan), UserException, 40263);
- ASSERT_THROWS_CODE(rounder->roundDown(nan), UserException, 40263);
+ ASSERT_THROWS_CODE(rounder->roundUp(nan), AssertionException, 40263);
+ ASSERT_THROWS_CODE(rounder->roundDown(nan), AssertionException, 40263);
Value positiveNan = Value(Decimal128::kPositiveNaN);
Value negativeNan = Value(Decimal128::kNegativeNaN);
- ASSERT_THROWS_CODE(rounder->roundUp(positiveNan), UserException, 40263);
- ASSERT_THROWS_CODE(rounder->roundDown(positiveNan), UserException, 40263);
- ASSERT_THROWS_CODE(rounder->roundUp(negativeNan), UserException, 40263);
- ASSERT_THROWS_CODE(rounder->roundDown(negativeNan), UserException, 40263);
+ ASSERT_THROWS_CODE(rounder->roundUp(positiveNan), AssertionException, 40263);
+ ASSERT_THROWS_CODE(rounder->roundDown(positiveNan), AssertionException, 40263);
+ ASSERT_THROWS_CODE(rounder->roundUp(negativeNan), AssertionException, 40263);
+ ASSERT_THROWS_CODE(rounder->roundDown(negativeNan), AssertionException, 40263);
}
}
@@ -563,12 +563,12 @@ TEST(GranularityRounderPreferredNumbersTest, ShouldFailOnRoundingNegativeNumber)
// Make sure that each GranularityRounder fails when rounding a negative number.
Value negativeNumber = Value(-1);
- ASSERT_THROWS_CODE(rounder->roundUp(negativeNumber), UserException, 40268);
- ASSERT_THROWS_CODE(rounder->roundDown(negativeNumber), UserException, 40268);
+ ASSERT_THROWS_CODE(rounder->roundUp(negativeNumber), AssertionException, 40268);
+ ASSERT_THROWS_CODE(rounder->roundDown(negativeNumber), AssertionException, 40268);
negativeNumber = Value(Decimal128(-1));
- ASSERT_THROWS_CODE(rounder->roundUp(negativeNumber), UserException, 40268);
- ASSERT_THROWS_CODE(rounder->roundDown(negativeNumber), UserException, 40268);
+ ASSERT_THROWS_CODE(rounder->roundUp(negativeNumber), AssertionException, 40268);
+ ASSERT_THROWS_CODE(rounder->roundDown(negativeNumber), AssertionException, 40268);
}
}
} // namespace
diff --git a/src/mongo/db/pipeline/lite_parsed_document_source.h b/src/mongo/db/pipeline/lite_parsed_document_source.h
index 3ce5fdc6324..60e2e8bd8ee 100644
--- a/src/mongo/db/pipeline/lite_parsed_document_source.h
+++ b/src/mongo/db/pipeline/lite_parsed_document_source.h
@@ -72,7 +72,8 @@ public:
static void registerParser(const std::string& name, Parser parser);
/**
- * Constructs a LiteParsedDocumentSource from the user-supplied BSON, or throws a UserException.
+ * Constructs a LiteParsedDocumentSource from the user-supplied BSON, or throws a
+ * AssertionException.
*
* Extracts the first field name from 'spec', and delegates to the parser that was registered
* with that field name using registerParser() above.
diff --git a/src/mongo/db/pipeline/lite_parsed_pipeline.h b/src/mongo/db/pipeline/lite_parsed_pipeline.h
index f7aaab26b92..a83a1e3c8a0 100644
--- a/src/mongo/db/pipeline/lite_parsed_pipeline.h
+++ b/src/mongo/db/pipeline/lite_parsed_pipeline.h
@@ -47,7 +47,7 @@ public:
/**
* Constructs a LiteParsedPipeline from the raw BSON stages given in 'request'.
*
- * May throw a UserException if there is an invalid stage specification, although full
+ * May throw a AssertionException if there is an invalid stage specification, although full
* validation happens later, during Pipeline construction.
*/
LiteParsedPipeline(const AggregationRequest& request) {
diff --git a/src/mongo/db/pipeline/parsed_add_fields_test.cpp b/src/mongo/db/pipeline/parsed_add_fields_test.cpp
index 289e8eb1f33..1191ea21cb5 100644
--- a/src/mongo/db/pipeline/parsed_add_fields_test.cpp
+++ b/src/mongo/db/pipeline/parsed_add_fields_test.cpp
@@ -55,35 +55,40 @@ using std::vector;
TEST(ParsedAddFieldsSpec, ThrowsOnCreationWithConflictingFieldPaths) {
boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
// These specs contain the same exact path.
- ASSERT_THROWS(ParsedAddFields::create(expCtx, BSON("a" << 1 << "a" << 2)), UserException);
+ ASSERT_THROWS(ParsedAddFields::create(expCtx, BSON("a" << 1 << "a" << 2)), AssertionException);
ASSERT_THROWS(ParsedAddFields::create(expCtx, BSON("a" << BSON("b" << 1 << "b" << 2))),
- UserException);
+ AssertionException);
ASSERT_THROWS(ParsedAddFields::create(expCtx, BSON("_id" << 3 << "_id" << true)),
- UserException);
+ AssertionException);
// These specs contain overlapping paths.
- ASSERT_THROWS(ParsedAddFields::create(expCtx, BSON("a" << 1 << "a.b" << 2)), UserException);
- ASSERT_THROWS(ParsedAddFields::create(expCtx, BSON("a.b.c" << 1 << "a" << 2)), UserException);
+ ASSERT_THROWS(ParsedAddFields::create(expCtx, BSON("a" << 1 << "a.b" << 2)),
+ AssertionException);
+ ASSERT_THROWS(ParsedAddFields::create(expCtx, BSON("a.b.c" << 1 << "a" << 2)),
+ AssertionException);
ASSERT_THROWS(ParsedAddFields::create(expCtx, BSON("_id" << true << "_id.x" << true)),
- UserException);
+ AssertionException);
}
// Verify that ParsedAddFields rejects specifications that contain invalid field paths.
TEST(ParsedAddFieldsSpec, ThrowsOnCreationWithInvalidFieldPath) {
boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
// Dotted subfields are not allowed.
- ASSERT_THROWS(ParsedAddFields::create(expCtx, BSON("a" << BSON("b.c" << true))), UserException);
+ ASSERT_THROWS(ParsedAddFields::create(expCtx, BSON("a" << BSON("b.c" << true))),
+ AssertionException);
// The user cannot start a field with $.
- ASSERT_THROWS(ParsedAddFields::create(expCtx, BSON("$dollar" << 0)), UserException);
- ASSERT_THROWS(ParsedAddFields::create(expCtx, BSON("c.$d" << true)), UserException);
+ ASSERT_THROWS(ParsedAddFields::create(expCtx, BSON("$dollar" << 0)), AssertionException);
+ ASSERT_THROWS(ParsedAddFields::create(expCtx, BSON("c.$d" << true)), AssertionException);
// Empty field names should throw an error.
- ASSERT_THROWS(ParsedAddFields::create(expCtx, BSON("" << 2)), UserException);
- ASSERT_THROWS(ParsedAddFields::create(expCtx, BSON("a" << BSON("" << true))), UserException);
- ASSERT_THROWS(ParsedAddFields::create(expCtx, BSON("" << BSON("a" << true))), UserException);
- ASSERT_THROWS(ParsedAddFields::create(expCtx, BSON("a." << true)), UserException);
- ASSERT_THROWS(ParsedAddFields::create(expCtx, BSON(".a" << true)), UserException);
+ ASSERT_THROWS(ParsedAddFields::create(expCtx, BSON("" << 2)), AssertionException);
+ ASSERT_THROWS(ParsedAddFields::create(expCtx, BSON("a" << BSON("" << true))),
+ AssertionException);
+ ASSERT_THROWS(ParsedAddFields::create(expCtx, BSON("" << BSON("a" << true))),
+ AssertionException);
+ ASSERT_THROWS(ParsedAddFields::create(expCtx, BSON("a." << true)), AssertionException);
+ ASSERT_THROWS(ParsedAddFields::create(expCtx, BSON(".a" << true)), AssertionException);
}
// Verify that ParsedAddFields rejects specifications that contain empty objects or invalid
@@ -93,20 +98,20 @@ TEST(ParsedAddFieldsSpec, ThrowsOnCreationWithInvalidObjectsOrExpressions) {
// Invalid expressions should be rejected.
ASSERT_THROWS(ParsedAddFields::create(
expCtx, BSON("a" << BSON("$add" << BSON_ARRAY(4 << 2) << "b" << 1))),
- UserException);
+ AssertionException);
ASSERT_THROWS(ParsedAddFields::create(expCtx,
BSON("a" << BSON("$gt" << BSON("bad"
<< "arguments")))),
- UserException);
+ AssertionException);
ASSERT_THROWS(ParsedAddFields::create(
expCtx, BSON("a" << false << "b" << BSON("$unknown" << BSON_ARRAY(4 << 2)))),
- UserException);
+ AssertionException);
// Empty specifications are not allowed.
- ASSERT_THROWS(ParsedAddFields::create(expCtx, BSONObj()), UserException);
+ ASSERT_THROWS(ParsedAddFields::create(expCtx, BSONObj()), AssertionException);
// Empty nested objects are not allowed.
- ASSERT_THROWS(ParsedAddFields::create(expCtx, BSON("a" << BSONObj())), UserException);
+ ASSERT_THROWS(ParsedAddFields::create(expCtx, BSON("a" << BSONObj())), AssertionException);
}
TEST(ParsedAddFields, DoesNotErrorOnTwoNestedFields) {
diff --git a/src/mongo/db/pipeline/parsed_aggregation_projection.cpp b/src/mongo/db/pipeline/parsed_aggregation_projection.cpp
index 1588e796970..403d290d054 100644
--- a/src/mongo/db/pipeline/parsed_aggregation_projection.cpp
+++ b/src/mongo/db/pipeline/parsed_aggregation_projection.cpp
@@ -188,7 +188,7 @@ private:
* Delegates to parseSubObject() if 'elem' is an object. Otherwise updates '_parsedType' if
* appropriate.
*
- * Throws a UserException if this element represents a mix of projection types.
+ * Throws a AssertionException if this element represents a mix of projection types.
*/
void parseElement(const BSONElement& elem, const FieldPath& pathToElem) {
if (elem.type() == BSONType::Object) {
@@ -230,7 +230,7 @@ private:
/**
* Traverses 'thisLevelSpec', parsing each element in turn.
*
- * Throws a UserException if 'thisLevelSpec' represents an invalid mix of projections.
+ * Throws a AssertionException if 'thisLevelSpec' represents an invalid mix of projections.
*/
void parseNestedObject(const BSONObj& thisLevelSpec, const FieldPath& prefix) {
diff --git a/src/mongo/db/pipeline/parsed_aggregation_projection.h b/src/mongo/db/pipeline/parsed_aggregation_projection.h
index 126254ce908..96611be19dc 100644
--- a/src/mongo/db/pipeline/parsed_aggregation_projection.h
+++ b/src/mongo/db/pipeline/parsed_aggregation_projection.h
@@ -112,7 +112,7 @@ public:
/**
* Main entry point for a ParsedAggregationProjection.
*
- * Throws a UserException if 'spec' is an invalid projection specification.
+ * Throws a AssertionException if 'spec' is an invalid projection specification.
*/
static std::unique_ptr<ParsedAggregationProjection> create(
const boost::intrusive_ptr<ExpressionContext>& expCtx, const BSONObj& spec);
diff --git a/src/mongo/db/pipeline/parsed_aggregation_projection_test.cpp b/src/mongo/db/pipeline/parsed_aggregation_projection_test.cpp
index 2ee53275e6a..35544d8d1f6 100644
--- a/src/mongo/db/pipeline/parsed_aggregation_projection_test.cpp
+++ b/src/mongo/db/pipeline/parsed_aggregation_projection_test.cpp
@@ -57,73 +57,73 @@ TEST(ParsedAggregationProjectionErrors, ShouldRejectDuplicateFieldNames) {
const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
// Include/exclude the same field twice.
ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON("a" << true << "a" << true)),
- UserException);
+ AssertionException);
ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON("a" << false << "a" << false)),
- UserException);
+ AssertionException);
ASSERT_THROWS(ParsedAggregationProjection::create(
expCtx, BSON("a" << BSON("b" << false << "b" << false))),
- UserException);
+ AssertionException);
// Mix of include/exclude and adding a field.
ASSERT_THROWS(
ParsedAggregationProjection::create(expCtx, BSON("a" << wrapInLiteral(1) << "a" << true)),
- UserException);
+ AssertionException);
ASSERT_THROWS(
ParsedAggregationProjection::create(expCtx, BSON("a" << false << "a" << wrapInLiteral(0))),
- UserException);
+ AssertionException);
// Adding the same field twice.
ASSERT_THROWS(ParsedAggregationProjection::create(
expCtx, BSON("a" << wrapInLiteral(1) << "a" << wrapInLiteral(0))),
- UserException);
+ AssertionException);
}
TEST(ParsedAggregationProjectionErrors, ShouldRejectDuplicateIds) {
const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
// Include/exclude _id twice.
ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON("_id" << true << "_id" << true)),
- UserException);
+ AssertionException);
ASSERT_THROWS(
ParsedAggregationProjection::create(expCtx, BSON("_id" << false << "_id" << false)),
- UserException);
+ AssertionException);
// Mix of including/excluding and adding _id.
ASSERT_THROWS(ParsedAggregationProjection::create(
expCtx, BSON("_id" << wrapInLiteral(1) << "_id" << true)),
- UserException);
+ AssertionException);
ASSERT_THROWS(ParsedAggregationProjection::create(
expCtx, BSON("_id" << false << "_id" << wrapInLiteral(0))),
- UserException);
+ AssertionException);
// Adding _id twice.
ASSERT_THROWS(ParsedAggregationProjection::create(
expCtx, BSON("_id" << wrapInLiteral(1) << "_id" << wrapInLiteral(0))),
- UserException);
+ AssertionException);
}
TEST(ParsedAggregationProjectionErrors, ShouldRejectFieldsWithSharedPrefix) {
const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
// Include/exclude Fields with a shared prefix.
ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON("a" << true << "a.b" << true)),
- UserException);
+ AssertionException);
ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON("a.b" << false << "a" << false)),
- UserException);
+ AssertionException);
// Mix of include/exclude and adding a shared prefix.
ASSERT_THROWS(
ParsedAggregationProjection::create(expCtx, BSON("a" << wrapInLiteral(1) << "a.b" << true)),
- UserException);
+ AssertionException);
ASSERT_THROWS(ParsedAggregationProjection::create(
expCtx, BSON("a.b" << false << "a" << wrapInLiteral(0))),
- UserException);
+ AssertionException);
// Adding a shared prefix twice.
ASSERT_THROWS(ParsedAggregationProjection::create(
expCtx, BSON("a" << wrapInLiteral(1) << "a.b" << wrapInLiteral(0))),
- UserException);
+ AssertionException);
ASSERT_THROWS(ParsedAggregationProjection::create(
expCtx, BSON("a.b.c.d" << wrapInLiteral(1) << "a.b.c" << wrapInLiteral(0))),
- UserException);
+ AssertionException);
}
TEST(ParsedAggregationProjectionErrors, ShouldRejectMixOfIdAndSubFieldsOfId) {
@@ -131,213 +131,224 @@ TEST(ParsedAggregationProjectionErrors, ShouldRejectMixOfIdAndSubFieldsOfId) {
// Include/exclude _id twice.
ASSERT_THROWS(
ParsedAggregationProjection::create(expCtx, BSON("_id" << true << "_id.x" << true)),
- UserException);
+ AssertionException);
ASSERT_THROWS(
ParsedAggregationProjection::create(expCtx, BSON("_id.x" << false << "_id" << false)),
- UserException);
+ AssertionException);
// Mix of including/excluding and adding _id.
ASSERT_THROWS(ParsedAggregationProjection::create(
expCtx, BSON("_id" << wrapInLiteral(1) << "_id.x" << true)),
- UserException);
+ AssertionException);
ASSERT_THROWS(ParsedAggregationProjection::create(
expCtx, BSON("_id.x" << false << "_id" << wrapInLiteral(0))),
- UserException);
+ AssertionException);
// Adding _id twice.
ASSERT_THROWS(ParsedAggregationProjection::create(
expCtx, BSON("_id" << wrapInLiteral(1) << "_id.x" << wrapInLiteral(0))),
- UserException);
+ AssertionException);
ASSERT_THROWS(
ParsedAggregationProjection::create(
expCtx, BSON("_id.b.c.d" << wrapInLiteral(1) << "_id.b.c" << wrapInLiteral(0))),
- UserException);
+ AssertionException);
}
TEST(ParsedAggregationProjectionErrors, ShouldRejectMixOfInclusionAndExclusion) {
const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
// Simple mix.
ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON("a" << true << "b" << false)),
- UserException);
+ AssertionException);
ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON("a" << false << "b" << true)),
- UserException);
+ AssertionException);
ASSERT_THROWS(
ParsedAggregationProjection::create(expCtx, BSON("a" << BSON("b" << false << "c" << true))),
- UserException);
+ AssertionException);
ASSERT_THROWS(ParsedAggregationProjection::create(
expCtx, BSON("_id" << BSON("b" << false << "c" << true))),
- UserException);
+ AssertionException);
ASSERT_THROWS(
ParsedAggregationProjection::create(expCtx, BSON("_id.b" << false << "a.c" << true)),
- UserException);
+ AssertionException);
// Mix while also adding a field.
ASSERT_THROWS(ParsedAggregationProjection::create(
expCtx, BSON("a" << true << "b" << wrapInLiteral(1) << "c" << false)),
- UserException);
+ AssertionException);
ASSERT_THROWS(ParsedAggregationProjection::create(
expCtx, BSON("a" << false << "b" << wrapInLiteral(1) << "c" << true)),
- UserException);
+ AssertionException);
// Mixing "_id" inclusion with exclusion.
ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON("_id" << true << "a" << false)),
- UserException);
+ AssertionException);
ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON("a" << false << "_id" << true)),
- UserException);
+ AssertionException);
ASSERT_THROWS(
ParsedAggregationProjection::create(expCtx, BSON("_id" << true << "a.b.c" << false)),
- UserException);
+ AssertionException);
ASSERT_THROWS(
ParsedAggregationProjection::create(expCtx, BSON("_id.x" << true << "a.b.c" << false)),
- UserException);
+ AssertionException);
}
TEST(ParsedAggregationProjectionType, ShouldRejectMixOfExclusionAndComputedFields) {
const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
ASSERT_THROWS(
ParsedAggregationProjection::create(expCtx, BSON("a" << false << "b" << wrapInLiteral(1))),
- UserException);
+ AssertionException);
ASSERT_THROWS(
ParsedAggregationProjection::create(expCtx, BSON("a" << wrapInLiteral(1) << "b" << false)),
- UserException);
+ AssertionException);
ASSERT_THROWS(ParsedAggregationProjection::create(
expCtx, BSON("a.b" << false << "a.c" << wrapInLiteral(1))),
- UserException);
+ AssertionException);
ASSERT_THROWS(ParsedAggregationProjection::create(
expCtx, BSON("a.b" << wrapInLiteral(1) << "a.c" << false)),
- UserException);
+ AssertionException);
ASSERT_THROWS(ParsedAggregationProjection::create(
expCtx, BSON("a" << BSON("b" << false << "c" << wrapInLiteral(1)))),
- UserException);
+ AssertionException);
ASSERT_THROWS(ParsedAggregationProjection::create(
expCtx, BSON("a" << BSON("b" << wrapInLiteral(1) << "c" << false))),
- UserException);
+ AssertionException);
}
TEST(ParsedAggregationProjectionErrors, ShouldRejectDottedFieldInSubDocument) {
const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON("a" << BSON("b.c" << true))),
- UserException);
+ AssertionException);
ASSERT_THROWS(
ParsedAggregationProjection::create(expCtx, BSON("a" << BSON("b.c" << wrapInLiteral(1)))),
- UserException);
+ AssertionException);
}
TEST(ParsedAggregationProjectionErrors, ShouldRejectFieldNamesStartingWithADollar) {
const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
- ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON("$dollar" << 0)), UserException);
- ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON("$dollar" << 1)), UserException);
+ ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON("$dollar" << 0)),
+ AssertionException);
+ ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON("$dollar" << 1)),
+ AssertionException);
ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON("b.$dollar" << 0)),
- UserException);
+ AssertionException);
ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON("b.$dollar" << 1)),
- UserException);
+ AssertionException);
ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON("b" << BSON("$dollar" << 0))),
- UserException);
+ AssertionException);
ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON("b" << BSON("$dollar" << 1))),
- UserException);
+ AssertionException);
- ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON("$add" << 0)), UserException);
- ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON("$add" << 1)), UserException);
+ ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON("$add" << 0)),
+ AssertionException);
+ ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON("$add" << 1)),
+ AssertionException);
}
TEST(ParsedAggregationProjectionErrors, ShouldRejectTopLevelExpressions) {
const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON("$add" << BSON_ARRAY(4 << 2))),
- UserException);
+ AssertionException);
}
TEST(ParsedAggregationProjectionErrors, ShouldRejectExpressionWithMultipleFieldNames) {
const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
ASSERT_THROWS(ParsedAggregationProjection::create(
expCtx, BSON("a" << BSON("$add" << BSON_ARRAY(4 << 2) << "b" << 1))),
- UserException);
+ AssertionException);
ASSERT_THROWS(ParsedAggregationProjection::create(
expCtx, BSON("a" << BSON("b" << 1 << "$add" << BSON_ARRAY(4 << 2)))),
- UserException);
+ AssertionException);
ASSERT_THROWS(
ParsedAggregationProjection::create(
expCtx, BSON("a" << BSON("b" << BSON("c" << 1 << "$add" << BSON_ARRAY(4 << 2))))),
- UserException);
+ AssertionException);
ASSERT_THROWS(
ParsedAggregationProjection::create(
expCtx, BSON("a" << BSON("b" << BSON("$add" << BSON_ARRAY(4 << 2) << "c" << 1)))),
- UserException);
+ AssertionException);
}
TEST(ParsedAggregationProjectionErrors, ShouldRejectEmptyProjection) {
const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
- ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSONObj()), UserException);
+ ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSONObj()), AssertionException);
}
TEST(ParsedAggregationProjectionErrors, ShouldRejectEmptyNestedObject) {
const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON("a" << BSONObj())),
- UserException);
+ AssertionException);
ASSERT_THROWS(
ParsedAggregationProjection::create(expCtx, BSON("a" << false << "b" << BSONObj())),
- UserException);
+ AssertionException);
ASSERT_THROWS(
ParsedAggregationProjection::create(expCtx, BSON("a" << true << "b" << BSONObj())),
- UserException);
+ AssertionException);
ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON("a.b" << BSONObj())),
- UserException);
+ AssertionException);
ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON("a" << BSON("b" << BSONObj()))),
- UserException);
+ AssertionException);
}
TEST(ParsedAggregationProjectionErrors, ShouldErrorOnInvalidExpression) {
const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
ASSERT_THROWS(ParsedAggregationProjection::create(
expCtx, BSON("a" << false << "b" << BSON("$unknown" << BSON_ARRAY(4 << 2)))),
- UserException);
+ AssertionException);
ASSERT_THROWS(ParsedAggregationProjection::create(
expCtx, BSON("a" << true << "b" << BSON("$unknown" << BSON_ARRAY(4 << 2)))),
- UserException);
+ AssertionException);
}
TEST(ParsedAggregationProjectionErrors, ShouldErrorOnInvalidFieldPath) {
const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
// Empty field names.
ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON("" << wrapInLiteral(2))),
- UserException);
- ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON("" << true)), UserException);
- ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON("" << false)), UserException);
+ AssertionException);
+ ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON("" << true)),
+ AssertionException);
+ ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON("" << false)),
+ AssertionException);
ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON("a" << BSON("" << true))),
- UserException);
+ AssertionException);
ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON("a" << BSON("" << false))),
- UserException);
+ AssertionException);
ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON("" << BSON("a" << true))),
- UserException);
+ AssertionException);
ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON("" << BSON("a" << false))),
- UserException);
+ AssertionException);
- ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON("a." << true)), UserException);
- ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON("a." << false)), UserException);
+ ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON("a." << true)),
+ AssertionException);
+ ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON("a." << false)),
+ AssertionException);
- ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON(".a" << true)), UserException);
- ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON(".a" << false)), UserException);
+ ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON(".a" << true)),
+ AssertionException);
+ ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON(".a" << false)),
+ AssertionException);
// Not testing field names with null bytes, since that is invalid BSON, and won't make it to the
// $project stage without a previous error.
// Field names starting with '$'.
ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON("$x" << wrapInLiteral(2))),
- UserException);
- ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON("c.$d" << true)), UserException);
+ AssertionException);
+ ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON("c.$d" << true)),
+ AssertionException);
ASSERT_THROWS(ParsedAggregationProjection::create(expCtx, BSON("c.$d" << false)),
- UserException);
+ AssertionException);
}
TEST(ParsedAggregationProjectionErrors, ShouldNotErrorOnTwoNestedFields) {
diff --git a/src/mongo/db/pipeline/parsed_inclusion_projection_test.cpp b/src/mongo/db/pipeline/parsed_inclusion_projection_test.cpp
index ef77bb03943..799ac5f92b3 100644
--- a/src/mongo/db/pipeline/parsed_inclusion_projection_test.cpp
+++ b/src/mongo/db/pipeline/parsed_inclusion_projection_test.cpp
@@ -57,13 +57,13 @@ TEST(InclusionProjection, ShouldThrowWhenParsingInvalidExpression) {
ParsedInclusionProjection inclusion(expCtx);
ASSERT_THROWS(inclusion.parse(BSON("a" << BSON("$gt" << BSON("bad"
<< "arguments")))),
- UserException);
+ AssertionException);
}
TEST(InclusionProjection, ShouldRejectProjectionWithNoOutputFields) {
const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
ParsedInclusionProjection inclusion(expCtx);
- ASSERT_THROWS(inclusion.parse(BSON("_id" << false)), UserException);
+ ASSERT_THROWS(inclusion.parse(BSON("_id" << false)), AssertionException);
}
TEST(InclusionProjection, ShouldAddIncludedFieldsToDependencies) {
diff --git a/src/mongo/db/pipeline/pipeline_test.cpp b/src/mongo/db/pipeline/pipeline_test.cpp
index ac54c766727..79e324d3901 100644
--- a/src/mongo/db/pipeline/pipeline_test.cpp
+++ b/src/mongo/db/pipeline/pipeline_test.cpp
@@ -1670,7 +1670,7 @@ TEST_F(PipelineDependenciesTest, ShouldThrowIfTextScoreIsNeededButNotPresent) {
auto pipeline = unittest::assertGet(Pipeline::create({needsText}, ctx));
ASSERT_THROWS(pipeline->getDependencies(DepsTracker::MetadataAvailable::kNoMetadata),
- UserException);
+ AssertionException);
}
TEST_F(PipelineDependenciesTest, ShouldRequireTextScoreIfAvailableAndNoStageReturnsExhaustiveMeta) {
diff --git a/src/mongo/db/pipeline/tee_buffer_test.cpp b/src/mongo/db/pipeline/tee_buffer_test.cpp
index 2e4495c3d5f..52f3922de57 100644
--- a/src/mongo/db/pipeline/tee_buffer_test.cpp
+++ b/src/mongo/db/pipeline/tee_buffer_test.cpp
@@ -40,12 +40,12 @@ namespace mongo {
namespace {
TEST(TeeBufferTest, ShouldRequireAtLeastOneConsumer) {
- ASSERT_THROWS_CODE(TeeBuffer::create(0), UserException, 40309);
+ ASSERT_THROWS_CODE(TeeBuffer::create(0), AssertionException, 40309);
}
TEST(TeeBufferTest, ShouldRequirePositiveBatchSize) {
- ASSERT_THROWS_CODE(TeeBuffer::create(1, 0), UserException, 40310);
- ASSERT_THROWS_CODE(TeeBuffer::create(1, -2), UserException, 40310);
+ ASSERT_THROWS_CODE(TeeBuffer::create(1, 0), AssertionException, 40310);
+ ASSERT_THROWS_CODE(TeeBuffer::create(1, -2), AssertionException, 40310);
}
TEST(TeeBufferTest, ShouldBeExhaustedIfInputIsExhausted) {
diff --git a/src/mongo/db/pipeline/value.h b/src/mongo/db/pipeline/value.h
index 40c05d89b9a..d2d337fa3ea 100644
--- a/src/mongo/db/pipeline/value.h
+++ b/src/mongo/db/pipeline/value.h
@@ -200,8 +200,8 @@ public:
/**
* Recursively serializes this value as a field in the object in 'builder' with the field name
- * 'fieldName'. This function throws a UserException if the recursion exceeds the server's BSON
- * depth limit.
+ * 'fieldName'. This function throws a AssertionException if the recursion exceeds the server's
+ * BSON depth limit.
*/
void addToBsonObj(BSONObjBuilder* builder,
StringData fieldName,
@@ -209,7 +209,7 @@ public:
/**
* Recursively serializes this value as an element in the array in 'builder'. This function
- * throws a UserException if the recursion exceeds the server's BSON depth limit.
+ * throws a AssertionException if the recursion exceeds the server's BSON depth limit.
*/
void addToBsonArray(BSONArrayBuilder* builder, size_t recursionLevel = 1) const;