diff options
author | Mathias Stearn <mathias@10gen.com> | 2017-08-10 15:52:33 -0400 |
---|---|---|
committer | Mathias Stearn <mathias@10gen.com> | 2017-08-16 16:28:02 -0400 |
commit | 347935f7a5d0452146b1a73ad7ef9e249eaf1fb5 (patch) | |
tree | 00b322f5adcf3eb9c2624747a6b5b2179e440052 /src/mongo/db/update | |
parent | cdf7aacb213c99d3ce620761ff46b030bbd7732d (diff) | |
download | mongo-347935f7a5d0452146b1a73ad7ef9e249eaf1fb5.tar.gz |
SERVER-30580 Eliminate UserException and MsgAssertionException types
All users were converted to just use AssertionException.
Diffstat (limited to 'src/mongo/db/update')
-rw-r--r-- | src/mongo/db/update/addtoset_node_test.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/update/arithmetic_node_test.cpp | 12 | ||||
-rw-r--r-- | src/mongo/db/update/object_replace_node_test.cpp | 12 | ||||
-rw-r--r-- | src/mongo/db/update/pop_node_test.cpp | 10 | ||||
-rw-r--r-- | src/mongo/db/update/pull_node.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/update/pull_node_test.cpp | 8 | ||||
-rw-r--r-- | src/mongo/db/update/pullall_node_test.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/update/push_node_test.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/update/rename_node_test.cpp | 24 | ||||
-rw-r--r-- | src/mongo/db/update/set_node_test.cpp | 30 | ||||
-rw-r--r-- | src/mongo/db/update/unset_node_test.cpp | 8 | ||||
-rw-r--r-- | src/mongo/db/update/update_array_node_test.cpp | 12 | ||||
-rw-r--r-- | src/mongo/db/update/update_driver_test.cpp | 8 | ||||
-rw-r--r-- | src/mongo/db/update/update_leaf_node.h | 2 | ||||
-rw-r--r-- | src/mongo/db/update/update_node.h | 4 | ||||
-rw-r--r-- | src/mongo/db/update/update_object_node_test.cpp | 28 |
16 files changed, 83 insertions, 83 deletions
diff --git a/src/mongo/db/update/addtoset_node_test.cpp b/src/mongo/db/update/addtoset_node_test.cpp index c8440764c38..26e6e1ea4fc 100644 --- a/src/mongo/db/update/addtoset_node_test.cpp +++ b/src/mongo/db/update/addtoset_node_test.cpp @@ -112,7 +112,7 @@ TEST_F(AddToSetNodeTest, ApplyFailsOnNonArray) { setPathTaken("a"); ASSERT_THROWS_CODE_AND_WHAT( node.apply(getApplyParams(doc.root()["a"])), - UserException, + AssertionException, ErrorCodes::BadValue, "Cannot apply $addToSet to non-array field. Field named 'a' has non-array type int"); } diff --git a/src/mongo/db/update/arithmetic_node_test.cpp b/src/mongo/db/update/arithmetic_node_test.cpp index 3a4d74121ea..a0a74654ac0 100644 --- a/src/mongo/db/update/arithmetic_node_test.cpp +++ b/src/mongo/db/update/arithmetic_node_test.cpp @@ -258,7 +258,7 @@ TEST_F(ArithmeticNodeTest, ApplyNonViablePathToInc) { setPathTaken("a"); addIndexedPath("a"); ASSERT_THROWS_CODE_AND_WHAT(node.apply(getApplyParams(doc.root()["a"])), - UserException, + AssertionException, ErrorCodes::PathNotViable, "Cannot create field 'b' in element {a: 5}"); } @@ -552,7 +552,7 @@ TEST_F(ArithmeticNodeTest, ApplyIncToObjectFails) { setPathTaken("a"); addIndexedPath("a"); ASSERT_THROWS_CODE_AND_WHAT(node.apply(getApplyParams(doc.root()["a"])), - UserException, + AssertionException, ErrorCodes::TypeMismatch, "Cannot apply $inc to a value of non-numeric type. {_id: " "\"test_object\"} has the field 'a' of non-numeric type object"); @@ -568,7 +568,7 @@ TEST_F(ArithmeticNodeTest, ApplyIncToArrayFails) { setPathTaken("a"); addIndexedPath("a"); ASSERT_THROWS_CODE_AND_WHAT(node.apply(getApplyParams(doc.root()["a"])), - UserException, + AssertionException, ErrorCodes::TypeMismatch, "Cannot apply $inc to a value of non-numeric type. {_id: " "\"test_object\"} has the field 'a' of non-numeric type array"); @@ -584,7 +584,7 @@ TEST_F(ArithmeticNodeTest, ApplyIncToStringFails) { setPathTaken("a"); addIndexedPath("a"); ASSERT_THROWS_CODE_AND_WHAT(node.apply(getApplyParams(doc.root()["a"])), - UserException, + AssertionException, ErrorCodes::TypeMismatch, "Cannot apply $inc to a value of non-numeric type. {_id: " "\"test_object\"} has the field 'a' of non-numeric type string"); @@ -663,7 +663,7 @@ TEST_F(ArithmeticNodeTest, ApplyPathNotViableArray) { setPathToCreate("b"); setPathTaken("a"); ASSERT_THROWS_CODE_AND_WHAT(node.apply(getApplyParams(doc.root()["a"])), - UserException, + AssertionException, ErrorCodes::PathNotViable, "Cannot create field 'b' in element {a: [ { b: 1 } ]}"); } @@ -775,7 +775,7 @@ TEST_F(ArithmeticNodeTest, ApplyNonViablePathThroughArray) { setPathToCreate("2.b"); setPathTaken("a"); ASSERT_THROWS_CODE_AND_WHAT(node.apply(getApplyParams(doc.root()["a"])), - UserException, + AssertionException, ErrorCodes::PathNotViable, "Cannot create field '2' in element {a: 0}"); } diff --git a/src/mongo/db/update/object_replace_node_test.cpp b/src/mongo/db/update/object_replace_node_test.cpp index 645a3e69ff3..27bb8aea7b3 100644 --- a/src/mongo/db/update/object_replace_node_test.cpp +++ b/src/mongo/db/update/object_replace_node_test.cpp @@ -158,7 +158,7 @@ TEST_F(ObjectReplaceNodeTest, CannotRemoveImmutablePath) { mutablebson::Document doc(fromjson("{_id: 0, a: {b: 1}}")); addImmutablePath("a.b"); ASSERT_THROWS_CODE_AND_WHAT(node.apply(getApplyParams(doc.root())), - UserException, + AssertionException, ErrorCodes::ImmutableField, "After applying the update, the 'a.b' (required and immutable) " "field was found to have been removed --{ _id: 0, a: { b: 1 } }"); @@ -185,7 +185,7 @@ TEST_F(ObjectReplaceNodeTest, CannotReplaceImmutablePathWithArrayField) { mutablebson::Document doc(fromjson("{_id: 0, a: {b: 1}}")); addImmutablePath("a.b"); ASSERT_THROWS_CODE_AND_WHAT(node.apply(getApplyParams(doc.root())), - UserException, + AssertionException, ErrorCodes::NotSingleValueField, "After applying the update to the document, the (immutable) field " "'a.b' was found to be an array or array descendant."); @@ -198,7 +198,7 @@ TEST_F(ObjectReplaceNodeTest, CannotMakeImmutablePathArrayDescendant) { mutablebson::Document doc(fromjson("{_id: 0, a: {'0': 1}}")); addImmutablePath("a.0"); ASSERT_THROWS_CODE_AND_WHAT(node.apply(getApplyParams(doc.root())), - UserException, + AssertionException, ErrorCodes::NotSingleValueField, "After applying the update to the document, the (immutable) field " "'a.0' was found to be an array or array descendant."); @@ -211,7 +211,7 @@ TEST_F(ObjectReplaceNodeTest, CannotModifyImmutablePath) { mutablebson::Document doc(fromjson("{_id: 0, a: {b: 1}}")); addImmutablePath("a.b"); ASSERT_THROWS_CODE_AND_WHAT(node.apply(getApplyParams(doc.root())), - UserException, + AssertionException, ErrorCodes::ImmutableField, "After applying the update, the (immutable) field 'a.b' was found " "to have been altered to b: 2"); @@ -224,7 +224,7 @@ TEST_F(ObjectReplaceNodeTest, CannotModifyImmutableId) { mutablebson::Document doc(fromjson("{_id: 0}")); addImmutablePath("_id"); ASSERT_THROWS_CODE_AND_WHAT(node.apply(getApplyParams(doc.root())), - UserException, + AssertionException, ErrorCodes::ImmutableField, "After applying the update, the (immutable) field '_id' was found " "to have been altered to _id: 1"); @@ -265,7 +265,7 @@ TEST_F(ObjectReplaceNodeTest, CannotCreateDollarPrefixedNameWhenValidateForStora mutablebson::Document doc(fromjson("{}")); ASSERT_THROWS_CODE_AND_WHAT( node.apply(getApplyParams(doc.root())), - UserException, + AssertionException, ErrorCodes::DollarPrefixedFieldName, "The dollar ($) prefixed field '$bad' in 'a.$bad' is not valid for storage."); } diff --git a/src/mongo/db/update/pop_node_test.cpp b/src/mongo/db/update/pop_node_test.cpp index 4cb14505988..40e0d38c36c 100644 --- a/src/mongo/db/update/pop_node_test.cpp +++ b/src/mongo/db/update/pop_node_test.cpp @@ -162,7 +162,7 @@ TEST_F(PopNodeTest, ThrowsWhenPathIsBlockedByAScalar) { addIndexedPath("a.b"); ASSERT_THROWS_CODE_AND_WHAT( popNode.apply(getApplyParams(doc.root()["a"])), - UserException, + AssertionException, ErrorCodes::PathNotViable, "Cannot use the part (b) of (a.b) to traverse the element ({a: \"foo\"})"); } @@ -191,7 +191,7 @@ TEST_F(PopNodeTest, ThrowsWhenPathExistsButDoesNotContainAnArray) { setPathTaken("a.b"); addIndexedPath("a.b"); ASSERT_THROWS_CODE_AND_WHAT(popNode.apply(getApplyParams(doc.root()["a"]["b"])), - UserException, + AssertionException, ErrorCodes::TypeMismatch, "Path 'a.b' contains an element of non-array type 'string'"); } @@ -342,7 +342,7 @@ TEST_F(PopNodeTest, ThrowsWhenPathIsImmutable) { addIndexedPath("a.b"); ASSERT_THROWS_CODE_AND_WHAT( popNode.apply(getApplyParams(doc.root()["a"]["b"])), - UserException, + AssertionException, ErrorCodes::ImmutableField, "Performing a $pop on the path 'a.b' would modify the immutable field 'a.b'"); } @@ -364,7 +364,7 @@ TEST_F(PopNodeTest, ThrowsWhenPathIsPrefixOfImmutable) { addIndexedPath("a"); ASSERT_THROWS_CODE_AND_WHAT( popNode.apply(getApplyParams(doc.root()["a"])), - UserException, + AssertionException, ErrorCodes::ImmutableField, "Performing a $pop on the path 'a' would modify the immutable field 'a.0'"); } @@ -381,7 +381,7 @@ TEST_F(PopNodeTest, ThrowsWhenPathIsSuffixOfImmutable) { addIndexedPath("a.b"); ASSERT_THROWS_CODE_AND_WHAT( popNode.apply(getApplyParams(doc.root()["a"]["b"])), - UserException, + AssertionException, ErrorCodes::ImmutableField, "Performing a $pop on the path 'a.b' would modify the immutable field 'a'"); } diff --git a/src/mongo/db/update/pull_node.cpp b/src/mongo/db/update/pull_node.cpp index e7a70620ad4..5842718c388 100644 --- a/src/mongo/db/update/pull_node.cpp +++ b/src/mongo/db/update/pull_node.cpp @@ -137,7 +137,7 @@ Status PullNode::init(BSONElement modExpr, const CollatorInterface* collator) { } else { _matcher = stdx::make_unique<EqualityMatcher>(modExpr, collator); } - } catch (UserException& exception) { + } catch (AssertionException& exception) { return exception.toStatus(); } diff --git a/src/mongo/db/update/pull_node_test.cpp b/src/mongo/db/update/pull_node_test.cpp index 9d3c101fba9..d54640c0d1a 100644 --- a/src/mongo/db/update/pull_node_test.cpp +++ b/src/mongo/db/update/pull_node_test.cpp @@ -90,7 +90,7 @@ TEST_F(PullNodeTest, ApplyToStringFails) { setPathTaken("a"); addIndexedPath("a"); ASSERT_THROWS_CODE_AND_WHAT(node.apply(getApplyParams(doc.root()["a"])), - UserException, + AssertionException, ErrorCodes::BadValue, "Cannot apply $pull to a non-array value"); } @@ -105,7 +105,7 @@ TEST_F(PullNodeTest, ApplyToObjectFails) { setPathTaken("a"); addIndexedPath("a"); ASSERT_THROWS_CODE_AND_WHAT(node.apply(getApplyParams(doc.root()["a"])), - UserException, + AssertionException, ErrorCodes::BadValue, "Cannot apply $pull to a non-array value"); } @@ -122,7 +122,7 @@ TEST_F(PullNodeTest, ApplyToNonViablePathFails) { addIndexedPath("a"); ASSERT_THROWS_CODE_AND_WHAT( node.apply(getApplyParams(doc.root()["a"])), - UserException, + AssertionException, ErrorCodes::PathNotViable, "Cannot use the part (b) of (a.b) to traverse the element ({a: 1})"); } @@ -580,7 +580,7 @@ TEST_F(PullNodeTest, CannotModifyImmutableField) { addImmutablePath("_id"); ASSERT_THROWS_CODE_AND_WHAT( node.apply(getApplyParams(doc.root()["_id"]["a"])), - UserException, + AssertionException, ErrorCodes::ImmutableField, "Performing an update on the path '_id.a' would modify the immutable field '_id'"); } diff --git a/src/mongo/db/update/pullall_node_test.cpp b/src/mongo/db/update/pullall_node_test.cpp index 4af970eb306..03ba5290d62 100644 --- a/src/mongo/db/update/pullall_node_test.cpp +++ b/src/mongo/db/update/pullall_node_test.cpp @@ -126,7 +126,7 @@ TEST_F(PullAllNodeTest, ApplyToNonArrayFails) { setPathTaken("a.0"); addIndexedPath("a"); ASSERT_THROWS_CODE_AND_WHAT(node.apply(getApplyParams(doc.root()["a"][0])), - UserException, + AssertionException, ErrorCodes::BadValue, "Cannot apply $pull to a non-array value"); } diff --git a/src/mongo/db/update/push_node_test.cpp b/src/mongo/db/update/push_node_test.cpp index ba9e988fb64..3525a4b8767 100644 --- a/src/mongo/db/update/push_node_test.cpp +++ b/src/mongo/db/update/push_node_test.cpp @@ -266,7 +266,7 @@ TEST_F(PushNodeTest, ApplyToNonArrayFails) { addIndexedPath("a"); ASSERT_THROWS_CODE_AND_WHAT( node.apply(getApplyParams(doc.root()["a"])), - UserException, + AssertionException, ErrorCodes::BadValue, "The field 'a' must be an array but is of type int in document {_id: \"test_object\"}"); } diff --git a/src/mongo/db/update/rename_node_test.cpp b/src/mongo/db/update/rename_node_test.cpp index a72485b7e23..2267f51de6e 100644 --- a/src/mongo/db/update/rename_node_test.cpp +++ b/src/mongo/db/update/rename_node_test.cpp @@ -248,7 +248,7 @@ TEST_F(RenameNodeTest, MoveIntoArray) { setPathTaken("a"); addIndexedPath("a"); ASSERT_THROWS_CODE_AND_WHAT(node.apply(getApplyParams(doc.root()["a"])), - UserException, + AssertionException, ErrorCodes::BadValue, "The destination field cannot be an array element, 'a.2' in doc " "with _id: \"test_object\" has an array field called 'a'"); @@ -265,7 +265,7 @@ TEST_F(RenameNodeTest, MoveIntoArrayNoId) { setPathTaken("a"); addIndexedPath("a"); ASSERT_THROWS_CODE_AND_WHAT(node.apply(getApplyParams(doc.root()["a"])), - UserException, + AssertionException, ErrorCodes::BadValue, "The destination field cannot be an array element, 'a.2' in doc " "with no id has an array field called 'a'"); @@ -281,7 +281,7 @@ TEST_F(RenameNodeTest, MoveToArrayElement) { setPathTaken("a.1"); addIndexedPath("a"); ASSERT_THROWS_CODE_AND_WHAT(node.apply(getApplyParams(doc.root()["a"]["1"])), - UserException, + AssertionException, ErrorCodes::BadValue, "The destination field cannot be an array element, 'a.1' in doc " "with _id: \"test_object\" has an array field called 'a'"); @@ -297,7 +297,7 @@ TEST_F(RenameNodeTest, MoveOutOfArray) { setPathToCreate("b"); addIndexedPath("a"); ASSERT_THROWS_CODE_AND_WHAT(node.apply(getApplyParams(doc.root())), - UserException, + AssertionException, ErrorCodes::BadValue, "The source field cannot be an array element, 'a.0' in doc with " "_id: \"test_object\" has an array field called 'a'"); @@ -314,7 +314,7 @@ TEST_F(RenameNodeTest, MoveNonexistentEmbeddedFieldOut) { addIndexedPath("a"); ASSERT_THROWS_CODE_AND_WHAT( node.apply(getApplyParams(doc.root())), - UserException, + AssertionException, ErrorCodes::PathNotViable, "cannot use the part (a of a.a) to traverse the element ({a: [ { a: 1 }, { b: 2 } ]})"); } @@ -329,7 +329,7 @@ TEST_F(RenameNodeTest, MoveEmbeddedFieldOutWithElementNumber) { setPathToCreate("b"); addIndexedPath("a"); ASSERT_THROWS_CODE_AND_WHAT(node.apply(getApplyParams(doc.root())), - UserException, + AssertionException, ErrorCodes::BadValue, "The source field cannot be an array element, 'a.0.a' in doc with " "_id: \"test_object\" has an array field called 'a'"); @@ -422,7 +422,7 @@ TEST_F(RenameNodeTest, ApplyCannotRemoveRequiredPartOfDBRef) { mutablebson::Document doc(fromjson("{a: {$ref: 'c', $id: 0}}")); setPathToCreate("b"); ASSERT_THROWS_CODE_AND_WHAT(node.apply(getApplyParams(doc.root())), - UserException, + AssertionException, ErrorCodes::InvalidDBRef, "The DBRef $ref field must be followed by a $id field"); } @@ -460,7 +460,7 @@ TEST_F(RenameNodeTest, ApplyCannotRemoveImmutablePath) { addImmutablePath("a.b"); ASSERT_THROWS_CODE_AND_WHAT( node.apply(getApplyParams(doc.root())), - UserException, + AssertionException, ErrorCodes::ImmutableField, "Unsetting the path 'a.b' using $rename would modify the immutable field 'a.b'"); } @@ -476,7 +476,7 @@ TEST_F(RenameNodeTest, ApplyCannotRemovePrefixOfImmutablePath) { addImmutablePath("a.b"); ASSERT_THROWS_CODE_AND_WHAT( node.apply(getApplyParams(doc.root())), - UserException, + AssertionException, ErrorCodes::ImmutableField, "Unsetting the path 'a' using $rename would modify the immutable field 'a.b'"); } @@ -492,7 +492,7 @@ TEST_F(RenameNodeTest, ApplyCannotRemoveSuffixOfImmutablePath) { addImmutablePath("a.b"); ASSERT_THROWS_CODE_AND_WHAT( node.apply(getApplyParams(doc.root())), - UserException, + AssertionException, ErrorCodes::ImmutableField, "Unsetting the path 'a.b.c' using $rename would modify the immutable field 'a.b'"); } @@ -525,7 +525,7 @@ TEST_F(RenameNodeTest, ApplyCannotCreateDollarPrefixedField) { setPathToCreate("$bad"); ASSERT_THROWS_CODE_AND_WHAT( node.apply(getApplyParams(doc.root())), - UserException, + AssertionException, ErrorCodes::DollarPrefixedFieldName, "The dollar ($) prefixed field '$bad' in '$bad' is not valid for storage."); } @@ -541,7 +541,7 @@ TEST_F(RenameNodeTest, ApplyCannotOverwriteImmutablePath) { addImmutablePath("b"); ASSERT_THROWS_CODE_AND_WHAT( node.apply(getApplyParams(doc.root()["b"])), - UserException, + AssertionException, ErrorCodes::ImmutableField, "Updating the path 'b' to b: 0 would modify the immutable field 'b'"); } diff --git a/src/mongo/db/update/set_node_test.cpp b/src/mongo/db/update/set_node_test.cpp index a7a6f793a10..792b7632c39 100644 --- a/src/mongo/db/update/set_node_test.cpp +++ b/src/mongo/db/update/set_node_test.cpp @@ -156,7 +156,7 @@ TEST_F(SetNodeTest, ApplyNonViablePathToCreate) { setPathTaken("a"); addIndexedPath("a"); ASSERT_THROWS_CODE_AND_WHAT(node.apply(getApplyParams(doc.root()["a"])), - UserException, + AssertionException, ErrorCodes::PathNotViable, "Cannot create field 'b' in element {a: 5}"); } @@ -385,7 +385,7 @@ TEST_F(SetNodeTest, ApplyPathNotViable) { setPathToCreate("b"); setPathTaken("a"); ASSERT_THROWS_CODE_AND_WHAT(node.apply(getApplyParams(doc.root()["a"])), - UserException, + AssertionException, ErrorCodes::PathNotViable, "Cannot create field 'b' in element {a: 1}"); } @@ -400,7 +400,7 @@ TEST_F(SetNodeTest, ApplyPathNotViableArrray) { setPathToCreate("b"); setPathTaken("a"); ASSERT_THROWS_CODE_AND_WHAT(node.apply(getApplyParams(doc.root()["a"])), - UserException, + AssertionException, ErrorCodes::PathNotViable, "Cannot create field 'b' in element {a: [ { b: 1 } ]}"); } @@ -560,7 +560,7 @@ TEST_F(SetNodeTest, ApplyNonViablePath) { setPathToCreate("2.b"); setPathTaken("a"); ASSERT_THROWS_CODE_AND_WHAT(node.apply(getApplyParams(doc.root()["a"])), - UserException, + AssertionException, ErrorCodes::PathNotViable, "Cannot create field '2' in element {a: 0}"); } @@ -789,7 +789,7 @@ TEST_F(SetNodeTest, NonViablePathWithoutRepl) { setPathToCreate("1.b"); setPathTaken("a"); ASSERT_THROWS_CODE_AND_WHAT(node.apply(getApplyParams(doc.root()["a"])), - UserException, + AssertionException, ErrorCodes::PathNotViable, "Cannot create field '1' in element {a: 1}"); } @@ -973,7 +973,7 @@ TEST_F(SetNodeTest, ApplyCannotCreateDollarPrefixedFieldInsideSetElement) { setPathTaken("a"); ASSERT_THROWS_CODE_AND_WHAT( node.apply(getApplyParams(doc.root()["a"])), - UserException, + AssertionException, ErrorCodes::DollarPrefixedFieldName, "The dollar ($) prefixed field '$bad' in 'a.$bad' is not valid for storage."); } @@ -988,7 +988,7 @@ TEST_F(SetNodeTest, ApplyCannotCreateDollarPrefixedFieldAtStartOfPath) { setPathToCreate("$bad.a"); ASSERT_THROWS_CODE_AND_WHAT( node.apply(getApplyParams(doc.root())), - UserException, + AssertionException, ErrorCodes::DollarPrefixedFieldName, "The dollar ($) prefixed field '$bad' in '$bad' is not valid for storage."); } @@ -1003,7 +1003,7 @@ TEST_F(SetNodeTest, ApplyCannotCreateDollarPrefixedFieldInMiddleOfPath) { setPathToCreate("a.$bad.b"); ASSERT_THROWS_CODE_AND_WHAT( node.apply(getApplyParams(doc.root())), - UserException, + AssertionException, ErrorCodes::DollarPrefixedFieldName, "The dollar ($) prefixed field '$bad' in 'a.$bad' is not valid for storage."); } @@ -1018,7 +1018,7 @@ TEST_F(SetNodeTest, ApplyCannotCreateDollarPrefixedFieldAtEndOfPath) { setPathToCreate("a.$bad"); ASSERT_THROWS_CODE_AND_WHAT( node.apply(getApplyParams(doc.root())), - UserException, + AssertionException, ErrorCodes::DollarPrefixedFieldName, "The dollar ($) prefixed field '$bad' in 'a.$bad' is not valid for storage."); } @@ -1053,7 +1053,7 @@ TEST_F(SetNodeTest, ApplyCannotOverwriteImmutablePath) { addImmutablePath("a.b"); ASSERT_THROWS_CODE_AND_WHAT( node.apply(getApplyParams(doc.root()["a"]["b"])), - UserException, + AssertionException, ErrorCodes::ImmutableField, "Updating the path 'a.b' to b: 1 would modify the immutable field 'a.b'"); } @@ -1088,7 +1088,7 @@ TEST_F(SetNodeTest, ApplyCannotOverwritePrefixToRemoveImmutablePath) { addImmutablePath("a.b"); ASSERT_THROWS_CODE_AND_WHAT( node.apply(getApplyParams(doc.root()["a"])), - UserException, + AssertionException, ErrorCodes::ImmutableField, "After applying the update, the immutable field 'a.b' was found to have been removed."); } @@ -1103,7 +1103,7 @@ TEST_F(SetNodeTest, ApplyCannotOverwritePrefixToModifyImmutablePath) { setPathTaken("a"); addImmutablePath("a.b"); ASSERT_THROWS_CODE_AND_WHAT(node.apply(getApplyParams(doc.root()["a"])), - UserException, + AssertionException, ErrorCodes::ImmutableField, "After applying the update, the immutable field 'a.b' was found to " "have been altered to b: 1"); @@ -1177,7 +1177,7 @@ TEST_F(SetNodeTest, ApplyCannotOverwriteSuffixOfImmutablePath) { addImmutablePath("a.b"); ASSERT_THROWS_CODE_AND_WHAT( node.apply(getApplyParams(doc.root()["a"]["b"]["c"])), - UserException, + AssertionException, ErrorCodes::ImmutableField, "Updating the path 'a.b.c' to c: 1 would modify the immutable field 'a.b'"); } @@ -1213,7 +1213,7 @@ TEST_F(SetNodeTest, ApplyCannotCreateFieldAtEndOfImmutablePath) { addImmutablePath("a.b"); ASSERT_THROWS_CODE_AND_WHAT( node.apply(getApplyParams(doc.root()["a"]["b"])), - UserException, + AssertionException, ErrorCodes::ImmutableField, "Updating the path 'a.b' to b: { c: 1 } would modify the immutable field 'a.b'"); } @@ -1230,7 +1230,7 @@ TEST_F(SetNodeTest, ApplyCannotCreateFieldBeyondEndOfImmutablePath) { addImmutablePath("a"); ASSERT_THROWS_CODE_AND_WHAT( node.apply(getApplyParams(doc.root()["a"]["b"])), - UserException, + AssertionException, ErrorCodes::ImmutableField, "Updating the path 'a.b' to b: { c: 1 } would modify the immutable field 'a'"); } diff --git a/src/mongo/db/update/unset_node_test.cpp b/src/mongo/db/update/unset_node_test.cpp index 94be0fadb2d..f1c43b4c6fa 100644 --- a/src/mongo/db/update/unset_node_test.cpp +++ b/src/mongo/db/update/unset_node_test.cpp @@ -335,7 +335,7 @@ TEST_F(UnsetNodeTest, ApplyCannotRemoveRequiredPartOfDBRef) { mutablebson::Document doc(fromjson("{a: {$ref: 'c', $id: 0}}")); setPathTaken("a.$id"); ASSERT_THROWS_CODE_AND_WHAT(node.apply(getApplyParams(doc.root()["a"]["$id"])), - UserException, + AssertionException, ErrorCodes::InvalidDBRef, "The DBRef $ref field must be followed by a $id field"); } @@ -370,7 +370,7 @@ TEST_F(UnsetNodeTest, ApplyCannotRemoveImmutablePath) { setPathTaken("a.b"); addImmutablePath("a.b"); ASSERT_THROWS_CODE_AND_WHAT(node.apply(getApplyParams(doc.root()["a"]["b"])), - UserException, + AssertionException, ErrorCodes::ImmutableField, "Unsetting the path 'a.b' would modify the immutable field 'a.b'"); } @@ -385,7 +385,7 @@ TEST_F(UnsetNodeTest, ApplyCannotRemovePrefixOfImmutablePath) { setPathTaken("a"); addImmutablePath("a.b"); ASSERT_THROWS_CODE_AND_WHAT(node.apply(getApplyParams(doc.root()["a"])), - UserException, + AssertionException, ErrorCodes::ImmutableField, "Unsetting the path 'a' would modify the immutable field 'a.b'"); } @@ -401,7 +401,7 @@ TEST_F(UnsetNodeTest, ApplyCannotRemoveSuffixOfImmutablePath) { addImmutablePath("a.b"); ASSERT_THROWS_CODE_AND_WHAT( node.apply(getApplyParams(doc.root()["a"]["b"]["c"])), - UserException, + AssertionException, ErrorCodes::ImmutableField, "Unsetting the path 'a.b.c' would modify the immutable field 'a.b'"); } diff --git a/src/mongo/db/update/update_array_node_test.cpp b/src/mongo/db/update/update_array_node_test.cpp index 42087846813..fc76b08e418 100644 --- a/src/mongo/db/update/update_array_node_test.cpp +++ b/src/mongo/db/update/update_array_node_test.cpp @@ -63,7 +63,7 @@ TEST_F(UpdateArrayNodeTest, ApplyCreatePathFails) { addIndexedPath("a"); ASSERT_THROWS_CODE_AND_WHAT( root.apply(getApplyParams(doc.root())), - UserException, + AssertionException, ErrorCodes::BadValue, "The path 'a.b' must exist in the document in order to apply array updates."); } @@ -86,7 +86,7 @@ TEST_F(UpdateArrayNodeTest, ApplyToNonArrayFails) { mutablebson::Document doc(fromjson("{a: {}}")); addIndexedPath("a"); ASSERT_THROWS_CODE_AND_WHAT(root.apply(getApplyParams(doc.root())), - UserException, + AssertionException, ErrorCodes::BadValue, "Cannot apply array updates to non-array element a: {}"); } @@ -370,7 +370,7 @@ TEST_F(UpdateArrayNodeTest, ApplyUpdatesWithMergeConflictToArrayElementFails) { mutablebson::Document doc(fromjson("{a: [0]}")); addIndexedPath("a"); ASSERT_THROWS_CODE_AND_WHAT(root.apply(getApplyParams(doc.root())), - UserException, + AssertionException, ErrorCodes::ConflictingUpdateOperators, "Update created a conflict at 'a.0'"); } @@ -401,7 +401,7 @@ TEST_F(UpdateArrayNodeTest, ApplyUpdatesWithEmptyIdentifiersWithMergeConflictToA mutablebson::Document doc(fromjson("{a: [{b: [0]}]}")); addIndexedPath("a"); ASSERT_THROWS_CODE_AND_WHAT(root.apply(getApplyParams(doc.root())), - UserException, + AssertionException, ErrorCodes::ConflictingUpdateOperators, "Update created a conflict at 'a.0.b.0'"); } @@ -436,7 +436,7 @@ TEST_F(UpdateArrayNodeTest, ApplyNestedArrayUpdatesWithMergeConflictFails) { mutablebson::Document doc(fromjson("{a: [{b: [0], c: 0}]}")); addIndexedPath("a"); ASSERT_THROWS_CODE_AND_WHAT(root.apply(getApplyParams(doc.root())), - UserException, + AssertionException, ErrorCodes::ConflictingUpdateOperators, "Update created a conflict at 'a.0.b.0'"); } @@ -659,7 +659,7 @@ TEST_F(UpdateArrayNodeTest, ApplyArrayUpdateNotFromReplication) { mutablebson::Document doc(fromjson("{a: [0]}")); addIndexedPath("a"); ASSERT_THROWS_CODE_AND_WHAT(root.apply(getApplyParams(doc.root())), - UserException, + AssertionException, ErrorCodes::PathNotViable, "Cannot create field 'b' in element {0: 0}"); } diff --git a/src/mongo/db/update/update_driver_test.cpp b/src/mongo/db/update/update_driver_test.cpp index 26dfb44cf79..52a4baa8b9a 100644 --- a/src/mongo/db/update/update_driver_test.cpp +++ b/src/mongo/db/update/update_driver_test.cpp @@ -90,7 +90,7 @@ TEST(Parse, EmptyMod) { std::map<StringData, std::unique_ptr<ExpressionWithPlaceholder>> arrayFilters; ASSERT_THROWS_CODE_AND_WHAT( driver.parse(fromjson("{$set:{}}"), arrayFilters).transitional_ignore(), - UserException, + AssertionException, ErrorCodes::FailedToParse, "'$set' is empty. You must specify a field like so: {$set: {<field>: ...}}"); } @@ -101,7 +101,7 @@ TEST(Parse, WrongMod) { std::map<StringData, std::unique_ptr<ExpressionWithPlaceholder>> arrayFilters; ASSERT_THROWS_CODE_AND_WHAT( driver.parse(fromjson("{$xyz:{a:1}}"), arrayFilters).transitional_ignore(), - UserException, + AssertionException, ErrorCodes::FailedToParse, "Unknown modifier: $xyz"); } @@ -112,7 +112,7 @@ TEST(Parse, WrongType) { std::map<StringData, std::unique_ptr<ExpressionWithPlaceholder>> arrayFilters; ASSERT_THROWS_CODE_AND_WHAT( driver.parse(fromjson("{$set:[{a:1}]}"), arrayFilters).transitional_ignore(), - UserException, + AssertionException, ErrorCodes::FailedToParse, "Modifiers operate on fields but we found type array instead. For " "example: {$mod: {<field>: ...}} not {$set: [ { a: 1 } ]}"); @@ -125,7 +125,7 @@ TEST(Parse, ModsWithLaterObjReplacement) { ASSERT_THROWS_CODE_AND_WHAT( driver.parse(fromjson("{$set:{a:1}, obj: \"obj replacement\"}"), arrayFilters) .transitional_ignore(), - UserException, + AssertionException, ErrorCodes::FailedToParse, "Unknown modifier: obj"); } diff --git a/src/mongo/db/update/update_leaf_node.h b/src/mongo/db/update/update_leaf_node.h index 3e0b5b4d095..c268facec30 100644 --- a/src/mongo/db/update/update_leaf_node.h +++ b/src/mongo/db/update/update_leaf_node.h @@ -57,7 +57,7 @@ public: * it. If 'element' is not an embedded object or array (e.g., we are trying to create path * "a.b.c" in the document {a: 1}) or 'element' is an array but the first component in * 'pathToCreate' is not an array index (e.g., the path "a.b.c" in the document - * {a: [{b: 1}, {b: 2}]}), then this function throws a UserException with + * {a: [{b: 1}, {b: 2}]}), then this function throws a AssertionException with * ErrorCode::PathNotViable. Otherwise, this function is a no-op. * * With the exception of $unset, update modifiers that do not create nonexistent paths ($pop, diff --git a/src/mongo/db/update/update_node.h b/src/mongo/db/update/update_node.h index 180f5755ecb..b8cb17dbb9a 100644 --- a/src/mongo/db/update/update_node.h +++ b/src/mongo/db/update/update_node.h @@ -150,8 +150,8 @@ public: * Creates a new node by merging the contents of two input nodes. The semantics of the merge * operation depend on the types of the input nodes. When the nodes have the same type, this * function dispatches the merge to a createUpdateNodeByMerging implementation defined for that - * subtype. Throws UserException with a ConflictingUpdateOperators code when the types of the - * input nodes differ or when any of the child nodes fail to merge. + * subtype. Throws AssertionException with a ConflictingUpdateOperators code when the types of + * the input nodes differ or when any of the child nodes fail to merge. */ static std::unique_ptr<UpdateNode> createUpdateNodeByMerging(const UpdateNode& leftNode, const UpdateNode& rightNode, diff --git a/src/mongo/db/update/update_object_node_test.cpp b/src/mongo/db/update/update_object_node_test.cpp index 6bb3d2c51c8..37569cdea05 100644 --- a/src/mongo/db/update/update_object_node_test.cpp +++ b/src/mongo/db/update/update_object_node_test.cpp @@ -1328,7 +1328,7 @@ TEST(UpdateObjectNodeTest, TopLevelConflictFails) { std::unique_ptr<UpdateNode> result; ASSERT_THROWS_CODE_AND_WHAT( result = UpdateNode::createUpdateNodeByMerging(setRoot1, setRoot2, &fakeFieldRef), - UserException, + AssertionException, ErrorCodes::ConflictingUpdateOperators, "Update created a conflict at 'root.a'"); } @@ -1357,7 +1357,7 @@ TEST(UpdateObjectNodeTest, NestedConflictFails) { std::unique_ptr<UpdateNode> result; ASSERT_THROWS_CODE_AND_WHAT( result = UpdateNode::createUpdateNodeByMerging(setRoot1, setRoot2, &fakeFieldRef), - UserException, + AssertionException, ErrorCodes::ConflictingUpdateOperators, "Update created a conflict at 'root.a.b'"); } @@ -1386,7 +1386,7 @@ TEST(UpdateObjectNodeTest, LeftPrefixMergeFails) { std::unique_ptr<UpdateNode> result; ASSERT_THROWS_CODE_AND_WHAT( result = UpdateNode::createUpdateNodeByMerging(setRoot1, setRoot2, &fakeFieldRef), - UserException, + AssertionException, ErrorCodes::ConflictingUpdateOperators, "Update created a conflict at 'root.a.b'"); } @@ -1415,7 +1415,7 @@ TEST(UpdateObjectNodeTest, RightPrefixMergeFails) { std::unique_ptr<UpdateNode> result; ASSERT_THROWS_CODE_AND_WHAT( result = UpdateNode::createUpdateNodeByMerging(setRoot1, setRoot2, &fakeFieldRef), - UserException, + AssertionException, ErrorCodes::ConflictingUpdateOperators, "Update created a conflict at 'root.a.b'"); } @@ -1444,7 +1444,7 @@ TEST(UpdateObjectNodeTest, LeftPrefixMergeThroughPositionalFails) { std::unique_ptr<UpdateNode> result; ASSERT_THROWS_CODE_AND_WHAT( result = UpdateNode::createUpdateNodeByMerging(setRoot1, setRoot2, &fakeFieldRef), - UserException, + AssertionException, ErrorCodes::ConflictingUpdateOperators, "Update created a conflict at 'root.a.$.c'"); } @@ -1473,7 +1473,7 @@ TEST(UpdateObjectNodeTest, RightPrefixMergeThroughPositionalFails) { std::unique_ptr<UpdateNode> result; ASSERT_THROWS_CODE_AND_WHAT( result = UpdateNode::createUpdateNodeByMerging(setRoot1, setRoot2, &fakeFieldRef), - UserException, + AssertionException, ErrorCodes::ConflictingUpdateOperators, "Update created a conflict at 'root.a.$.c'"); } @@ -1502,7 +1502,7 @@ TEST(UpdateObjectNodeTest, MergeWithConflictingPositionalFails) { std::unique_ptr<UpdateNode> result; ASSERT_THROWS_CODE_AND_WHAT( result = UpdateNode::createUpdateNodeByMerging(setRoot1, setRoot2, &fakeFieldRef), - UserException, + AssertionException, ErrorCodes::ConflictingUpdateOperators, "Update created a conflict at 'root.a.$'"); } @@ -1564,7 +1564,7 @@ TEST(UpdateObjectNodeTest, MergingArrayNodeWithObjectNodeFails) { std::unique_ptr<UpdateNode> result; ASSERT_THROWS_CODE_AND_WHAT( result = UpdateNode::createUpdateNodeByMerging(setRoot1, setRoot2, &fakeFieldRef), - UserException, + AssertionException, ErrorCodes::ConflictingUpdateOperators, "Update created a conflict at 'root.a'"); } @@ -1595,7 +1595,7 @@ TEST(UpdateObjectNodeTest, MergingArrayNodeWithLeafNodeFails) { std::unique_ptr<UpdateNode> result; ASSERT_THROWS_CODE_AND_WHAT( result = UpdateNode::createUpdateNodeByMerging(setRoot1, setRoot2, &fakeFieldRef), - UserException, + AssertionException, ErrorCodes::ConflictingUpdateOperators, "Update created a conflict at 'root.a'"); } @@ -1666,7 +1666,7 @@ TEST(UpdateObjectNodeTest, MergeConflictThroughArrayNodesFails) { std::unique_ptr<UpdateNode> result; ASSERT_THROWS_CODE_AND_WHAT( result = UpdateNode::createUpdateNodeByMerging(setRoot1, setRoot2, &fakeFieldRef), - UserException, + AssertionException, ErrorCodes::ConflictingUpdateOperators, "Update created a conflict at 'root.a.$[i].b'"); } @@ -2088,7 +2088,7 @@ TEST_F(UpdateObjectNodeTest, ApplyBlockingElement) { mutablebson::Document doc(fromjson("{a: 0}")); addIndexedPath("a"); ASSERT_THROWS_CODE_AND_WHAT(root.apply(getApplyParams(doc.root())), - UserException, + AssertionException, ErrorCodes::PathNotViable, "Cannot create field 'b' in element {a: 0}"); } @@ -2140,7 +2140,7 @@ TEST_F(UpdateObjectNodeTest, ApplyPositionalMissingMatchedField) { addIndexedPath("a"); ASSERT_THROWS_CODE_AND_WHAT( root.apply(getApplyParams(doc.root())), - UserException, + AssertionException, ErrorCodes::BadValue, "The positional operator did not find the match needed from the query."); } @@ -2241,7 +2241,7 @@ TEST_F(UpdateObjectNodeTest, ApplyMergeConflictWithPositionalChild) { setMatchedField("0"); addIndexedPath("a"); ASSERT_THROWS_CODE_AND_WHAT(root.apply(getApplyParams(doc.root())), - UserException, + AssertionException, ErrorCodes::ConflictingUpdateOperators, "Update created a conflict at 'a.0'"); } @@ -2489,7 +2489,7 @@ TEST_F(UpdateObjectNodeTest, ApplyUpdateToNonViablePathInArray) { mutablebson::Document doc(fromjson("{a: [{b: 1}, {b: 2}]}")); addIndexedPath("a"); ASSERT_THROWS_CODE_AND_WHAT(root.apply(getApplyParams(doc.root())), - UserException, + AssertionException, ErrorCodes::PathNotViable, "Cannot create field 'b' in element {a: [ { b: 1 }, { b: 2 } ]}"); } |