Commit 14ed99fc authored by Carsten  Rose's avatar Carsten Rose
Browse files

B6880. Fixed Exceptions with too many details to end user. fixes #6880

parent df216920
Pipeline #941 passed with stage
in 1 minute and 49 seconds
......@@ -223,7 +223,6 @@ Setup CSS & JS
# Only needed in case FormElement 'annotate' is used.
file20 = typo3conf/ext/qfq/Resources/Public/JavaScript/fabric.min.js
file21 = typo3conf/ext/qfq/Resources/Public/JavaScript/qfq.fabric.min.js
}
......
......@@ -260,7 +260,11 @@ abstract class AbstractBuildForm {
} else {
$recordId = $this->store->getVar(SIP_RECORD_ID, STORE_SIP);
if (!($recordId == '' || is_numeric($recordId))) {
throw new UserFormException('Invalid record ID: r="' . $recordId, '"', ERROR_INVALID_VALUE);
throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'Invalid record ID', ERROR_MESSAGE_SUPPORT => 'Invalid record ID: r="' . $recordId]),
ERROR_INVALID_VALUE);
}
$htmlElements = $this->elements($recordId, $filter, 0, $json, $modeCollectFe, $htmlElementNameIdZero, $storeUse, $mode);
......@@ -1392,7 +1396,10 @@ abstract class AbstractBuildForm {
}
if (false === stristr(substr($sqlTest, 0, 7), 'SELECT ')) {
throw new UserFormException("Expect a SELECT statement in " . FE_TYPEAHEAD_SQL . " - got: " . $sqlTest, ERROR_BROKEN_PARAMETER);
throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => '"Expect a SELECT statement', ERROR_MESSAGE_SUPPORT => "Expect a SELECT statement in " . FE_TYPEAHEAD_SQL . " - got: " . $sqlTest]),
ERROR_BROKEN_PARAMETER);
}
if (false === stristr($sql, ' LIMIT ')) {
......
......@@ -42,9 +42,11 @@ class BodytextParser {
$bodytext = Support::decryptDoubleCurlyBraces($bodytext);
if (strpos($bodytext, NESTING_TOKEN_OPEN) !== false) {
throw new UserFormException("Missing close delimiter: $bodytext", ERROR_MISSING_CLOSE_DELIMITER);
throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'Report: Missing close delimiter', ERROR_MESSAGE_SUPPORT => $bodytext]), ERROR_MISSING_CLOSE_DELIMITER);
}
return $bodytext;
}
......@@ -279,7 +281,10 @@ class BodytextParser {
if ($posMatchOpen === false) {
$result = $this->decryptNestingDelimeter($result, $nestingOpen, $nestingClose);
throw new UserFormException("Missing open delimiter: $result", ERROR_MISSING_OPEN_DELIMITER);
throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'Missing open delimiter', ERROR_MESSAGE_SUPPORT => "Missing open delimiter: $result"]),
ERROR_MISSING_OPEN_DELIMITER);
}
$pre = substr($result, 0, $posMatchOpen);
......
......@@ -71,7 +71,10 @@ class Delete {
$cwd = getcwd();
$sitePath = $this->store->getVar(SYSTEM_SITE_PATH, STORE_SYSTEM);
if ($cwd === false || $sitePath === false || !chdir($sitePath)) {
throw new UserFormException("getcwd() failed or SITE_PATH undefined or chdir('$sitePath') failed.", ERROR_IO_CHDIR);
throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'getcwd() failed or SITE_PATH undefined or chdir() failed', ERROR_MESSAGE_SUPPORT => "getcwd() failed or SITE_PATH undefined or chdir('$sitePath') failed."]),
ERROR_IO_CHDIR);
}
// Read record first.
......@@ -82,7 +85,10 @@ class Delete {
$this->db->sql("DELETE FROM $tableName WHERE $primaryKey =? LIMIT 1", ROW_REGULAR, [$recordId]);
} else {
throw new UserFormException("Record $recordId not found in table '$tableName'.", ERROR_RECORD_NOT_FOUND);
throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'Record not found in table', ERROR_MESSAGE_SUPPORT => "Record $recordId not found in table '$tableName'."]),
ERROR_RECORD_NOT_FOUND);
}
chdir($cwd);
......@@ -119,7 +125,9 @@ class Delete {
$samePathFileName = $this->db->sql("SELECT COUNT($primaryKey) AS cnt FROM $tableName WHERE $key LIKE ?", ROW_EXPECT_1, [$file]);
if ($samePathFileName['cnt'] === 1) {
if (!unlink($file)) {
throw new UserFormException("Error deleting file: $file", ERROR_IO_UNLINK);
throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'Error deleting file', ERROR_MESSAGE_SUPPORT => "Error deleting file: $file"]),
ERROR_IO_UNLINK);
}
}
}
......
......@@ -127,7 +127,9 @@ class Evaluate {
$flagTokenReplaced = false;
if ($recursion > 4) {
throw new qfq\UserFormException("Recursion too deep ($recursion). Line: $line", ERROR_RECURSION_TOO_DEEP);
throw new qfq\UserFormException(json_encode([ERROR_MESSAGE_TO_USER => 'Recursion too deep', ERROR_MESSAGE_SUPPORT => "Recursion too deep ($recursion). Line: $line"]),
ERROR_RECURSION_TOO_DEEP);
}
$result = $line;
......@@ -143,7 +145,9 @@ class Evaluate {
$posMatchOpen = strrpos(substr($result, 0, $posFirstClose), $this->startDelimiter);
if ($posMatchOpen === false) {
throw new UserFormException("Missing open delimiter: $result", ERROR_MISSING_OPEN_DELIMITER);
throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'Missing open delimiter', ERROR_MESSAGE_SUPPORT => "Missing open delimiter: $result"]),
ERROR_MISSING_OPEN_DELIMITER);
}
$pre = substr($result, 0, $posMatchOpen);
......
......@@ -123,7 +123,9 @@ class File {
$statusUpload = array_merge($statusUpload, $newArr);
if ($statusUpload[FILES_ERROR] !== UPLOAD_ERR_OK) {
throw new UserFormException($this->uploadErrMsg[$newArr[FILES_ERROR]], ERROR_UPLOAD);
throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'Upload: Error', ERROR_MESSAGE_SUPPORT => $this->uploadErrMsg[$newArr[FILES_ERROR]]]),
ERROR_UPLOAD);
}
$this->checkMaxFileSize($statusUpload['size']);
......@@ -154,7 +156,9 @@ class File {
$file = Support::extendFilename($statusUpload[FILES_TMP_NAME], UPLOAD_CACHED);
if (file_exists($file)) {
if (!unlink($file)) {
throw new UserFormException('unlink file: ' . $file, ERROR_IO_UNLINK);
throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'Unlink file', ERROR_MESSAGE_SUPPORT => 'unlink file: ' . $file]),
ERROR_IO_UNLINK);
}
}
$statusUpload[FILES_TMP_NAME] = '';
......
......@@ -471,14 +471,18 @@ class Save {
$cwd = getcwd();
$sitePath = $this->store->getVar(SYSTEM_SITE_PATH, STORE_SYSTEM);
if ($cwd === false || $sitePath === false || !chdir($sitePath)) {
throw new UserFormException("getcwd() failed or SITE_PATH undefined or chdir('$sitePath') failed.", ERROR_IO_CHDIR);
throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'getcwd() failed or SITE_PATH undefined or chdir() failed', ERROR_MESSAGE_SUPPORT => "getcwd() failed or SITE_PATH undefined or chdir('$sitePath') failed."]),
ERROR_IO_CHDIR);
}
// Get original pathFileName
$field = HelperFormElement::AppendFormElementNameImageCut($formElement);
$pathFileName = $this->store->getVar($field, STORE_SIP);
if ($pathFileName == '' || !file_exists($pathFileName)) {
throw new UserFormException('Empty file or file not found: ' . $pathFileName, ERROR_IO_FILE_NOT_FOUND);
throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'Empty file or file not found', ERROR_MESSAGE_SUPPORT => 'Empty file or file not found: ' . $pathFileName]),
ERROR_IO_FILE_NOT_FOUND);
}
// 'data:image/png;base64,AAAFBfj42Pj4...';
......@@ -515,7 +519,9 @@ class Save {
!file_exists($pathParts['dirname'] . $pathParts['filename'] . $extSave)
) {
if (!rename($pathFileName, $pathFileName . $extSave)) {
throw new UserFormException("Rename file: '$pathFileName' > '$pathFileName$extSave'", ERROR_IO_RENAME);
throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'Rename file', ERROR_MESSAGE_SUPPORT => "Rename file: '$pathFileName' > '$pathFileName$extSave'"]),
ERROR_IO_RENAME);
}
}
}
......@@ -525,7 +531,9 @@ class Save {
}
if (false === file_put_contents($pathFileName, base64_decode($imageData))) {
throw new UserFormException("Write new image failed: $pathFileName", ERROR_IO_WRITE);
throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'Write new image failed', ERROR_MESSAGE_SUPPORT => "Write new image failed: $pathFileName"]),
ERROR_IO_WRITE);
}
$this->store->setVar($formElement[FE_NAME], $pathFileName, STORE_FORM, true);
......@@ -573,7 +581,9 @@ class Save {
$cwd = getcwd();
$sitePath = $this->store->getVar(SYSTEM_SITE_PATH, STORE_SYSTEM);
if ($cwd === false || $sitePath === false || !chdir($sitePath)) {
throw new UserFormException("getcwd() failed or SITE_PATH undefined or chdir('$sitePath') failed.", ERROR_IO_CHDIR);
throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'getcwd() failed or SITE_PATH undefined or chdir() failed', ERROR_MESSAGE_SUPPORT => "getcwd() failed or SITE_PATH undefined or chdir('$sitePath') failed."]),
ERROR_IO_CHDIR);
}
// Delete existing old file.
......@@ -582,7 +592,9 @@ class Save {
$oldFile = $arr[EXISTING_PATH_FILE_NAME];
if (file_exists($oldFile)) {
if (!unlink($oldFile)) {
throw new UserFormException('Unlink file failed: ' . $oldFile, ERROR_IO_UNLINK);
throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'Unlink file failed', ERROR_MESSAGE_SUPPORT => 'Unlink file failed: ' . $oldFile]),
ERROR_IO_UNLINK);
}
}
$flagDelete = ($oldFile != '');
......
......@@ -138,12 +138,22 @@ class Database {
$mysqli = new \mysqli($config[SYSTEM_DB_SERVER], $config[SYSTEM_DB_USER], $config[SYSTEM_DB_PASSWORD], $config[SYSTEM_DB_NAME]);
if ($mysqli->connect_error) {
throw new UserFormException ("Error open Database 'mysql:host=" . $config[SYSTEM_DB_SERVER] . ";dbname=" . $config[SYSTEM_DB_NAME] . ";dbuser=" . $config[SYSTEM_DB_USER] . "'': " . $mysqli->connect_errno . PHP_EOL . $mysqli->connect_error, ERROR_DB_OPEN);
throw new UserFormException (
json_encode([ERROR_MESSAGE_TO_USER => 'Error open Database',
ERROR_MESSAGE_SUPPORT => "Error open Database 'mysql:host=" . $config[SYSTEM_DB_SERVER] .
";dbname=" . $config[SYSTEM_DB_NAME] .
";dbuser=" . $config[SYSTEM_DB_USER] .
"'': " . $mysqli->connect_errno . PHP_EOL . $mysqli->connect_error]),
ERROR_DB_OPEN);
}
// Necessary that mysqli::real_escape_string() functions properly.
if (!$mysqli->set_charset('utf8')) {
throw new UserFormException ("Error set_charset('utf8') Database: " . $mysqli->connect_errno . PHP_EOL . $mysqli->connect_error, ERROR_DB_SET_CHARSET);
throw new UserFormException (
json_encode([ERROR_MESSAGE_TO_USER => "Error set_charset('utf8')",
ERROR_MESSAGE_SUPPORT => "Error set_charset('utf8') Database: " . $mysqli->connect_errno . PHP_EOL . $mysqli->connect_error]),
ERROR_DB_SET_CHARSET);
}
return $mysqli;
......@@ -184,7 +194,7 @@ class Database {
// CR (& EV) often forgets to specify the $mode and use prepared statement with parameter instead.
if (is_array($mode)) {
throw new CodeException("Probably a parameter forgotten: \$mode ?");
throw new CodeException("Probably a parameter forgotten: $mode ?");
}
// for error reporting in exception
......@@ -387,7 +397,10 @@ class Database {
case 'DESCRIBE':
case 'EXPLAIN':
if (false === ($result = $this->mysqli_stmt->get_result())) {
throw new DbException('[ mysqli: ' . $this->mysqli_stmt->errno . ' ] ' . $this->mysqli_stmt->error . $specificMessage, ERROR_DB_EXECUTE);
throw new DbException(
json_encode([ERROR_MESSAGE_TO_USER => 'Error DB execute', ERROR_MESSAGE_SUPPORT => '[ mysqli: ' . $this->mysqli_stmt->errno . ' ] ' . $this->mysqli_stmt->error . $specificMessage]),
ERROR_DB_EXECUTE);
}
$queryType = QUERY_TYPE_SELECT;
$this->mysqli_result = $result;
......@@ -693,13 +706,17 @@ class Database {
* @throws UserFormException
*/
private function getFieldDefinitionFromTable($table, $columnName) {
$tableDefinition = $this->getTableDefinition($table);
foreach ($tableDefinition AS $row) {
if ($row["Field"] == $columnName) {
return $row;
}
}
throw new DbException("Column name '$columnName' not found in table '$table'.", ERROR_DB_COLUMN_NOT_FOUND_IN_TABLE);
throw new DbException(
json_encode([ERROR_MESSAGE_TO_USER => 'Column name not found', ERROR_MESSAGE_SUPPORT => "Column name '$columnName' not found in table '$table'."]),
ERROR_DB_COLUMN_NOT_FOUND_IN_TABLE);
}
/**
......
......@@ -313,7 +313,8 @@ class FormAction {
$msg = $this->evaluate->parse($fe[FE_MESSAGE_FAIL]); // Replace possible dynamic parts
// Throw user error message
throw new UserFormException($msg, ERROR_REPORT_FAILED_ACTION);
throw new UserFormException(json_encode([ERROR_MESSAGE_TO_USER => 'validate() failed', ERROR_MESSAGE_SUPPORT => $msg]), ERROR_REPORT_FAILED_ACTION);
}
/**
......@@ -593,7 +594,9 @@ class FormAction {
Support::mkDirParent($rowDest[$key]);
if (!copy($val, $rowDest[$key])) {
throw new UserFormException("Error copy file from [$val] to [" . $rowDest[$key] . "]", ERROR_IO_COPY_FILE);
throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'Error copy file', ERROR_MESSAGE_SUPPORT => "Error copy file from [$val] to [" . $rowDest[$key] . "]"]),
ERROR_IO_COPY_FILE);
}
}
}
......
......@@ -231,7 +231,9 @@ class HelperFile {
if ($chmod !== false) {
if (false === chmod($pathFileName, $chmod)) {
throw new UserFormException("Failed: chmod $chmod '$pathFileName'", ERROR_IO_CHMOD);
throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'Failed: chmod', ERROR_MESSAGE_SUPPORT => "Failed: chmod $chmod '$pathFileName'"]),
ERROR_IO_CHMOD);
}
}
......
......@@ -41,7 +41,9 @@ class Ldap {
$ds = ldap_connect($ldapServer); // must be a valid LDAP server!
if (!$ds) {
throw new UserFormException("Unable to connect to LDAP server: $ldapServer", ERROR_LDAP_CONNECT);
throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'Unable to connect to LDAP server', ERROR_MESSAGE_SUPPORT => "Unable to connect to LDAP server: $ldapServer"]),
ERROR_LDAP_CONNECT);
}
// http://php.net/manual/en/function.ldap-set-option.php >> This function is only available when using OpenLDAP 2.x.x OR Netscape Directory SDK x.x.
......
......@@ -42,12 +42,18 @@ class Logger {
// Try to open the file a second time.
if (!$handle = fopen($filename, $mode)) {
throw new UserFormException("Error - cannot open. File: " . $filename . " ( CWD: " . getcwd() . ") - " . error_get_last(), ERROR_IO_OPEN);
throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'Error: cannot open file',
ERROR_MESSAGE_SUPPORT => "Error - cannot open. File: " . $filename . " ( CWD: " . getcwd() . ") - " . error_get_last()]),
ERROR_IO_OPEN);
}
}
if (fwrite($handle, $msg . PHP_EOL) === false) {
throw new UserFormException("Error - cannot write. File: " . $filename . " ( CWD: " . getcwd() . ") - " . error_get_last(), ERROR_IO_WRITE);
throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'Error: cannot write file',
ERROR_MESSAGE_SUPPORT => "Error - cannot open. File: " . $filename . " ( CWD: " . getcwd() . ") - " . error_get_last()]),
ERROR_IO_WRITE);
}
fclose($handle);
......
......@@ -70,6 +70,7 @@ class FillStoreForm {
$form = $this->store->getVar(SIP_FORM, STORE_SIP, SANITIZE_ALLOW_ALNUMX);
if (!empty($form)) {
// To make STORE_RECORD available at a very early stage.
$recordId = $this->store->getVar(SIP_RECORD_ID, STORE_SIP, SANITIZE_ALLOW_DIGIT);
$tableFromFormSql = "SELECT tableName, primaryKey FROM Form WHERE name=?";
$form = $this->dbArray[$this->dbIndexQfq]->sql($tableFromFormSql, ROW_EXPECT_1, [$form]);
......@@ -79,8 +80,8 @@ class FillStoreForm {
}
$this->store->fillStoreWithRecord($form[F_TABLE_NAME], $recordId, $this->dbArray[$this->dbIndexData], $form[F_PRIMARY_KEY]);
}
$this->evaluate = new Evaluate($this->store, $this->dbArray[$this->dbIndexData]);
$this->evaluate = new Evaluate($this->store, $this->dbArray[$this->dbIndexData]);
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment