snytkine / LampCMS

Open source Question and Answer program similar to StackOverflow and Quora in PHP + MongoDB. Follow @snytkine on Twitter
http://support.lampcms.com
323 stars 104 forks source link

Better handling of Mongo connection errors #84

Closed snytkine closed 12 years ago

snytkine commented 12 years ago

Mongo sucks at reporting connection errors. One thing is does is it emits php notice that contains some nonsense text. For example ("saying something" or "parsing servers") We have our own error handler that turns php notices, warnings and errors into DevException. So we have DevException back in Mongo Connection dumps this nonsense at us. But what if error level is set to ignore php notice?

Sometimes Mongo may not even report any errors during initial connection but then during simple operations like findOne it will detect connection error and return some ugly notice or error or some other unpredictable error.

Possible solution: Try to make use of MongoConnectionException first, then MongoException, then DevException, then \Exception Make sure to set php error level high to catch even php notices.

Try to do a simple operation inside of our own mongo constructor like selectDB() and then listCollection()

And hope that Mongo will report some errors if there is any connection problems.

Must test with later version of Mongo database and with latest version of php mongo extension. if everything looks good then at least recommend people to use at least these versions.

snytkine commented 12 years ago

Done. Updated constructor in Mongo\DB to lower error reporting level and also to catch more specific exceptions first. Also modified LampcmsErrorHandler to ignore any error that has 'mongocollection' string in it. These are notices that come from MongoCollection object during ensureIndex and during some other operations.