|
From: R. M. v. D. <mv...@ca...> - 2003-07-28 23:28:28
|
I've commit to CVS a preliminary version of a new error handler for
review in class/errorhandler.php. Changes were also made in
include/common.php to 'activate' it.
By default, I have turned on error reporting at the beginning, which later
gets turned off once the DB is connected and the config value
(debug_mode) can be read.
It cannot trap PHP 'fatal' or 'parse' errors, so 'trigger_error' should be
added throughout the code where problems can be detected early. e.g. I
have modified common.php so if the database is not connected, an error is
triggered. (If the code were to continue instead, it would trigger a
'fatal' error, "call to a member of a non-object" which cannot be
trapped.) When an error cannot be trapped, it leads to the blank page
problem (if server has display_errors Off).
Currently an error triggered with type 'E_USER_ERROR' will add its message
then exit immediately. This should be used for unrecoverable problems
(such as not able to connect to DB). 'E_USER_WARNING' and 'E_USER_NOTICE'
can be used to print helpful diagnostics due to unexpected but not fatal
conditions.
e.g.
trigger_error("Encountered major error and cannot continue generating
page", E_USER_ERROR");
trigger_error("Encountered a less major problem which we can ignore
but here is a diagnostic message", E_USER_WARNING);
Anyways, please let me know if you like it. I can remove it / correct it
if anyone finds any problems with it.
Regards,
Mike
On Fri, 11 Jul 2003, K. Ono wrote:
> I guess we'd better stick with using the trigger_error function directly
> otherwise we would need to pass the file name and line numbers explicitly
> like
> notice($msg, __FILE__, __LINE__); if we need to know where the error
> occurred exactly and that doesn't seem to make things any easier for the
> developers..
>
> - Kazu
>
>
> ----- Original Message -----
> From: "K. Ono" <web...@my...>
> To: <xoo...@li...>
> Sent: Thursday, July 10, 2003 4:21 PM
> Subject: Re: [Xoops-development] addressing "blank page" problem
>
>
> > > Or maybe this: Leave the error handler always ON. If debug mode is on,
> > > show all errors and warnings (native PHP messages AND explicitly
> > > 'triggered' messages). If debug mode is off, show only 'triggered'
> > > messages. If we use trigger_error very sparingly (or E_USER_ERROR for
> > > errors-to-be-displayed) then the end user will only see a message if
> > > something goes very wrong (e.g. can't connect to database), which may be
> > > useful to alert the site administrator. (In a custom error handler you
> > > can strip out any path info so this is not a security risk.)
> >
> > I like this idea.. Maybe we can wrap the trigger_error() function with a
> > custom function/class so that we
> > can always call the custom trigger error function/method within the codes
> > which does
> > not always call the native trigger_error function. This way, the coders
> > wouldn't need to
> > think about whether to use the native trigger_error() function in certain
> > areas of their
> > codes but just always use the custom one wherever something wrong might
> > happen.
> >
> > For example,
> >
> >
> > class ErrorHandler
> > {
> >
> > function ErrorHandler()
> > {
> > set_error_handler(array(&$this, 'trigger'));
> > }
> >
> > function trigger($errno, $errstr, $errfile, $errline)
> > {
> > switch ($errno) {
> > case E_USER_ERROR:
> > // do something here
> > break;
> > case E_USER_WARNING:
> > // do something here
> > break;
> > case E_USER_NOTICE:
> > // do something here
> > break;
> > default:
> > // do something here
> > break;
> > }
> >
> > }
> >
> > // A class that triggers all errors
> > class ShowAllErrorHandler extends ErrorHandler
> > {
> >
> > function notice($msg)
> > {
> > trigger_error(E_USER_NOTICE, $msg);
> > }
> >
> > function warning($msg)
> > {
> > trigger_error(E_USER_WARNING, $msg);
> > }
> >
> > function fatal($msg)
> > {
> > trigger_error(E_USER_ERROR, $msg);
> > }
> > }
> >
> > // A class that triggers only fatal-level errors
> > class FatalErrorHandler extends ErrorHandler
> > {
> > function notice($msg)
> > {
> > // do nothing
> > }
> >
> > function warning($msg)
> > {
> > // do nothing
> > }
> >
> > function fatal($msg)
> > {
> > trigger_error(E_USER_ERROR, $msg);
> > }
> > }
> >
> >
> > And at startup, we can use a factory method/class to create one of the
> error
> > handler classes
> > depending on a config setting or the user level (admin, anonymous, etc).
> >
> > $debug_level = $xoopsUser->isAdmin() ? XOOPS_DEBUG_SHOWALL :
> > $config['debug_level'];
> > $error_handler =& ErrorHandler::getInstance($debug_level);
> > ...
> > $error_handler->notice('A notice error');
> > ...
>
>
>
> -------------------------------------------------------
> This SF.Net email sponsored by: Parasoft
> Error proof Web apps, automate testing & more.
> Download & eval WebKing and get a free book.
> www.parasoft.com/bulletproofapps1
> _______________________________________________
> Xoops-development mailing list
> Xoo...@li...
> https://lists.sourceforge.net/lists/listinfo/xoops-development
>
>
|