public static function panic(\exception $e) { $response = Factory::make("response"); $vars = []; $vars['message'] = $e->getMessage(); $vars['file_line'] = $e->getFile() . " " . $e->getLine(); $response->renderHtml("exception.html", $vars); }
/** * Show YAF Error * only display errors under DEV, else save error in LOG_FILE * @param exception $exception * @return void */ public function errorAction($exception) { switch ($exception->getCode()) { case YAF_ERR_NOTFOUND_MODULE: case YAF_ERR_NOTFOUND_CONTROLLER: case YAF_ERR_NOTFOUND_ACTION: case YAF_ERR_NOTFOUND_VIEW: if (ENV == 'DEV') { echo 404, ":", $exception->getMessage(); } else { echo 404; file_put_contents(LOG_FILE, $exception->getMessage() . PHP_EOL, FILE_APPEND); } break; default: if (ENV == 'DEV') { echo 0, ":", $exception->getMessage(); } else { echo 'Unknown error'; file_put_contents(LOG_FILE, $exception->getMessage() . PHP_EOL, FILE_APPEND); } break; } }
/** * Static s_display_error */ static function generic_display_error(exception $ex) { $title = $ex->getMessage(); $err_no = $ex->getCode(); if (!class_exists('loader') || class_exists('loader') && !loader::in_ajax()) { header('', true, 500); $message = '<style>* {font: 0.97em verdana;} a {text-decoration:none;background:#EFEFEF;padding:4px;} a:hover{background: red;}</style><h1>Ups! We have an error here.</h1>'; $subject = "Error " . " at " . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $message .= 'Visit <a href="/">index</a> page.<br/><br/>'; echo $message; // if debug if (class_exists('core') && core::is_debug()) { echo '<br/>Error : ' . $title . ' : ' . $err_no; echo '<br/><br/>' . nl2br($ex->getTraceAsString()); } } }
/** * Custom exception handler with backtrace * * @param exception $exception Thrown exception * * @return void */ function exceptionHandler($exception) { global $dPconfig; $time = date("Y-m-d H:i:s"); // User information $user_id = null; $user_view = ""; if (class_exists("CAppUI", false) && CAppUI::$user) { $user = CAppUI::$user; if ($user->_id) { $user_id = $user->_id; $user_view = $user->_view; } } // Server IP $server_ip = isset($_SERVER["SERVER_ADDR"]) ? $_SERVER["SERVER_ADDR"] : null; $file = mbRelativePath($exception->getFile()); $line = $exception->getLine(); $type = "exception"; $text = $exception->getMessage(); // Stacktrace $contexts = $exception->getTrace(); foreach ($contexts as &$ctx) { unset($ctx['args']); } // Might noy be ready at the time error is thrown $session = isset($_SESSION) ? $_SESSION : array(); unset($session['AppUI']); unset($session['dPcompteRendu']['templateManager']); $_all_params = array("GET" => $_GET, "POST" => $_POST, "SESSION" => $session); filterInput($_all_params); // CApp might not be ready yet as of early error handling $request_uid = null; if (class_exists("CApp", false)) { $request_uid = CApp::getRequestUID(); CApp::$performance[CError::$_categories["exception"]]++; } $build_output = ini_get("display_errors"); $save_to_file = false; $data = array("stacktrace" => $contexts, "param_GET" => $_all_params["GET"], "param_POST" => $_all_params["POST"], "session_data" => $_all_params["SESSION"]); if (@$dPconfig["error_logs_in_db"] && class_exists("CErrorLog")) { try { CErrorLog::insert($user_id, $server_ip, $time, $request_uid, $type, $text, $file, $line, $data); } catch (Exception $e) { $build_output = true; $save_to_file = true; } } else { $build_output = true; $save_to_file = true; } if ($build_output) { $hash = md5(serialize($contexts)); $html_class = "big-warning"; $log = "\n\n<div class='{$html_class}' title='{$hash}'>"; if ($user_id) { $log .= "\n<strong>User: </strong>{$user_view} ({$user_id})"; } $file = CError::openInIDE($file, $line); $log .= <<<HTML <strong>Time: </strong>{$time} <strong>Type: </strong>{$type} <strong>Text: </strong>{$text} <strong>File: </strong>{$file} <strong>Line: </strong>{$line} HTML; foreach ($_all_params as $_type => $_params) { $log .= print_infos($_all_params[$_type], $_type); } foreach ($contexts as $context) { $function = isset($context["class"]) ? $context["class"] . ":" : ""; $function .= $context["function"] . "()"; $log .= "\n<strong>Function: </strong> {$function}"; if (isset($context["file"])) { $log .= "\n<strong>File: </strong>" . CError::openInIDE($context["file"], isset($context["line"]) ? $context["line"] : null); } if (isset($context["line"])) { $log .= "\n<strong>Line: </strong>" . $context["line"]; } $log .= "<br />"; } $log .= "</div>"; if ($save_to_file) { file_put_contents(LOG_PATH, $log, FILE_APPEND); } if (ini_get("display_errors")) { echo $log; } } }
/** * Virhelogi * * @param string $message Virheviesti * @param exception $exception Exception * @param string $type Kirjataanko tuote vai tilauslogiin */ public function log($message, $exception = '', $type = 'product') { if (self::LOGGING == true) { $timestamp = date('d.m.y H:i:s'); $message = utf8_encode($message); if ($exception != '') { $message .= " (" . $exception->getMessage() . ") faultcode: " . $exception->faultcode; } $message .= "\n"; $log_location = $type == 'product' ? '/tmp/magento_log.txt' : '/tmp/magento_order_log.txt'; error_log("{$timestamp}: {$message}", 3, $log_location); } }
/** * Sends an errormessage (html) to the user * * @access public * @static * @param exception $exception Instanz of an exception */ public function showError($exception) { /* flush cache */ ob_clean(); ob_start(); /* display html */ ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>phpMedaDB :: Exception</title> <style type="text/css"> <!-- body { font-size:12px; font-family:monospace; } h1 { font-size:18px; color:red; } .phpmediadb-body-exception { background-color:#FFFFCC; border:1px dashed grey; margin-bottom:10px; padding:5px; } .phpmediadb-body-exception-code { background-color:#FAFAFA; border:1px dotted grey; margin:10px; padding:5px; } .phpmediadb-body-exception-copyright { text-align:right; } --> </style> </head> <body> <div class="phpmediadb-body-exception"> <h1>Ouch, got an exception...</h1> Sorry but I was not able to complete your request. Please try again. <?php if (constant('PHPMEDIADB_SYSTEM_DEBUGLEVEL') >= 1) { ?> <br /><br /> <b>Exception Details:</b> <div class="phpmediadb-body-exception-code"><pre><?php echo htmlentities($exception->getMessage()); ?> </pre></div> <?php } ?> </div> <?php if (constant('PHPMEDIADB_SYSTEM_DEBUGLEVEL') >= 2) { ?> <div class="phpmediadb-body-exception"> <h1>Debug</h1> <b>Stack trace:</b><br /> <div class="phpmediadb-body-exception-code"><pre><?php echo htmlentities($exception->getTraceAsString()); ?> </pre></div> <br /> <b>File:</b> <?php echo htmlentities($exception->getFile()); ?> <b>Line:</b> <?php echo htmlentities($exception->getLine()); ?> </div> <?php } ?> <div class="phpmediadb-body-exception-copyright"> phpMediaDB :: The media database<br /> Version <?php echo PHPMEDIADB_SYSTEM_VERSION; ?> </div> </body> </html><?php }
/** * Handles all PHP exceptions. * * @param exception|\exception $exception An exception. * * @note Exceptions handled successfully by this routine will NOT be logged by PHP as errors. * As the exception handler, we will need to log and/or display anything that needs to be recorded here. * The PHP interpreter simply terminates script execution whenever an exception occurs (nothing more). * * @note If an exception is thrown while handling an exception; PHP will revert to it's default exception handler. * This will result in a fatal error that may get logged by PHP itself (depending on `error_reporting` and `error_log`). * * @throws exception|\exception If we are unable to handle the exception (i.e. the XDaRk Core is not even available yet), * this handler will simply re-throw the exception (forcing a fatal error); as just described in the previous note. * * @note The display of exception messages is NOT dependent upon `display_errors`; nor do we consider that setting here. * However, we do tighten security within the `exception.php` template file; hiding most details by default; and displaying all details * only if the current user is a Super Administrator in WordPress; or if `WP_DEBUG_DISPLAY` mode has been enabled on this site. * * @note If there was another exception handler active on the site; and this exception is NOT for * a plugin under this version of the XDaRk Core; we simply hand the exception back to the previous handler. * In the case of multiple versions of the XDaRk Core across various plugins; this allows us to work up the chain * of previous handlers until we find the right version of the XDaRk Core; assuming each version * of the XDaRk Core handles things this way too (which is to be expected). * * @see http://php.net/manual/en/function.set-exception-handler.php */ public static function handle(\exception $exception) { try { static::$exception = $exception; // Reference. if (static::$exception instanceof exception) { static::$plugin = static::$exception->plugin; static::handle_plugin_exception(); return; // We're done here. } // Else this is some other type of exception. if (static::$previous_handler && is_callable(static::$previous_handler)) { call_user_func(static::$previous_handler, static::$exception); return; // We're done here. } // There is NO other handler available (deal w/ it here; if possible). if (is_callable('\\' . stub::$core_ns . '\\core')) { static::$plugin = core(); static::handle_plugin_exception(); return; // We're done here. } throw static::$exception; // Re-throw (forcing a fatal error). } catch (\exception $_exception) { throw new \exception(sprintf(stub::__('Failed to handle exception code: `%1$s` with message: `%2$s`.'), $exception->getCode(), $exception->getMessage()) . ' ' . sprintf(stub::__('Failure caused by exception code: `%1$s` with message: `%2$s`.'), $_exception->getCode(), $_exception->getMessage()), 20, $_exception); } }
/** * Send the error information to the WS client * formatted as an XML document. * * @param exception $ex the exception to send back */ protected function send_error($ex = null) { if ($ex) { $info = $ex->getMessage(); if (debugging() and isset($ex->debuginfo)) { $info .= ' - ' . $ex->debuginfo; } } else { $info = 'Unknown error'; } $xml = '<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Body><SOAP-ENV:Fault> <faultcode>MOODLE:error</faultcode> <faultstring>' . $info . '</faultstring> </SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>'; $this->send_headers(); header('Content-Type: application/xml; charset=utf-8'); header('Content-Disposition: inline; filename="response.xml"'); echo $xml; }
/** * Returns detailed information about specified exception. * @param exception $ex * @return object */ function get_exception_info($ex) { global $CFG, $DB, $SESSION; if ($ex instanceof moodle_exception) { $errorcode = $ex->errorcode; $module = $ex->module; $a = $ex->a; $link = $ex->link; $debuginfo = $ex->debuginfo; } else { $errorcode = 'generalexceptionmessage'; $module = 'error'; $a = $ex->getMessage(); $link = ''; $debuginfo = null; } $backtrace = $ex->getTrace(); $place = array('file'=>$ex->getFile(), 'line'=>$ex->getLine(), 'exception'=>get_class($ex)); array_unshift($backtrace, $place); // Be careful, no guarantee moodlelib.php is loaded. if (empty($module) || $module == 'moodle' || $module == 'core') { $module = 'error'; } if (function_exists('get_string_manager')) { if (get_string_manager()->string_exists($errorcode, $module)) { $message = get_string($errorcode, $module, $a); } elseif ($module == 'error' && get_string_manager()->string_exists($errorcode, 'moodle')) { // Search in moodle file if error specified - needed for backwards compatibility $message = get_string($errorcode, 'moodle', $a); } else { $message = $module . '/' . $errorcode; } } else { $message = $module . '/' . $errorcode; } // Be careful, no guarantee weblib.php is loaded. if (function_exists('clean_text')) { $message = clean_text($message); } else { $message = htmlspecialchars($message); } if (!empty($CFG->errordocroot)) { $errordocroot = $CFG->errordocroot; } else if (!empty($CFG->docroot)) { $errordocroot = $CFG->docroot; } else { $errordocroot = 'http://docs.moodle.org'; } if ($module === 'error') { $modulelink = 'moodle'; } else { $modulelink = $module; } $moreinfourl = $errordocroot . '/en/error/' . $modulelink . '/' . $errorcode; if (empty($link)) { if (!empty($SESSION->fromurl)) { $link = $SESSION->fromurl; unset($SESSION->fromurl); } else { $link = $CFG->wwwroot .'/'; } } $info = new stdClass(); $info->message = $message; $info->errorcode = $errorcode; $info->backtrace = $backtrace; $info->link = $link; $info->moreinfourl = $moreinfourl; $info->a = $a; $info->debuginfo = $debuginfo; return $info; }
public function testRun() { $this->given($pusher = new testedClass(__FILE__), $pusher->setTaggerEngine($taggerEngine = new \mock\mageekguy\atoum\scripts\tagger\engine()), $pusher->setGit($git = new \mock\mageekguy\atoum\cli\commands\git()), $pusher->setErrorWriter($errorWriter = new \mock\mageekguy\atoum\writers\std\err()), $pusher->setInfoWriter($infoWriter = new \mock\mageekguy\atoum\writers\std\out()), $this->calling($infoWriter)->write = $infoWriter)->assert('Pusher should write error if tag file is not readable')->if($this->calling($errorWriter)->write = $errorWriter, $this->function->file_get_contents = false)->then->object($pusher->run())->isIdenticalTo($pusher)->mock($errorWriter)->call('write')->withArguments('Unable to read \'' . $pusher->getTagFile() . '\'')->once()->assert('Pusher should write error if tag file is not writable')->if($this->calling($errorWriter)->write = $errorWriter, $this->function->file_put_contents = false, $this->function->file_get_contents = '0.0.0')->then->object($pusher->run())->isIdenticalTo($pusher)->mock($errorWriter)->call('write')->withArguments('Unable to write in \'' . $pusher->getTagFile() . '\'')->once()->assert('Pusher should tag code and commit it if tag file is writable')->if($this->function->file_put_contents = function ($path, $data) { return strlen($data); }, $this->calling($taggerEngine)->tagVersion->doesNothing(), $this->calling($git)->addAllAndCommit = $git, $this->calling($git)->checkoutAllFiles = $git, $this->calling($git)->createTag = $git, $this->calling($git)->push = $git, $this->calling($git)->forcePush = $git, $this->calling($git)->pushTag = $git, $this->calling($git)->resetHardTo = $git, $this->calling($git)->deleteLocalTag = $git)->then->object($pusher->run())->isIdenticalTo($pusher)->function('file_put_contents')->wasCalledWithArguments($pusher->getTagFile(), '0.0.1')->once()->mock($taggerEngine)->call('tagVersion')->before($this->mock($git)->call('addAllAndCommit')->withArguments('Set version to 0.0.1.')->before($this->mock($git)->call('createTag')->withArguments('0.0.1')->before($this->mock($git)->call('push')->withArguments($pusher->getRemote())->once())->before($this->mock($git)->call('pushTag')->withArguments('0.0.1', $pusher->getRemote())->once())->once())->once())->after($this->mock($taggerEngine)->call('setSrcDirectory')->withArguments($pusher->getWorkingDirectory())->once())->after($this->mock($taggerEngine)->call('setVersion')->withArguments('$Rev:' . ' 0.0.1 $')->once())->once()->call('tagVersion')->before($this->mock($git)->call('addAllAndCommit')->withArguments('Set version to dev-master.')->once())->after($this->mock($taggerEngine)->call('setSrcDirectory')->withArguments($pusher->getWorkingDirectory())->once())->after($this->mock($taggerEngine)->call('setVersion')->withArguments('$Rev:' . ' dev-master $')->once())->once()->if($pusher->tagPatchVersion())->then->object($pusher->run())->isIdenticalTo($pusher)->function('file_put_contents')->wasCalledWithArguments($pusher->getTagFile(), '0.0.1')->twice()->if($pusher->tagMinorVersion())->then->object($pusher->run())->isIdenticalTo($pusher)->function('file_put_contents')->wasCalledWithArguments($pusher->getTagFile(), '0.1.0')->once()->if($pusher->tagMajorVersion())->then->object($pusher->run())->isIdenticalTo($pusher)->function('file_put_contents')->wasCalledWithArguments($pusher->getTagFile(), '1.0.0')->once()->assert('Pusher should write error if pushing tag failed and should try to reset repository')->if($pusher->tagPatchVersion(), $this->calling($git)->pushTag->throw = $exception = new \exception(uniqid()))->then->object($pusher->run())->isIdenticalTo($pusher)->mock($errorWriter)->call('write')->withArguments($exception->getMessage())->once()->mock($git)->call('resetHardTo')->withArguments('HEAD~2')->once()->call('deleteLocalTag')->withArguments('0.0.1')->once()->assert('Pusher should write error if pushing commit failed and should try to reset repository')->if($this->calling($git)->push->throw = $exception = new \exception(uniqid()))->then->object($pusher->run())->isIdenticalTo($pusher)->mock($errorWriter)->call('write')->withArguments($exception->getMessage())->once()->mock($git)->call('resetHardTo')->withArguments('HEAD~2')->once()->call('deleteLocalTag')->withArguments('0.0.1')->once()->assert('Pusher should write error if pushing commit for DEVELOPMENT version failed and should try to reset repository')->if($this->calling($git)->push = $git, $this->calling($git)->addAllAndCommit[2]->throw = $exception = new \exception(uniqid()))->then->object($pusher->run())->isIdenticalTo($pusher)->mock($errorWriter)->call('write')->withArguments($exception->getMessage())->once()->mock($git)->call('resetHardTo')->withArguments('HEAD~1')->once()->assert('Pusher should write error if pushing commit for DEVELOPMENT version failed and should try to reset repository')->if($this->calling($git)->createTag->throw = $exception = new \exception(uniqid()))->then->object($pusher->run())->isIdenticalTo($pusher)->mock($errorWriter)->call('write')->withArguments($exception->getMessage())->once()->mock($git)->call('resetHardTo')->withArguments('HEAD~1')->once()->assert('Pusher should write error if commit failed for STABLE version and should try to reset repository')->if($this->calling($git)->createTag = $git, $this->calling($git)->addAllAndCommit[1]->throw = $exception = new \exception(uniqid()))->then->object($pusher->run())->isIdenticalTo($pusher)->mock($errorWriter)->call('write')->withArguments($exception->getMessage())->after($this->mock($git)->call('addAllAndCommit'))->once()->mock($git)->call('checkoutAllFiles')->after($this->mock($git)->call('addAllAndCommit'))->once()->assert('Pusher should write error if reset failed')->if($this->calling($git)->checkoutAllFiles->throw = $checkoutAllFilesException = new \exception(uniqid()))->then->object($pusher->run())->isIdenticalTo($pusher)->mock($errorWriter)->call('write')->withArguments($checkoutAllFilesException->getMessage())->once(); }
/** * Returns detailed information about specified exception. * @param exception $ex * @return object */ function get_exception_info($ex) { global $CFG, $DB, $SESSION; if ($ex instanceof moodle_exception) { $errorcode = $ex->errorcode; $module = $ex->module; $a = $ex->a; $link = $ex->link; $debuginfo = $ex->debuginfo; } else { $errorcode = 'generalexceptionmessage'; $module = 'error'; $a = $ex->getMessage(); $link = ''; $debuginfo = ''; } // Append the error code to the debug info to make grepping and googling easier $debuginfo .= PHP_EOL . "Error code: {$errorcode}"; $backtrace = $ex->getTrace(); $place = array('file' => $ex->getFile(), 'line' => $ex->getLine(), 'exception' => get_class($ex)); array_unshift($backtrace, $place); // Be careful, no guarantee moodlelib.php is loaded. if (empty($module) || $module == 'moodle' || $module == 'core') { $module = 'error'; } // Search for the $errorcode's associated string // If not found, append the contents of $a to $debuginfo so helpful information isn't lost if (function_exists('get_string_manager')) { if (get_string_manager()->string_exists($errorcode, $module)) { $message = get_string($errorcode, $module, $a); } elseif ($module == 'error' && get_string_manager()->string_exists($errorcode, 'moodle')) { // Search in moodle file if error specified - needed for backwards compatibility $message = get_string($errorcode, 'moodle', $a); } else { $message = $module . '/' . $errorcode; $debuginfo .= PHP_EOL . '$a contents: ' . print_r($a, true); } } else { $message = $module . '/' . $errorcode; $debuginfo .= PHP_EOL . '$a contents: ' . print_r($a, true); } // Remove some absolute paths from message and debugging info. $searches = array(); $replaces = array(); $cfgnames = array('tempdir', 'cachedir', 'localcachedir', 'themedir', 'dataroot', 'dirroot'); foreach ($cfgnames as $cfgname) { if (property_exists($CFG, $cfgname)) { $searches[] = $CFG->{$cfgname}; $replaces[] = "[{$cfgname}]"; } } if (!empty($searches)) { $message = str_replace($searches, $replaces, $message); $debuginfo = str_replace($searches, $replaces, $debuginfo); } // Be careful, no guarantee weblib.php is loaded. if (function_exists('clean_text')) { $message = clean_text($message); } else { $message = htmlspecialchars($message); } if (!empty($CFG->errordocroot)) { $errordoclink = $CFG->errordocroot . '/en/'; } else { $errordoclink = get_docs_url(); } if ($module === 'error') { $modulelink = 'moodle'; } else { $modulelink = $module; } $moreinfourl = $errordoclink . 'error/' . $modulelink . '/' . $errorcode; if (empty($link)) { if (!empty($SESSION->fromurl)) { $link = $SESSION->fromurl; unset($SESSION->fromurl); } else { $link = $CFG->wwwroot . '/'; } } // When printing an error the continue button should never link offsite. // We cannot use clean_param() here as it is not guaranteed that it has been loaded yet. $httpswwwroot = str_replace('http:', 'https:', $CFG->wwwroot); if (stripos($link, $CFG->wwwroot) === 0) { // Internal HTTP, all good. } else { if (!empty($CFG->loginhttps) && stripos($link, $httpswwwroot) === 0) { // Internal HTTPS, all good. } else { // External link spotted! $link = $CFG->wwwroot . '/'; } } $info = new stdClass(); $info->message = $message; $info->errorcode = $errorcode; $info->backtrace = $backtrace; $info->link = $link; $info->moreinfourl = $moreinfourl; $info->a = $a; $info->debuginfo = $debuginfo; return $info; }
/** * Virhelogi * * @param string $message Virheviesti * @param exception|string $exception $exception Exception */ private function log($message, $exception = '') { if (self::LOGGING == true) { $timestamp = date('d.m.y H:i:s'); $message = utf8_encode($message); if ($exception != '') { $message .= " (" . $exception->getMessage() . ") faultcode: " . $exception->faultcode; } $message .= "\n"; error_log("{$timestamp}: {$message}", 3, '/tmp/lumo_log.txt'); } }
/** * Get a single line of text representing the exception: * * Error [ Code ]: Message ~ File [ Line ] * * @param object Exception * @return string */ public static function text(exception $e) { return sprintf('Message: %s ERROR: %s Code:[ %s ] Fiel: %s ~ Line [ %d ]', strip_tags($e->getMessage()), get_class($e), $e->getCode(), $e->getFile(), $e->getLine()); }
/** * Function handle_exceptions * * * @param exception $e * @return void */ function handle_exceptions(exception $e) { global $msg; $trace = $e->getTrace(); file_put_contents(_LOG_PATH_ . 'admin.exception.log', print_r($trace, true), FILE_APPEND); $msg .= $e->getMessage(); return 'logout'; }
/** * Send the error information to the WS client * formatted as XML document. * @param exception $ex * @return void */ protected function send_error($ex = null) { // Zend Soap server fault handling is incomplete compared to XML-RPC :-( // we can not use: echo $this->zend_server->fault($ex); //TODO: send some better response in XML if ($ex) { $info = $ex->getMessage(); if (debugging() and isset($ex->debuginfo)) { $info .= ' - ' . $ex->debuginfo; } } else { $info = 'Unknown error'; } $xml = '<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Body><SOAP-ENV:Fault> <faultcode>MOODLE:error</faultcode> <faultstring>' . $info . '</faultstring> </SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>'; $this->send_headers(); header('Content-Type: application/xml; charset=utf-8'); header('Content-Disposition: inline; filename="response.xml"'); echo $xml; }
/** * adds a exception to the array of displayed exceptions for the view * by default is displayed in the inc_header, but with the custom destination set to true * the exception won't be displayed by default but can be displayed where ever wanted in the tpl * * @param exception $oEr a exception object or just a language local (string) which will be converted into a oxExceptionToDisplay object * @param bool $blFull if true the whole object is add to display (default false) * @param bool $blCustomDestination true if the exception shouldn't be displayed at the default position (default false) * @param string $sCustomDestination defines a name of the view variable containing the messages, overrides Parameter 'CustomError' ("default") * @param string $sActiveController defines a name of the controller, which should handle the error. */ public function addErrorToDisplay($oEr, $blFull = false, $blCustomDestination = false, $sCustomDestination = "", $sActiveController = "") { if ($blCustomDestination && (oxRegistry::getConfig()->getRequestParameter('CustomError') || $sCustomDestination != '')) { // check if the current request wants do display exceptions on its own $sDestination = oxRegistry::getConfig()->getRequestParameter('CustomError'); if ($sCustomDestination != '') { $sDestination = $sCustomDestination; } } else { //default $sDestination = 'default'; } //starting session if not yet started as all exception //messages are stored in session $oSession = $this->getSession(); if (!$oSession->getId() && !$oSession->isHeaderSent()) { $oSession->setForceNewSession(); $oSession->start(); } $aEx = oxRegistry::getSession()->getVariable('Errors'); if ($oEr instanceof oxException) { $oEx = oxNew('oxExceptionToDisplay'); $oEx->setMessage($oEr->getMessage()); $oEx->setExceptionType(get_class($oEr)); if ($oEr instanceof oxSystemComponentException) { $oEx->setMessageArgs($oEr->getComponent()); } $oEx->setValues($oEr->getValues()); $oEx->setStackTrace($oEr->getTraceAsString()); $oEx->setDebug($blFull); $oEr = $oEx; } elseif ($oEr && !$oEr instanceof oxIDisplayError) { // assuming that a string was given $sTmp = $oEr; $oEr = oxNew('oxDisplayError'); $oEr->setMessage($sTmp); } elseif ($oEr instanceof oxIDisplayError) { // take the object } else { $oEr = null; } if ($oEr) { $aEx[$sDestination][] = serialize($oEr); oxRegistry::getSession()->setVariable('Errors', $aEx); if ($sActiveController == '') { $sActiveController = oxRegistry::getConfig()->getRequestParameter('actcontrol'); } if ($sActiveController) { $aControllerErrors[$sDestination] = $sActiveController; oxRegistry::getSession()->setVariable('ErrorController', $aControllerErrors); } } }
/** * Displays an exception in HTML, and exists. Includes the exception * trace in an HTML comment, and a readable error string along with the * exception message. * @param exception $e Exception */ public static function handle_exception($e) { // Display actual trace in HTML comment. There shouldn't be any // security-sensitive information in the trace, so this can be // displayed even on live server (I hope). if (debugging('', DEBUG_DEVELOPER)) { global $CFG; print "<pre class='forumng-stacktrace'>"; print htmlspecialchars(str_replace($CFG->dirroot, '', $e->getTraceAsString())); print "</pre>"; } else { print "<!--\n"; print $e->getTraceAsString(); // Not escaped, I think this is correct... print "\n-->"; } // Make a short version of the trace string for log $minitrace = self::get_minitrace_part($e->getFile(), $e->getLine()); foreach ($e->getTrace() as $entry) { $minitrace .= ' ' . self::get_minitrace_part($entry['file'], $entry['line']); } $minitrace = shorten_text($minitrace, 120, true); $message = shorten_text($e->getMessage(), 120, true); global $FULLME, $USER, $CFG; $url = str_replace($CFG->wwwroot . '/mod/forumng/', '', $FULLME); add_to_log(0, 'forumng', 'error', $url, "{$message} / {$minitrace}", 0, $USER->id); // Error to user with just the message print_error('error_exception', 'forumng', '', $e->getMessage()); }
/** * Returns detailed information about specified exception. * @param exception $ex * @return object */ function get_exception_info($ex) { global $CFG, $DB, $SESSION; if ($ex instanceof moodle_exception) { $errorcode = $ex->errorcode; $module = $ex->module; $a = $ex->a; $link = $ex->link; $debuginfo = $ex->debuginfo; } else { $errorcode = 'generalexceptionmessage'; $module = 'error'; $a = $ex->getMessage(); $link = ''; $debuginfo = ''; } // Append the error code to the debug info to make grepping and googling easier $debuginfo .= PHP_EOL . "Error code: {$errorcode}"; $backtrace = $ex->getTrace(); $place = array('file' => $ex->getFile(), 'line' => $ex->getLine(), 'exception' => get_class($ex)); array_unshift($backtrace, $place); // Be careful, no guarantee moodlelib.php is loaded. if (empty($module) || $module == 'moodle' || $module == 'core') { $module = 'error'; } // Search for the $errorcode's associated string // If not found, append the contents of $a to $debuginfo so helpful information isn't lost if (function_exists('get_string_manager')) { if (get_string_manager()->string_exists($errorcode, $module)) { $message = get_string($errorcode, $module, $a); } elseif ($module == 'error' && get_string_manager()->string_exists($errorcode, 'moodle')) { // Search in moodle file if error specified - needed for backwards compatibility $message = get_string($errorcode, 'moodle', $a); } else { $message = $module . '/' . $errorcode; $debuginfo .= PHP_EOL . '$a contents: ' . print_r($a, true); } } else { $message = $module . '/' . $errorcode; $debuginfo .= PHP_EOL . '$a contents: ' . print_r($a, true); } // Be careful, no guarantee weblib.php is loaded. if (function_exists('clean_text')) { $message = clean_text($message); } else { $message = htmlspecialchars($message); } if (!empty($CFG->errordocroot)) { $errordoclink = $CFG->errordocroot . '/en/'; } else { $errordoclink = get_docs_url(); } if ($module === 'error') { $modulelink = 'moodle'; } else { $modulelink = $module; } $moreinfourl = $errordoclink . 'error/' . $modulelink . '/' . $errorcode; if (empty($link)) { if (!empty($SESSION->fromurl)) { $link = $SESSION->fromurl; unset($SESSION->fromurl); } else { $link = $CFG->wwwroot . '/'; } } // when printing an error the continue button should never link offsite if (stripos($link, $CFG->wwwroot) === false && stripos($link, $CFG->httpswwwroot) === false) { $link = $CFG->wwwroot . '/'; } $info = new stdClass(); $info->message = $message; $info->errorcode = $errorcode; $info->backtrace = $backtrace; $info->link = $link; $info->moreinfourl = $moreinfourl; $info->a = $a; $info->debuginfo = $debuginfo; return $info; }
/** * Handle with exceptions * * @param exception $e */ public function handleException($e) { $msg = ''; $trace = $e->getTrace(); ksort($trace); foreach ($trace as $error) { if (isset($error['function']) && isset($error['file'])) { $msg .= $error['file'] . ' (' . $error['line'] . ') '; if (isset($error['function']) && is_string($error['function'])) { $msg .= (isset($error['class']) ? $error['class'] . $error['type'] : '') . $error['function'] . '()'; } $msg .= '<br />'; } } echo <<<EOT <!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <title>Akami Framework</title> </head> <body> <style> html, body { height: 100%; padding: 0; margin: 0; } body { width: 100%; display: table; background: #16938A; color: #333; font-size: 14px; line-height: 1.825; font-family: "Lucida Grande", Helvetica, Arial, "Microsoft YaHei", FreeSans, Arimo, "Droid Sans","wenquanyi micro hei","Hiragino Sans GB", "Hiragino Sans GB W3", Arial, sans-serif } .box { display: table-cell; vertical-align: middle; } .box .container { background: #fff; width: 500px; margin: 0 auto; padding: 2em; box-shadow: 0 2px 8px rgba(0, 0, 0, .2); -webkit-box-sizing: border-box; box-sizing: border-box; } header { color: #999; display: block; margin-bottom: 1em; } .bold { color: #222; font-weight: bold; } p { color: #222; } .message { color: #777; font-size: 12px; margin-top: 1em; margin-bottom: 0; } </style> <div class="box"> <div class="container"> <header> <span class="bold">Message Reminder</span> - {$e->getMessage()} </header> <p class="file"><span class="bold">Location: </span> {$e->getfile()} <i>({$e->getLine()})</i></p> <p class="message">{$msg}</p> </div> </div> </body> </html> EOT; }