Example #1
0
 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);
 }
Example #2
0
 public function __construct($message, $engmessage, $data = NULL)
 {
     parent::__construct($message);
     if (!is_null($data)) {
         $this->data = $data;
     }
 }
Example #3
0
	public function __construct ($message = null, $code = 0)
	{
		parent::__construct($message, $code);
		$this->stage  = coren::current_stage ();
		$this->module = coren::current_module();
		$this->method = coren::current_method();
	}
Example #4
0
 /**
  * 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());
         }
     }
 }
Example #5
0
 /**
  * Constructor
  */
 public function __construct($code, $string, $file, $line, $context)
 {
     parent::__construct($string, $code);
     die($string);
     // override line and file to match error
     $this->line = $line;
     $this->file = $file;
     // save context, in an extended propertie
     $this->context = $context;
 }
 public function __construct($errno, $errstr, $file, $line)
 {
     switch ($errno) {
         case E_ERROR:
             $str_type = 'E_ERROR';
             break;
         case E_WARNING:
             $str_type = 'E_WARNING';
             break;
         case E_PARSE:
             $str_type = 'E_PARSE';
             break;
         case E_NOTICE:
             $str_type = 'E_NOTICE';
             break;
         case E_CORE_ERROR:
             $str_type = 'E_CORE_ERROR';
             break;
         case E_CORE_WARNING:
             $str_type = 'E_CORE_WARNING';
             break;
         case E_COMPILE_ERROR:
             $str_type = 'E_COMPILE_ERROR';
             break;
         case E_COMPILE_WARNING:
             $str_type = 'E_COMPILE_WARNING';
             break;
         case E_USER_ERROR:
             $str_type = 'E_USER_ERROR';
             break;
         case E_USER_WARNING:
             $str_type = 'E_USER_WARNING';
             break;
         case E_USER_NOTICE:
             $str_type = 'E_USER_NOTICE';
             break;
         case E_STRICT:
             $str_type = 'E_STRICT';
             break;
         default:
             $str_type = sprintf('E_%d', $errno);
             break;
     }
     $message = sprintf('%s: %s at [%s:%d]', $str_type, $errstr, $file, $line);
     parent::__construct($message, $errno);
     $this->php_error_code = $errno;
     $this->php_error_code_str = $str_type;
     $this->php_error_message = $errstr;
     $this->php_error_file = $file;
     $this->php_error_line = $line;
 }
 /**
  * 文件导入
  */
 public static function import($className, $type)
 {
     static $_file = array();
     //特殊字符转换
     $type = strtolower($type);
     if (isset($_file[$className])) {
         return true;
     }
     //判断文件类型 1=>action 2=>model -1=>其他文件
     $filetype = $type == 'action' ? 1 : ($type == 'model' ? 2 : -1);
     $flag = false;
     if ($filetype == 1) {
         $flag = self::importAction($className);
     } else {
         if ($filetype == 2) {
             $flag = self::importModel($className);
         } else {
             $flag = self::importOther($className);
         }
     }
     if (!$flag) {
         exception::halt(FILE_NOTFOUND, '文件:' . $className . '未找到');
     }
 }
Example #8
0
File: Error.php Project: xn1224/YOF
 /** 
  * 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;
     }
 }
Example #9
0
 private function addExceptionToScore(\exception $exception)
 {
     list($file, $line) = $this->getBacktrace($exception->getTrace());
     $this->score->addException($file, $this->class, $this->currentMethod, $line, $exception);
     return $this;
 }
Example #10
0
 /**
  * Converts a Stripe exception into an error message.
  *
  * @param exception $exception
  *
  * @return string Error message.
  */
 public static function error_message($exception)
 {
     if ($exception instanceof Stripe_CardError) {
         $body = $exception->getJsonBody();
         $error = $body['error'];
         return sprintf(_x('Error code: <code>%1$s</code>. %2$s.', 's2member-front', 's2member'), esc_html(trim($error['code'], '.')), esc_html(trim($error['message'], '.')));
     }
     if ($exception instanceof Stripe_InvalidRequestError) {
         return _x('Invalid parameters to Stripe; please contact the site owner.', 's2member-front', 's2member');
     }
     if ($exception instanceof Stripe_AuthenticationError) {
         return _x('Invalid Stripe API keys; please contact the site owner.', 's2member-front', 's2member');
     }
     if ($exception instanceof Stripe_ApiConnectionError) {
         return _x('Network communication failure with Stripe; please try again.', 's2member-front', 's2member');
     }
     if ($exception instanceof Stripe_Error) {
         return _x('Stripe API error; please try again.', 's2member-front', 's2member');
     }
     return _x('Stripe error; please try again.', 's2member-front', 's2member');
 }
Example #11
0
 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();
 }
    /**
     * 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;
    }
 /**
  * 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());
 }
Example #14
0
 /**
  * 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);
     }
 }
 /**
  * generer une erreur HTML2PDF
  * 
  * @param	int		numero de l'erreur
  * @param	mixed	indications suplementaires sur l'erreur
  * @return	string	code HTML eventuel associé à l'erreur
  */
 public final function __construct($err = 0, $other = null, $html = '')
 {
     // creation du message d'erreur
     $msg = '';
     switch ($err) {
         case 1:
             $msg = HTML2PDF::textGET('err01');
             $msg = str_replace('[[OTHER]]', $other, $msg);
             $this->tag = $other;
             break;
         case 2:
             $msg = HTML2PDF::textGET('err02');
             $msg = str_replace('[[OTHER_0]]', $other[0], $msg);
             $msg = str_replace('[[OTHER_1]]', $other[1], $msg);
             $msg = str_replace('[[OTHER_2]]', $other[2], $msg);
             break;
         case 3:
             $msg = HTML2PDF::textGET('err03');
             $msg = str_replace('[[OTHER]]', $other, $msg);
             $this->tag = $other;
             break;
         case 4:
             $msg = HTML2PDF::textGET('err04');
             $msg = str_replace('[[OTHER]]', print_r($other, true), $msg);
             break;
         case 5:
             $msg = HTML2PDF::textGET('err05');
             $msg = str_replace('[[OTHER]]', print_r($other, true), $msg);
             break;
         case 6:
             $msg = HTML2PDF::textGET('err06');
             $msg = str_replace('[[OTHER]]', $other, $msg);
             $this->image = $other;
             break;
         case 7:
             $msg = HTML2PDF::textGET('err07');
             break;
         case 8:
             $msg = HTML2PDF::textGET('err08');
             $msg = str_replace('[[OTHER]]', $other, $msg);
             $this->tag = $other;
             break;
         case 9:
             $msg = HTML2PDF::textGET('err09');
             $msg = str_replace('[[OTHER_0]]', $other[0], $msg);
             $msg = str_replace('[[OTHER_1]]', $other[1], $msg);
             $this->tag = $other[0];
             break;
     }
     // creation du message HTML
     $this->message_html = '<span style="color: #AA0000; font-weight: bold;">' . HTML2PDF::textGET('txt01') . $err . '</span><br>';
     $this->message_html .= HTML2PDF::textGET('txt02') . ' ' . $this->file . '<br>';
     $this->message_html .= HTML2PDF::textGET('txt03') . ' ' . $this->line . '<br>';
     $this->message_html .= '<br>';
     $this->message_html .= $msg;
     // creation du message classique
     $msg = HTML2PDF::textGET('txt01') . $err . ' : ' . strip_tags($msg);
     if ($html) {
         $this->message_html .= "<br><br>HTML : ..." . trim(htmlentities($html)) . '...';
         $this->html = $html;
         $msg .= ' HTML : ...' . trim($html) . '...';
     }
     parent::__construct($msg, $err);
 }
 function __construct($message)
 {
     parent::__construct($message);
 }
Example #17
0
 /**
  * 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());
 }
 public function __construct($message = null, $code = 0, $data = null, Exception $previous = null)
 {
     $this->data = (array) $data;
     parent::__construct($message, $code, $previous);
 }
Example #19
0
 /**
  * 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);
         }
     }
 }
Example #20
0
/**
 * 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';
}
Example #21
0
    /**
     * 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;
    }
Example #22
0
 public function __construct($msg)
 {
     parent::__construct($msg);
 }
Example #23
0
 /**
  * generate a HTML2PDF exception
  *
  * @param    int $err error number
  * @param    mixed $other additionnal informations
  * @return   string  $html optionnal code HTML associated to the error
  */
 public final function __construct($err = 0, $other = null, $html = '')
 {
     // read the error
     switch ($err) {
         case 1:
             // Unsupported tag
             $msg = HTML2PDF_locale::get('err01');
             $msg = str_replace('[[OTHER]]', $other, $msg);
             $this->_tag = $other;
             break;
         case 2:
             // too long sentence
             $msg = HTML2PDF_locale::get('err02');
             $msg = str_replace('[[OTHER_0]]', $other[0], $msg);
             $msg = str_replace('[[OTHER_1]]', $other[1], $msg);
             $msg = str_replace('[[OTHER_2]]', $other[2], $msg);
             break;
         case 3:
             // closing tag in excess
             $msg = HTML2PDF_locale::get('err03');
             $msg = str_replace('[[OTHER]]', $other, $msg);
             $this->_tag = $other;
             break;
         case 4:
             // tags closed in the wrong order
             $msg = HTML2PDF_locale::get('err04');
             $msg = str_replace('[[OTHER]]', print_r($other, true), $msg);
             break;
         case 5:
             // unclosed tag
             $msg = HTML2PDF_locale::get('err05');
             $msg = str_replace('[[OTHER]]', print_r($other, true), $msg);
             break;
         case 6:
             // image can not be loaded
             $msg = HTML2PDF_locale::get('err06');
             $msg = str_replace('[[OTHER]]', $other, $msg);
             $this->_image = $other;
             break;
         case 7:
             // too big TD content
             $msg = HTML2PDF_locale::get('err07');
             break;
         case 8:
             // SVG tag not in DRAW tag
             $msg = HTML2PDF_locale::get('err08');
             $msg = str_replace('[[OTHER]]', $other, $msg);
             $this->_tag = $other;
             break;
         case 9:
             // deprecated
             $msg = HTML2PDF_locale::get('err09');
             $msg = str_replace('[[OTHER_0]]', $other[0], $msg);
             $msg = str_replace('[[OTHER_1]]', $other[1], $msg);
             $this->_tag = $other[0];
             break;
         case 0:
             // specific error
         // specific error
         default:
             $msg = $other;
             break;
     }
     // create the HTML message
     $this->_messageHtml = '<span style="color: #AA0000; font-weight: bold;">' . HTML2PDF_locale::get('txt01', 'error: ') . $err . '</span><br>';
     $this->_messageHtml .= HTML2PDF_locale::get('txt02', 'file:') . ' ' . $this->file . '<br>';
     $this->_messageHtml .= HTML2PDF_locale::get('txt03', 'line:') . ' ' . $this->line . '<br>';
     $this->_messageHtml .= '<br>';
     $this->_messageHtml .= $msg;
     // create the text message
     $msg = HTML2PDF_locale::get('txt01', 'error: ') . $err . ' : ' . strip_tags($msg);
     // add the optionnal html content
     if ($html) {
         $this->_messageHtml .= "<br><br>HTML : ..." . trim(htmlentities($html)) . '...';
         $this->_html = $html;
         $msg .= ' HTML : ...' . trim($html) . '...';
     }
     // save the other informations
     $this->_other = $other;
     // construct the exception
     parent::__construct($msg, $err);
 }
Example #24
0
/**
 * 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;
        }
    }
}
    /**
     * 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 
    }
Example #26
0
/**
 * 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;
}
Example #27
0
/**
 * 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;
}
Example #28
0
 public function __construct(_Extruct_SpecError $oError)
 {
     //
     // Takes a _Extruct_SpecError instance as its only parameter.
     // Not to be used externally.
     //
     $this->Stack = $oError->Stack;
     parent::__construct($oError->getMessage() . " (" . implode('/', $this->Stack));
 }
Example #29
0
/**
 * 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;
}
Example #30
0
 /**
  * Constructor
  * @param	string	$message [optional default null] : A message to display to user (will be translated if needed). Null for default message
  * @param	string	$title [optional default null'] : Title of the error box to display (will be translated if needed). Null for default title
  */
 public function __construct($message = null, $title = null)
 {
     // set the display param
     $this->display = array('message' => $message, 'title' => $title);
     parent::__construct($message);
 }