snytkine / LampCMS

Open source Question and Answer program similar to StackOverflow and Quora in PHP + MongoDB. Follow @snytkine on Twitter

Home Page:http://support.lampcms.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Better handling of Mongo connection errors

snytkine opened this issue · comments

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.

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.