As fairly new FuelPHP user, I must say, I’ve been impressed so far. The built-in packages are impressive, migrations are awesome, and the profiling tool takes a lot of headache out of debugging. However, the one thing I’ve disliked about FuelPHP is my frequent run-ins with this really annoying, generic error that simply says:
Oops! An unexpected error has occurred.
That’s it. No line numbers, no filenames, no broken SQL statements, nothing. So like any other FuelPHP developer would do, I turned on profiling–easy fix, right? Well as it turns out, the error broke profiling as well. So after an hour or so of tracing through code, I found the culprit: an SQL insert statement referencing a field that didn’t exist. Apparently, a simple SQL error caused the PHP framework equivalent of a kernel panic. I found problem by adding this debugging echo statement in fuel/core/classes/database/mysql/connection.php on line 209:
// Execute the query
if (($result = mysql_query($sql, $this->_connection)) === false)
{
if (isset($benchmark))
{
// This benchmark is worthless
Profiler::delete($benchmark);
}
echo mysql_error($this->_connection); //Add this line here
throw new \Database_Exception(mysql_error($this->_connection).' [ '.$sql.' ]', mysql_errno($this->_connection));
}
It’s a bit frustrating that FuelPHP couldn’t detect the cause of the error, but the framework is a work-in-progress (a very good one at that), and all things considered, it’s still an awesome piece of software.
3 Comments
Could you report an issue for this on github? Preferably with a little more info and some code, that way we can fix this.
FuelPHP only displays this generic error message when the framework is running in production mode. This is for security reasons, you don’t want to divulge information about the internal workings of your application.
In development mode the error is displayed, including a backtrace.
In all modes, the error is also written to the logfile, so even for production sites you can find the error.
That makes sense, I should have checked the logs, thanks for the tip. Good thing FuelPHP is smarter than I am.