-
Type: Improvement
-
Resolution: Done
-
Priority: Minor - P4
-
Affects Version/s: 0.9
-
Component/s: None
-
None
-
Environment:Win 7
When a MongoCommandException exception is thrown the code that reports it discards the 'assertion' and 'assertion code' from the results object. These typically contain the actual reason for the problem.
Suggestions:-
1) Maybe the ErrorMessage property of the CommandResult class should be changed to be a concatenation of the errmsg, assertion code, and assertion properties as the error message itself is fairly useless
2) The RunCommandAs method should be changed to use the existing constructor for MongoCommandException that puts the result object into the .Data property of the exception. (Most developers however aren't familiar with Exception.Data and might miss this)
3) if not #1 then at least the RunCommandAs should concatenate the strings when it creates an exception message.
public TCommandResult RunCommandAs<TCommandResult>(
IMongoCommand command
) where TCommandResult : CommandResult {
var result = CommandCollection.FindOneAs<TCommandResult>(command);
if (!result.Ok) {
if (result.ErrorMessage == "not master")
string errorMessage = string.Format("Command failed:
{0}", string.Join(" ", result.Select(x => x.ToString()).ToArray()); // a simple dump of the result enumeration
throw new MongoCommandException(errorMessage, result);
}
return result;
}