Esempio n. 1
0
 /**
  * @return null|string
  */
 public function getErrorMessage()
 {
     if ($this->error instanceof Error) {
         return $this->error->getMessage();
     }
     return null;
 }
Esempio n. 2
0
 protected function post($mode = "", $id = null, $title = "", $description = "", $media = "")
 {
     //validations
     if ($mode != "delete") {
         if (!(is_numeric($id) && $id > 0)) {
             throw new RestException("99", "ID no es valido");
         }
         if (empty($title)) {
             throw new RestException("99", "Titulo no puede ir vacio");
         }
     } else {
         if (!(is_numeric($id) && $id > 0)) {
             throw new RestException("99", "ID no es valido");
         }
     }
     switch ($mode) {
         case "edit":
             return $this->dp->update($id, $title, $description, $media);
             break;
         case "delete":
             return $this->dp->delete($id);
             break;
         case "add":
             return $this->dp->insert($id, $title, $description, $media);
             break;
     }
     Error::getMessage(304);
 }
Esempio n. 3
0
 public function testBasic()
 {
     $error = new Error('error', 1);
     $this->assertSame('error', (string) $error);
     $this->assertSame('error', $error->getMessage());
     $this->assertSame(1, $error->getCode());
 }
Esempio n. 4
0
 public function testUnknownLine()
 {
     $error = new Error('Some error');
     $this->assertSame(-1, $error->getStartLine());
     $this->assertSame(-1, $error->getEndLine());
     $this->assertSame('Some error on unknown line', $error->getMessage());
 }
Esempio n. 5
0
 /**
  * Wraps the passed Error class
  *
  * @param Error $error the Error object
  */
 public function __construct($error)
 {
     $this->_error = $error;
     $message = $error->getMessage();
     $code = $error->getCode();
     parent::__construct(sprintf('(%s) - %s', get_class($error), $message), $code);
 }
Esempio n. 6
0
 private function formatErrorMessage(Error $e, $code)
 {
     if ($e->hasColumnInfo()) {
         return $e->getMessageWithColumnInfo($code);
     } else {
         return $e->getMessage();
     }
 }
Esempio n. 7
0
 private function formatErrorMessage(Error $e, $code)
 {
     if ($e->hasColumnInfo()) {
         return $e->getRawMessage() . ' from ' . $e->getStartLine() . ':' . $e->getStartColumn($code) . ' to ' . $e->getEndLine() . ':' . $e->getEndColumn($code);
     } else {
         return $e->getMessage();
     }
 }
 /**
  * 
  * @param \webignition\CssValidatorOutput\Message\Error $error
  * @return \webignition\CssValidatorOutput\Message\Warning
  */
 public static function fromError(Error $error)
 {
     $warning = new Warning();
     $warning->setContext($error->getContext());
     $warning->setLineNumber($error->getLineNumber());
     $warning->setMessage($error->getMessage());
     $warning->setRef($error->getRef());
     return $warning;
 }
Esempio n. 9
0
/**
 * @param Exception | Error $e
 */
function handleException($e)
{
    $request = \OC::$server->getRequest();
    // in case the request content type is text/xml - we assume it's a WebDAV request
    $isXmlContentType = strpos($request->getHeader('Content-Type'), 'text/xml');
    if ($isXmlContentType === 0) {
        // fire up a simple server to properly process the exception
        $server = new Server();
        if (!$e instanceof RemoteException) {
            // we shall not log on RemoteException
            $server->addPlugin(new ExceptionLoggerPlugin('webdav', \OC::$server->getLogger()));
        }
        $server->on('beforeMethod', function () use($e) {
            if ($e instanceof RemoteException) {
                switch ($e->getCode()) {
                    case OC_Response::STATUS_SERVICE_UNAVAILABLE:
                        throw new ServiceUnavailable($e->getMessage());
                    case OC_Response::STATUS_NOT_FOUND:
                        throw new \Sabre\DAV\Exception\NotFound($e->getMessage());
                }
            }
            $class = get_class($e);
            $msg = $e->getMessage();
            throw new ServiceUnavailable("{$class}: {$msg}");
        });
        $server->exec();
    } else {
        $statusCode = OC_Response::STATUS_INTERNAL_SERVER_ERROR;
        if ($e instanceof \OC\ServiceUnavailableException) {
            $statusCode = OC_Response::STATUS_SERVICE_UNAVAILABLE;
        }
        if ($e instanceof RemoteException) {
            // we shall not log on RemoteException
            OC_Response::setStatus($e->getCode());
            OC_Template::printErrorPage($e->getMessage());
        } else {
            \OC::$server->getLogger()->logException($e, ['app' => 'remote']);
            OC_Response::setStatus($statusCode);
            OC_Template::printExceptionErrorPage($e);
        }
    }
}
Esempio n. 10
0
 public function test()
 {
     $error = new Error(E_ERROR, 'message', 'file', 0);
     $this->assertSame(E_ERROR, $error->getSeverity());
     $this->assertSame('message', $error->getMessage());
     $this->assertSame('Fatal error', $error->getSeverityAsString());
     $this->assertSame('E_ERROR', $error->getSeverityAsConstantName());
     $this->assertSame('file', $error->getFile());
     $this->assertSame(0, $error->getLine());
     $this->assertSame('Fatal error:  message in file on line 0', (string) $error);
 }
Esempio n. 11
0
 /**
  * Set error response
  * @param \Sonic\Controller\Error|integer|string $message Error message object, error code or message string
  * @param integer $code Error code, only used if message is a string
  * @param integer $httpCode HTTP status code
  * @return FALSE
  */
 protected function error($message = 'invalid request', $code = 0, $httpCode = 0)
 {
     if (is_numeric($message)) {
         $error = new Error($message);
         $code = $error->getCode();
         $message = $error->getMessage();
     } else {
         if ($message instanceof Error) {
             $code = $message->getCode();
             $message = $message->getMessage();
         }
     }
     $this->view->response = array('success' => 0, 'error_code' => $code, 'error_description' => $message);
     if ($httpCode) {
         $this->httpStatus($httpCode);
     }
     return FALSE;
 }
 /**
  * log error to configured log facility
  *
  * @param Error $error the error
  *
  * @return bool
  *
  * @todo finish!
  */
 protected function logError($error)
 {
     return error_log($error->getMessage());
 }
 public function __construct(Error $error)
 {
     parent::__construct($error->getMessage() ? $error->getMessage() : '');
     $this->error = $error;
 }
Esempio n. 14
0
 public function testValidMessage()
 {
     $errorMessage = 'This is an error message';
     $error = new Error($errorMessage);
     $this->assertEquals($errorMessage, $error->getMessage());
 }
Esempio n. 15
0
 public function testGetMessage()
 {
     $this->assertEquals('error_message', $this->error->getMessage());
 }
Esempio n. 16
0
 /** 
  * Retorna el valor string correspondiente al atributo texto del error
  * @return   string
  */
 function getMessage()
 {
     return Error::getMessage();
 }
Esempio n. 17
0
			width: 360px;
			background-color: #E5ECF9;
			padding: 5px;
			border: 1px solid #C5D7EF;
			color: #3366FF;
		}
	</style>
</head>

<body>

	<div align="center">
		<div class="box">
			<h1>DB Error!</h1>
			<h3><?php 
echo Error::getMessage();
?>
</h3>

			<?php 
$params = Error::getParams();
$dbMsg = $params['errorMessage'];
$dbQuery = $params['query'];
$dbTrace = $params['trace'];
$dbValues = $params['queryValues'];
?>
			<p><b>Failure:</b> <?php 
echo $dbMsg;
?>
</p>
			<p><b>Trace:</b><br/><PRE><?php 
Esempio n. 18
0
 public function testUnknownLine()
 {
     $error = new Error('Some error');
     $this->assertEquals(-1, $error->getRawLine());
     $this->assertEquals('Some error on unknown line', $error->getMessage());
 }
Esempio n. 19
0
 /**
  * @group disconnected
  */
 public function testErrorMessage()
 {
     $error = new Error(self::ERR_WRONG_KEY_TYPE);
     $this->assertEquals(self::ERR_WRONG_KEY_TYPE, $error->getMessage());
 }
Esempio n. 20
0
 protected function FormatErrorMessage(Error $Error)
 {
     return $Error->getTimestamp() . ' [' . $Error->getCode() . '] "' . $Error->getMessage() . '" in file: ' . $Error->getFilepath() . ', line: ' . $Error->getLine() . PHP_EOL . $Error->getRequest();
 }
Esempio n. 21
0
 /**
  * Main function for uploading data
  */
 public function uploadData()
 {
     $request = \Bitrix\Main\Context::getCurrent()->getRequest();
     $post = array_merge($request->getQueryList()->toArray(), $request->getPostList()->toArray());
     $error = "";
     $post = self::__UnEscape($post);
     $status = null;
     if ($this->getPost("type") != "brief") {
         $eventName = $this->log->getValue("executed") == false ? "onUploadIsStarted" : "onUploadIsContinued";
         $this->log->setValue("executed", true);
         $logData = $this->log->getValues();
         $packData = $this->packLog->getValues();
         foreach (GetModuleEvents(self::EVENT_NAME, $eventName, true) as $arEvent) {
             if (ExecuteModuleEventEx($arEvent, array(&$packData, &$logData, &$post, &$_FILES, &$error)) === false) {
                 $status = new Error("BXU350.1", $error);
                 break;
             }
         }
         if ($status === null) {
             $eventName = $this->packLog->getValue("executed") == false ? "onPackageIsContinued" : "onPackageIsStarted";
             $this->packLog->setValue("executed", true);
             foreach (GetModuleEvents(self::EVENT_NAME, $eventName, true) as $arEvent) {
                 if (ExecuteModuleEventEx($arEvent, array(&$packData, &$logData, &$post, &$_FILES, &$error)) === false) {
                     $status = new Error("BXU350.1", $error);
                     break;
                 }
             }
         }
         $this->log->setValues($logData);
         $this->packLog->setValues($packData);
     }
     if ($status === null) {
         $data = array();
         if (!empty($post[self::FILE_NAME])) {
             foreach ($post[self::FILE_NAME] as $fileID => $props) {
                 $hash = $this->getHash(array("id" => $fileID, "name" => $props["name"]));
                 $data[$fileID] = array_merge($props, array("status" => "inprogress", "hash" => $hash, "id" => $fileID, "files" => array()));
                 if (FileInputUtility::instance()->checkFile($this->CID, $hash)) {
                     $data[$fileID] = self::merge($data[$fileID], $this->getFromCache($data[$fileID]["hash"]));
                     if ($props["restored"] == "Y") {
                         $data[$fileID]["status"] = "inprogress";
                     }
                 }
             }
         }
         /*@var $files array*/
         $files = $this->getUploadedFiles($data);
         $logData = $this->log->getValues();
         $packData = $this->packLog->getValues();
         foreach ($data as $fileID => $file) {
             if (!$this->checkTime()) {
                 break;
             }
             $result = new Status($file["status"]);
             if ($result->getStatus() == "inprogress") {
                 unset($file["restored"]);
                 unset($file["executed"]);
                 if (array_key_exists($fileID, $files)) {
                     FileInputUtility::instance()->registerFile($this->CID, $file["hash"]);
                     foreach ($files[$fileID] as $f) {
                         $res = $this->checkFile($f, $file);
                         if ($res instanceof Error) {
                             $result = $res;
                             break;
                         }
                     }
                 }
                 if ($result->getStatus() == "inprogress") {
                     $result = $this->saveFile($file);
                 }
             }
             if (array_key_exists("restored", $file) && array_key_exists("executed", $file) && array_key_exists("~status", $file)) {
                 unset($file["restored"]);
                 unset($file["executed"]);
                 $result = new Status($file["~status"]);
             }
             $file["~status"] = $result->getStatus();
             if ($result->getStatus() == "uploaded" && $this->getPost("type") != "brief" && !array_key_exists("executed", $file)) {
                 $packData1 = $packData;
                 $logData1 = $logData;
                 $file["executed"] = "Y";
                 foreach (GetModuleEvents(self::EVENT_NAME, "onFileIsUploaded", true) as $arEvent) {
                     $error = "";
                     if (!ExecuteModuleEventEx($arEvent, array($file["hash"], &$file, &$packData, &$logData, &$error))) {
                         $result = new Error("BXU350.1", $error);
                         $file["executed"] = "error";
                         break;
                     }
                 }
                 if ($logData1 != $logData) {
                     $this->log->setValues($logData);
                 }
                 if ($packData1 != $packData) {
                     $this->packLog->setValues($packData);
                 }
             }
             $file["status"] = $result->getStatus();
             $this->setIntoCache($file["hash"], $file);
             // it is a compatibility
             $log = array("status" => $file["status"], "hash" => $file["hash"]);
             if ($result instanceof Error) {
                 $log += array("error" => $result->getMessage(), "errorCode" => $result->getCode());
                 if (empty($log["error"])) {
                     $log["error"] = "Unknown error.";
                 }
                 //					trigger_error("Uploading error: ".$file["name"]." wasn't uploaded: ".$log["error"]." [".$log["errorCode"]."]", E_USER_WARNING);
             }
             $this->files[$fileID] = $log + array("file" => $file);
             if ($file["status"] == "uploaded" || $file["status"] == "error") {
                 $this->packLog->setValue("files", array($file["id"] => $file["status"]));
             }
         }
         $declaredFiles = (int) $this->packLog->getValue("filesCount");
         if ($declaredFiles > 0 && $declaredFiles == count($this->packLog->getValue("files"))) {
             $status = new Status("done");
             if ($this->getPost("type") !== "brief") {
                 foreach (GetModuleEvents(self::EVENT_NAME, "onPackageIsFinished", true) as $arEvent) {
                     if (ExecuteModuleEventEx($arEvent, array($packData, $logData, $post, $this->files)) === false) {
                         $status = new Error("BXU350.1", $error);
                         break;
                     }
                 }
             }
         } else {
             $status = new Status("inprogress");
         }
         if ($this->getPost("type") == "brief" || $status->getStatus() == "inprogress") {
             $this->log->setValues($logData);
             $this->packLog->setValues($packData);
         } else {
             $this->packLog->unlink();
         }
     }
     $this->status = $status->getStatus();
     return $status;
 }
 public function testGetters()
 {
     $error = new Error(123, 'foo');
     $this->assertEquals(123, $error->getCode());
     $this->assertEquals('foo', $error->getMessage());
 }
Esempio n. 23
0
 /**
  * Message as two immutable members code and message that can only be
  * set in the constructor
  *
  * @return null
  */
 public function testGetCodeMessageSql()
 {
     $this->assertEquals($this->errCode, $this->error->getCode());
     $this->assertEquals($this->errText, $this->error->getMessage());
     $this->assertEquals($this->sqlState, $this->error->getSqlState());
 }
Esempio n. 24
0
 /**
  * New exception.
  *
  * @param Exception $exception        	
  * @param boolean $printError
  *        	show error or not
  * @param boolean $clear
  *        	clear the errorlog
  * @param string $errorFile
  *        	file to save to
  */
 public static function newMessage(\Error $exception)
 {
     $message = $exception->getMessage();
     $code = $exception->getCode();
     $file = $exception->getFile();
     $line = $exception->getLine();
     $trace = $exception->getTraceAsString();
     $trace = str_replace(DB_PASS, '********', $trace);
     $date = date('M d, Y G:iA');
     $logMessage = "<h3>Exception information:</h3>\n\n           <p><strong>Date:</strong> {$date}</p>\n\n           <p><strong>Message:</strong> {$message}</p>\n\n           <p><strong>Code:</strong> {$code}</p>\n\n           <p><strong>File:</strong> {$file}</p>\n\n           <p><strong>Line:</strong> {$line}</p>\n\n           <h3>Stack trace:</h3>\n\n           <pre>{$trace}</pre>\n\n           <hr />\n";
     $errorFile = self::getCurrentErrorLog();
     if (is_file($errorFile) === false) {
         file_put_contents($errorFile, '');
     }
     if (self::$clear) {
         $f = fopen($errorFile, "r+");
         if ($f !== false) {
             ftruncate($f, 0);
             fclose($f);
         }
         $content = null;
     } else {
         $content = file_get_contents($errorFile);
     }
     file_put_contents($errorFile, $logMessage . $content);
     if (self::$printError == true) {
         echo $logMessage;
         exit;
     }
 }
Esempio n. 25
0
 public function testGetMessage()
 {
     $error = new Error(42, 'Unknown error');
     $this->assertEquals('Unknown error', $error->getMessage());
 }
Esempio n. 26
0
		 font-weight: bold;
		}
		
		.box{
			width: 360px;
			background-color: #E5ECF9;
			padding: 5px;
			border: 1px solid #C5D7EF;
			color: #3366FF;
		}
	</style>
</head>

<body>

	<div align="center">
		<div class="box">
			<h1>404 Error!</h1>
			<p>The page you were looking for does not exist.</p>
			<?php 
echo "<h3>Caught exception: " . Error::getMessage() . "</h3>";
echo "<p><PRE>";
print_r(Error::getTrace());
echo "</PRE></p>";
?>
		</div>
	</div>

</body>
</html>
Esempio n. 27
0
 /**
  * @param Error $error
  * @return array
  */
 public static function formatError(Error $error)
 {
     return FormattedError::create($error->getMessage(), $error->getLocations());
 }
Esempio n. 28
0
 /**
  * Return throwable data in array format.
  *
  * @param \Error|\Exception $ex
  * @param int $offset
  * @return string[]
  */
 public static function getThrowableData($ex, $offset = 0)
 {
     return ['message' => $ex->getMessage(), 'class' => get_class($ex), 'file' => $ex->getFile(), 'line' => $ex->getLine(), 'code' => $ex->getCode(), 'trace' => static::getTraceElements($ex, $offset), 'isError' => $ex instanceof \Error, 'prev' => null];
 }