marcesher / cfmongodb

MongoDB client wrapper for ColdFusion
89 stars 34 forks source link

Handling of a bad mapReduce #18

Closed cfjedimaster closed 13 years ago

cfjedimaster commented 13 years ago

This is most likely a simple bug on my part, but cfmongo db isn't handling the error right. I'm trying to mapReduce a complex set of data down to report on tags. Given that I'm probably doing it wrong, this is the error I get:

Element result is undefined in a Java object of type class com.mongodb.CommandResult.

The error occurred in C:\Users\Raymond\Dropbox\websites\testingzone\deepcomment\cfmongodb\core\DBCollection.cfc: line 255 253 : var commandResult = mongoDB.command( dbCommand ); 254 : 255 : var mrCollection = mongo.getDBCollection( commandResult["result"] ); 256 : var searchResult = mrCollection.query().find(); 257 : var mapReduceResult = createObject("component", "MapReduceResult").init(dbCommand, commandResult, searchResult, mongoUtil);

Looks like result may not always exist in commandResult. A simple structKeyExists would help that (or an isnull check if the key exists and the value is null).

cfjedimaster commented 13 years ago

As just an FYI, I quickly did this:

var commandResult = mongoDB.command( dbCommand ); writedump(commandResult);abort;

and in commandResult I did see a nice error from Mongo. So cfmongo should just grab that and rethrow it.

cfjedimaster commented 13 years ago

This is the mod I made:

if(structKeyExists(commandResult, "errmsg")) throw(message=commandResult["errmsg"],detail=commandResult["assertion"]);

Although I don't know if assertion will always exist as a key.

marcesher commented 13 years ago

Done for both mapreduce and group. Message will contain the 'errmsg' key, and extendedinfo will contain all the information provided by the command result