Permalink
Browse files

SERVER-12093 Improve error message when adding a user with a role tha…

…t doesn't exist on mongos
  • Loading branch information...
1 parent 5faea8c commit db151b44bce6975fd66e6eece4088035526e57ae @stbrody stbrody committed Jan 14, 2014
Showing with 16 additions and 2 deletions.
  1. +1 −0 src/mongo/base/error_codes.err
  2. +15 −2 src/mongo/db/auth/authz_manager_external_state_s.cpp
@@ -79,6 +79,7 @@ error_code("NoReplicationEnabled", 76)
error_code("OperationIncomplete", 77)
error_code("CommandResultSchemaViolation", 78)
error_code("UnknownReplWriteConcern", 79)
+error_code("RoleDataInconsistent", 80)
# Non-sequential error codes (for compatibility only)
error_code("DuplicateKey", 11000)
@@ -129,7 +129,8 @@ namespace mongo {
std::vector<BSONElement> foundUsers = cmdResult["users"].Array();
if (foundUsers.size() == 0) {
- return Status(ErrorCodes::UserNotFound, "User not found");
+ return Status(ErrorCodes::UserNotFound,
+ "User \"" + userName.toString() + "\" not found");
}
if (foundUsers.size() > 1) {
return Status(ErrorCodes::UserDataInconsistent,
@@ -166,7 +167,19 @@ namespace mongo {
if (code == 0) code = ErrorCodes::UnknownError;
return Status(ErrorCodes::Error(code), cmdResult["errmsg"].str());
}
- *result = cmdResult["roles"]["0"].Obj().getOwned();
+
+ std::vector<BSONElement> foundRoles = cmdResult["roles"].Array();
+ if (foundRoles.size() == 0) {
+ return Status(ErrorCodes::RoleNotFound,
+ "Role \"" + roleName.toString() + "\" not found");
+ }
+ if (foundRoles.size() > 1) {
+ return Status(ErrorCodes::RoleDataInconsistent,
+ mongoutils::str::stream() << "Found multiple roles on the \"" <<
+ roleName.getDB() << "\" database with name \"" <<
+ roleName.getRole() << "\"");
+ }
+ *result = foundRoles[0].Obj().getOwned();
conn->done();
return Status::OK();
} catch (const DBException& e) {

0 comments on commit db151b4

Please sign in to comment.