Exception Handling
ebeyrent - October 23, 2008 - 20:08
| Project: | AMFPHP |
| Version: | 5.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Description
I've been working with Flex, AMFPHP, and Services, and came across a case where AMFPHP was throwing a fault on a PHP warning message:
imagecolorsforindex(): Color index 108 out of range
I found that simply changing the gateway error handling to this:
<?php
//$gateway->setErrorHandling(E_ALL ^ E_NOTICE);
$gateway->setErrorHandling(E_ERROR);
?>Everything works as expected. Should faults get thrown on warnings? Could we just add an admin interface:
<?php
define(AMFPHP_EXCEPTION_HANDLER, 'amfphp_exception_handler');
/**
* implementation of hook_menu
*/
function amfphp_menu($may_cache){
$items = array();
if($may_cache){
$items[] = array(
'path' => 'admin/settings/amfphp/exceptions',
'title' => t('AMFPHP Exceptions Configuration'),
'callback' => 'drupal_get_form',
'callback arguments' => array('amfphp_admin'),
'description' => t('AMFPHP Exception handling configuration'),
'access' => user_access('administer site configuration')
);
}
return $items;
}
function amfphp_admin(){
$form = array();
$form['amfphp'] = array(
'#type' => 'fieldset',
'#title' => t('AMFPHP Exception Settings'),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
'#weight' => -4,
);
$form['amfphp'][AMFPHP_EXCEPTION_HANDLER] = array(
'#type' => 'select',
'#title' => t('Select PHP error threshold'),
'#default_value' => variable_get(AMFPHP_EXCEPTION_HANDLER, 'E_ALL ^ E_NOTICE'),
'#options' => array(
'E_ALL ^ E_NOTICE' => t('E_ALL ^ E_NOTICE'),
'E_ERROR' => t('E_ERROR')
),
'#help' => 'Configure the PHP error types for which AMFPHP will throw exceptions'
);
return system_settings_form($form);
}
?>And then in amfphp.module, you could do something like:
<?php
$gateway->setErrorHandling(variable_get(AMFPHP_EXCEPTION_HANDLER, 'E_ALL ^ E_NOTICE'));
?>
#1
Actually, a more correct implementation would probably be to store the value of the PHP constants:
<?phpfunction amfphp_admin(){
$form = array();
$form['amfphp'] = array(
'#type' => 'fieldset',
'#title' => t('AMFPHP Exception Settings'),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
'#weight' => -4,
);
$form['amfphp'][AMFPHP_EXCEPTION_HANDLER] = array(
'#type' => 'select',
'#title' => t('Select PHP error threshold'),
'#default_value' => variable_get(AMFPHP_EXCEPTION_HANDLER, 2039),
'#options' => array(
2039 => t('E_ALL ^ E_NOTICE'),
2047 => t('E_ERROR')
),
'#description' => 'Configure the PHP error types for which AMFPHP will throw exceptions'
);
return system_settings_form($form);
}
?>
And this is how the gateway error handling would be set:
<?php$gateway->setErrorHandling(variable_get(AMFPHP_EXCEPTION_HANDLER, 2039));
?>
#2
And here's a patch comprised of the above code.
#3
Committed to D5 and D6 dev branches. See admin/build/services/settings/amfphp.
Thanks guys!
#4
Automatically closed -- issue fixed for 2 weeks with no activity.