Flourish PHP Unframework
This is an archived copy of the forum for reference purposes

fCore::handleException() BUG/Typo

posted by gabrielu 9 years ago

I've noticed that setting fCore::enableErrorHandling() and fCore::enableExceptionHandling() without 'html' as the value still prints the message on screen. In my scenario I do the following:

$template = new fTemplating(DOC_ROOT . '/templates/');
$template->set('site_down', 'site_down.php');

fCore::enableErrorHandling(DOC_ROOT . '/writable/errors.log');
fCore::enableExceptionHandling(DOC_ROOT . '/writable/exceptions.log', array($template, 'place'), array('site_down'));

$db = new fDatabase('mysql', 'invalid_db', 'invalid_user', 'invalid_pass', 'invalid_host');

if($db->getConnection()) {
	echo "connected!";
} else {
	echo "cannot connect!";
}
fORMDatabase::attach($db);

I purposely used invalid database connection information. I expected the connection to fail and for the "site_down.php" template to load with all errors and exceptions being written to .log files. Instead the "It appears an error has occured - we apologize for the inconvenience. The problem may be resolved if you try again." message was printed on screen.

I was able to track down the error and believe that it is in fCore::handleException() line# 824:

if (self::$exception_destination != 'html' && $exception instanceof fException) {

I believe that should be changed to:

if (self::$exception_destination == 'html' && $exception instanceof fException) {

I can definitely see how this could be interpreted as a bug, however that was the intended functionality. I think you make a good point, so I changed the code to only print the message if the destination is not html and there is no callback. Basically fException::printMessage() acts as a default callback for non-html destinations. This change was made in r844.

posted by wbond 9 years ago

Thanks! It was giving me problems (printing error message to screen) when I wanted to show a message/page like "Website Updating..." when there was an issue connecting to the database.

posted by gabrielu 9 years ago

I tried using this, and i want to send myself an email in case my site gives off some errors to address them.

fCore::enableErrorHandling('my@email.com');
fCore::enableExceptionHandling('my@email.com');
	
fCore::enableErrorHandling(DOC_ROOT . '/logs/errors.log');
fCore::enableExceptionHandling(DOC_ROOT . '/logs/exceptions.log');

I made my site catch an exception but there is no email that is sent and the logs are never created. Is this still a bug? Anyone experiencing this issue?

posted by psylovibe 9 years ago

It seems that you can't have a

Try { 
} Catch { 
}

on code that you want fCore::enableErrorHandling() and fCore::enableExceptionHandling() to handle.

posted by gabrielu 9 years ago

Right, the exception handler is only for uncaught exceptions. There is no way built into Flourish to log all exceptions that are thrown. You probably wouldn't want to do that anyway since there are many places where Flourish throws and catches exceptions that you never need to know or worry about.

posted by wbond 9 years ago

You can only have only destination for errors and one destination for exceptions. In the example you provided, the errors and exceptions should be going to the log files and not the email since you overrode the email with the log file path.

I use email error and exception notification daily on many production sites, however I do not use logging on a regular basis. If there is a problem, please be sure to file a ticket.

posted by wbond 9 years ago