From 4b5cfc190c702aad25a353d8b3e275f71599b05f Mon Sep 17 00:00:00 2001 From: Scott Hernandez Date: Mon, 7 Oct 2013 15:23:43 -0400 Subject: SERVER-10958: Update error messages and provide _id of error docs --- src/mongo/db/ops/field_checker.cpp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'src/mongo/db/ops/field_checker.cpp') diff --git a/src/mongo/db/ops/field_checker.cpp b/src/mongo/db/ops/field_checker.cpp index 86d7981b24b..e4611727832 100644 --- a/src/mongo/db/ops/field_checker.cpp +++ b/src/mongo/db/ops/field_checker.cpp @@ -44,21 +44,25 @@ namespace fieldchecker { const size_t numParts = field.numParts(); if (numParts == 0) { - return Status(ErrorCodes::BadValue, "cannot update an empty field name"); + return Status(ErrorCodes::EmptyFieldName, + "An empty update path is not valid."); } for (size_t i = 0; i != numParts; ++i) { const StringData part = field.getPart(i); if ((i == 0) && part.compare("_id") == 0) { - return Status(ErrorCodes::BadValue, - "update cannot affect the _id"); + return Status(ErrorCodes::ImmutableIdField, + mongoutils::str::stream() << "The update path '" + << field.dottedField() + << "' contains the '_id' field, which cannot be updated."); } if (part.empty()) { - return Status(ErrorCodes::BadValue, - mongoutils::str::stream() << field.dottedField() - << " contains empty fields"); + return Status(ErrorCodes::EmptyFieldName, + mongoutils::str::stream() << "The update path '" + << field.dottedField() + << "' contains an empty field, which is not allowed."); } if (!legacy && (part[0] == '$')) { @@ -88,9 +92,11 @@ namespace fieldchecker { part.startsWith("$ref"); if (!mightBePartOfDbRef) - return Status(ErrorCodes::BadValue, - mongoutils::str::stream() << field.dottedField() - << " contains field names with leading '$' character"); + return Status(ErrorCodes::DollarPrefixedFieldName, + mongoutils::str::stream() << "The update path '" + << field.dottedField() + << "' contains an illegal field name " + "(field name starts with '$')."); } -- cgit v1.2.1