Re: Using PEAR_ErrorStack

From: Date: Wed, 15 Mar 2006 18:15:49 +0000
Subject: Re: Using PEAR_ErrorStack
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-41802@lists.php.net to get a copy of this message
Scott Mattocks a écrit :
Hello, I am trying to understand how to use PEAR_ErrorStack so that I can update my proposal for PEAR_PackageUpdate but I am having some trouble. I need to capture errors from other packages and add them to the stack. For example, I have this in my code: // Check for errors. if (PEAR::isError($parsed)) {
    // Do something with the error...
} How can I get that error on to the stack without making calls to getCode, getMessage, etc...? Also, is there a way to make other packages use my error stack? The above code comes from a call to a PEAR_Registry object. I would like to use PEAR::setErrorHandling() but there is no option for PEAR_ErrorStack. Using setErrorHandling(PEAR_ERROR_CALLBACK, array($myStack, 'push')) will not work because the call back must accept a PEAR_Error object. Any help is appreciated. Thanks,
Scott, i think solution came with Ian Eure and its StackThunk package Here is part of code reproduced and already implemented in my PFM backend.
    function repackagePEAR_Error(&$error)
    {
        static $map;
        if (!isset($map)) {
            $map = array(
                E_ERROR            => 'error',
                E_WARNING          => 'warning',
                E_PARSE            => 'exception',
                E_NOTICE           => 'notice',
                E_CORE_ERROR       => 'error',
                E_CORE_WARNING     => 'warning',
                E_COMPILE_ERROR    => 'exception',
                E_COMPILE_WARNING  => 'warning',
                E_USER_ERROR       => 'error',
                E_USER_WARNING     => 'warning',
                E_USER_NOTICE      => 'notice'
            );
        }
        // Strip this function from the trace
        if (is_array($error->backtrace)) {
            array_shift($error->backtrace);
            $error->userinfo['backtrace'] =& $error->backtrace;
        }
        PEAR_ErrorStack::staticPush('@package_name@',
            $error->code, $map[$error->level],
            $error->userinfo, $error->message, false, $error->backtrace
            );
    }
$error is a PEAR_Error object Here is a simple example $pkg = &PEAR_PackageFileManager2::importFromPackageFile1($packagefile, $optionsUpdate); if (PEAR::isError($pkg)) {
    $this->repackagePEAR_Error($pkg);
} and you get PEAR_Error from PFM into your own stack PEAR_ErrorStack::singleton('@package_name@'); is called by PEAR_ErrorStack::staticPush('@package_name@', ...); Hope it will help Laurent

« previous php.pear.dev (#41802) next »