Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.1.0RC1

Request #7456 improve error frame used with PEAR_ErrorStack
Submitted: 2006-04-22 06:58 UTC Modified: 2006-04-25 14:39 UTC
From: farell Assigned: farell
Status: Closed Package: PEAR_PackageUpdate (version 0.4.2)
PHP Version: 4.4.2 OS: Windows XP
Roadmaps: (Not assigned)    
Subscription  


 [2006-04-22 06:58 UTC] farell (Laurent Laville)
Description: ------------ While i'm now ready to propose a PPU web frontend in next minutes, i've found another problem with error management. This is due to implementation of PEAR_ErrorStack. When no context callback is set to PEAR_ErrorStack instance and no backtrace given when calling PEAR_ErrorStack push() method (see line 915 of PPU) you get always the same context error. To avoid this situation, i suggest to add: - in class constructor ( __construct ), just after $this->errors =& PEAR_ErrorStack::singleton(get_class($this)); this line : $this->errors->setContextCallback(array(&$this,'getBacktrace')); - and of course the new getBacktrace() method function getBacktrace() { if (function_exists('debug_backtrace')) { $backtrace = debug_backtrace(); $backtrace = $backtrace[count($backtrace)-1]; } else { $backtrace = false; } return $backtrace; } Even if it's not really a bug (change request), it could be nice to improve to have a better error reporting. BTW, i've added an optional context feature in PPU web frontend errorDialog() method. Hope it will help again Laurent Test script: --------------- // test script file: ppu3.php <?php require_once 'PEAR/PackageUpdate.php'; function varDump($var) { echo '<pre style="background-color:#eee; color:#000; padding:1em;">'; var_dump($var['context']); echo '</pre>'; } class PEAR_PackageUpdate3 extends PEAR_PackageUpdate { function PEAR_PackageUpdate3($packageName, $channel) { PEAR_PackageUpdate3::__construct($packageName, $channel); } function __construct($packageName, $channel) { // Create a pear error stack. require_once 'PEAR/ErrorStack.php'; $this->errors =& PEAR_ErrorStack::singleton(get_class($this)); $this->errors->setContextCallback(array(&$this,'getBacktrace')); // Set the package name and channel. $this->packageName = $packageName; $this->channel = $channel; // Load the user's preferences. $this->loadPreferences(); } function getBacktrace() { if (function_exists('debug_backtrace')) { $backtrace = debug_backtrace(); $backtrace = $backtrace[count($backtrace)-1]; } else { $backtrace = false; } return $backtrace; } } $ppu = PEAR_PackageUpdate3::factory('Web', 'XML_RPC', ''); // Make sure the updater was created properly. if ($ppu === false) { echo "Could not create updater.\n"; echo "You might want to check for an install updates manually.\n"; die(); } // Check to see if any updates are availble. if ($ppu->checkUpdate()) { // If updates are available, present the user with the option to update. if ($ppu->presentUpdate()) { // Update the package. print "// Update the package\n"; } } // Check for errors. if ($ppu->hasErrors()) { $err = $ppu->popError(); varDump($err); } ?> Expected result: ---------------- array(6) { ["file"]=> string(45) "[...]\PEAR_PackageUpdate_Web\ppu3.php" ["line"]=> int(55) ["function"]=> string(11) "checkupdate" ["class"]=> string(22) "pear_packageupdate_web" ["type"]=> string(2) "->" ["args"]=> array(0) { } } Actual result: -------------- array(4) { ["file"]=> string(40) "[...]\PEAR\PackageUpdate.php" ["line"]=> int(915) ["function"]=> string(9) "pusherror" ["class"]=> string(22) "pear_packageupdate_web" }

Comments

 [2006-04-25 13:36 UTC] farell (Laurent Laville)
Assign to myself.
 [2006-04-25 14:39 UTC] farell (Laurent Laville)
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.