Commit cd8c1e03 authored by Christian Kuhn's avatar Christian Kuhn Committed by Wouter Wolters
Browse files

[TASK] Improve duplicate exception code check

* better regex finds more with less false positives
* use grep instead of ack-grep
* find exceptions without exception code
* the script kills travis for unkown reasons and removed

Change-Id: I6ae7c005bc9f493365d36f9602aebf389f1f7786
Resolves: #78221
Releases: master
Reviewed-on: https://review.typo3.org/50150


Reviewed-by: Markus Klein's avatarMarkus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein's avatarMarkus Klein <markus.klein@typo3.org>
Tested-by: default avatarTYPO3com <no-reply@typo3.com>
Reviewed-by: Wouter Wolters's avatarWouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters's avatarWouter Wolters <typo3@wouterwolters.nl>
parent f288f76b
......@@ -8,7 +8,7 @@ matrix:
include:
- php: 7
env: UNIT_TESTS=yes FUNCTIONAL_TESTS=yes ACCEPTANCE_TESTS=no JSUNIT_TESTS=yes PHP_LINT=yes XLF_CHECK=yes SUBMODULE_TEST=yes EXCEPTIONCODE_TEST=yes
env: UNIT_TESTS=yes FUNCTIONAL_TESTS=yes ACCEPTANCE_TESTS=no JSUNIT_TESTS=yes PHP_LINT=yes XLF_CHECK=yes SUBMODULE_TEST=yes
sudo: false
......@@ -105,8 +105,3 @@ script:
fi
"
fi
- >
if [[ "$EXCEPTIONCODE_TEST" == "yes" ]]; then
./typo3/sysext/core/Build/Scripts/duplicateExceptionCodeCheck.sh
fi
\ No newline at end of file
......@@ -127,9 +127,9 @@ class CliRequestHandler implements RequestHandlerInterface
{
$cliKey = $input->getFirstArgument();
if (empty($cliKey)) {
throw new \InvalidArgumentException('This script must have a command as first argument.', 1);
throw new \InvalidArgumentException('This script must have a command as first argument.', 1476107418);
} elseif (!is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['cliKeys'][$cliKey])) {
throw new \InvalidArgumentException('This supplied command is not valid.', 1);
throw new \InvalidArgumentException('This supplied command is not valid.', 1476107480);
}
return $cliKey;
}
......@@ -167,18 +167,18 @@ class CliRequestHandler implements RequestHandlerInterface
protected function loadCommandLineBackendUser($commandLineName)
{
if ($GLOBALS['BE_USER']->user['uid']) {
throw new \RuntimeException('Another user was already loaded which is impossible in CLI mode!', 3);
throw new \RuntimeException('Another user was already loaded which is impossible in CLI mode!', 1476107444);
}
if (!StringUtility::beginsWith($commandLineName, '_CLI_')) {
throw new \RuntimeException('Module name, "' . $commandLineName . '", was not prefixed with "_CLI_"', 3);
throw new \RuntimeException('Module name, "' . $commandLineName . '", was not prefixed with "_CLI_"', 1476107445);
}
$userName = strtolower($commandLineName);
$GLOBALS['BE_USER']->setBeUserByName($userName);
if (!$GLOBALS['BE_USER']->user['uid']) {
throw new \RuntimeException('No backend user named "' . $userName . '" was found!', 3);
throw new \RuntimeException('No backend user named "' . $userName . '" was found!', 1476107195);
}
if ($GLOBALS['BE_USER']->isAdmin()) {
throw new \RuntimeException('CLI backend user "' . $userName . '" was ADMIN which is not allowed!', 3);
throw new \RuntimeException('CLI backend user "' . $userName . '" was ADMIN which is not allowed!', 1476107446);
}
}
......
......@@ -169,7 +169,7 @@ class EditFileController extends AbstractModule
$extList = $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'];
try {
if (!$extList || !GeneralUtility::inList($extList, $this->fileObject->getExtension())) {
throw new \Exception('Files with that extension are not editable.');
throw new \Exception('Files with that extension are not editable.', 1476050135);
}
// Read file content to edit:
......
......@@ -70,7 +70,7 @@ class UriBuilder
{
$this->loadBackendRoutes();
if (!isset($this->routes[$name])) {
throw new RouteNotFoundException('Unable to generate a URL for the named route "' . $name . '" because this route was not found.');
throw new RouteNotFoundException('Unable to generate a URL for the named route "' . $name . '" because this route was not found.', 1476050190);
}
$route = $this->routes[$name];
......
......@@ -918,7 +918,7 @@ class ConditionMatcherTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
public function matchCallsTestConditionAndHandsOverParameters()
{
$this->expectException(TestConditionException::class);
$this->expectExceptionCode(1411581139);
$this->expectExceptionCode(1476109533);
$this->matchCondition->match('[TYPO3\\CMS\\Backend\\Tests\\Unit\\Configuration\\TypoScript\\ConditionMatching\\Fixtures\\TestCondition = 7, != 6]');
}
}
......@@ -30,7 +30,7 @@ class TestCondition extends \TYPO3\CMS\Core\Configuration\TypoScript\ConditionMa
{
// Throw an exception if everything is fine, this exception is *expected* in the according unit test
if ($conditionParameters[0] === '= 7' && $conditionParameters[1] === '!= 6') {
throw new TestConditionException('All Ok', 1411581139);
throw new TestConditionException('All Ok', 1476109533);
}
}
}
......@@ -247,7 +247,7 @@ class TcaCheckboxItemsTest extends UnitTestCase
|| $parameters['field'] !== 'aField'
|| $parameters['flexParentDatabaseRow']['aParentDatabaseRowFieldName'] !== 'aParentDatabaseRowFieldValue'
) {
throw new \UnexpectedValueException('broken', 1438604329);
throw new \UnexpectedValueException('broken', 1476109402);
}
},
],
......
......@@ -290,7 +290,7 @@ class TcaRadioItemsTest extends UnitTestCase
|| $parameters['row'] !== [ 'aField' => 'aValue' ]
|| $parameters['field'] !== 'aField'
) {
throw new \UnexpectedValueException('broken', 1438604329);
throw new \UnexpectedValueException('broken', 1476109434);
}
},
],
......@@ -352,7 +352,7 @@ class TcaRadioItemsTest extends UnitTestCase
],
],
'itemsProcFunc' => function (array $parameters, $pObj) {
throw new \UnexpectedValueException('anException', 1438604329);
throw new \UnexpectedValueException('anException', 1476109435);
},
],
],
......
......@@ -1857,8 +1857,8 @@ class TcaSelectItemsTest extends UnitTestCase
$queryBuilderProphet->andWhere(' 1=1')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
$queryBuilderProphet->andWhere('`pages.uid` = `fTable.pid`')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
$prevException = new DBALException('Invalid table name', 400);
$exception = new DBALException('Driver error', 500, $prevException);
$prevException = new DBALException('Invalid table name', 1476045274);
$exception = new DBALException('Driver error', 1476045971, $prevException);
$queryBuilderProphet->execute()->shouldBeCalled()->willThrow($exception);
......@@ -2679,7 +2679,7 @@ class TcaSelectItemsTest extends UnitTestCase
|| $parameters['row'] !== [ 'aField' => 'aValue' ]
|| $parameters['field'] !== 'aField'
) {
throw new \UnexpectedValueException('broken', 1438604329);
throw new \UnexpectedValueException('broken', 1476109436);
}
},
],
......@@ -2742,7 +2742,7 @@ class TcaSelectItemsTest extends UnitTestCase
],
],
'itemsProcFunc' => function (array $parameters, $pObj) {
throw new \UnexpectedValueException('anException', 1438604329);
throw new \UnexpectedValueException('anException', 1476109437);
},
],
],
......
......@@ -3,50 +3,84 @@
#########################
#
# Find duplicate exception timestamps and list them.
# It expects to be run from the core root.
# Additionally find exceptions that have no exception code.
#
# The script searches for duplicate timestamps with
# two exceptions:
# 1. timestamps defined by the "IGNORE" array
# 2. timestamps within Tests directories
# It expects to be run from the core root.
#
##########################
cd typo3/
# Array of timestamps which are allowed to be non-unique
IGNORE=("1270853884")
# The ack / ack-grep command can be different for different OS
ACK=${ACK:-ack-grep}
ignoreFiles=()
# auto generated file, shouldn't be checked
ignoreFiles+="sysext/core/Build/Configuration/Acceptance/Support/_generated/AcceptanceTesterActions.php"
# a exception in here throws up an code from a previous exception
ignoreFiles+="sysext/extbase/Classes/Core/Bootstrap.php"
# Respect only php files and ignore files within a "Tests" directory
EXCEPTIONS=$(${ACK} --type php --ignore-dir Tests 'throw new' -A5 0>&- | grep '[[:digit:]]\{10\}')
foundNewFile=0
oldFilename=""
firstLineOfMatch=""
foundExceptionInFile=1
exceptionCodes=()
DUPLICATES=$(echo ${EXCEPTIONS} | awk '{
for(i=1; i<=NF; i++) {
if(match($i, /[0-9]{10}/)) {
print $i
}
}
}' | cut -d';' -f1 | tr -cd '0-9\012' | sort | uniq -d)
COUNTER=0
# grep
# '-r' recursive
# '--include '*.php'' in all .php files
# '-Pzoab' pcre regex, -zo remove all linebreaks for multiline match, treat all files as text, output position "filename:position: match", binary position
#
# (?:(?!Exception\()[\w\\])* negative lookahead. capture all alphanum and \ until we reach "Exception("
# eat "Exception("
# (?:(?!\);).|[\r\n])*\);[\r\n]+ negative lookahead again, eat everything including a \n until we reach the first ");", then line breaks
for CODE in ${DUPLICATES}; do
grep \
-r \
--include '*.php' \
-Pzoab \
'new (?:(?!Exception\()[\w\\])*Exception\((?:(?!\);).|[\r\n])*\);[\r\n]+' \
| \
while read line;
do
possibleFilename=`echo ${line} | cut -d':' -f1`
if [[ ${possibleFilename} =~ .php$ ]]; then
# the matched line consists of a file name match, we're dealing with a new match here.
foundNewFile=1
oldFilename=${currentFilename}
currentFilename=${possibleFilename}
else
foundNewFile=0
fi
# Ignore timestamps which are defined by the "IGNORE" array
if [ ${IGNORE[@]} != ${CODE} ] ; then
echo "Possible duplicate exception code $CODE": ${ACK} --type php ${CODE}
COUNTER=$((COUNTER+1))
# skip file if in blacklist
if [[ {$ignoreFiles[@]} =~ ${currentFilename} ]]; then
continue
fi
done
# check for match in previous file name
if [[ ${foundNewFile} -eq 1 ]] && [[ ${foundExceptionInFile} -eq 0 ]]; then
echo "File: $oldFilename"
echo "The created exception contains no 10 digit exception code as second argument, in or below this line:"
echo "$firstLineOfMatch"
exit 1
fi
if [ ${COUNTER} -gt 0 ] ; then
echo "$COUNTER possible duplicate exception codes found."
exit 1
fi
# reset found flag if we're handling new file
if [[ ${foundNewFile} -eq 1 ]]; then
foundExceptionInFile=0
firstLineOfMatch=${line}
fi
exit 0
# see if the line consists of an exception code
if [[ "$line" =~ .*([0-9]{10}).* ]]; then
foundExceptionInFile=1
exceptionCode=${BASH_REMATCH[1]}
# check if that code was registered already
if [[ {$exceptionCodes[@]} =~ ${exceptionCode} ]]; then
echo "Duplicate exception code ${exceptionCode} in file:"
echo ${currentFilename}
exit 1
fi
exceptionCodes+=${exceptionCode}
fi
done || exit 1
exit 0
\ No newline at end of file
......@@ -370,7 +370,7 @@ abstract class AbstractUserAuthentication
{
// Backend or frontend login - used for auth services
if (empty($this->loginType)) {
throw new Exception('No loginType defined, should be set explicitly by subclass');
throw new Exception('No loginType defined, should be set explicitly by subclass', 1476045345);
}
// Enable dev logging if set
if ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['writeDevLog']) {
......
......@@ -152,7 +152,10 @@ class SimpleFileBackend extends \TYPO3\CMS\Core\Cache\Backend\AbstractBackend im
}
}
if (!$cacheDirectoryInBaseDir) {
throw new \TYPO3\CMS\Core\Cache\Exception('Open_basedir restriction in effect. The directory "' . $cacheDirectory . '" is not in an allowed path.');
throw new \TYPO3\CMS\Core\Cache\Exception(
'Open_basedir restriction in effect. The directory "' . $cacheDirectory . '" is not in an allowed path.',
1476045417
);
}
} else {
if ($cacheDirectory[0] == '/') {
......
......@@ -96,7 +96,7 @@ class CommandRequestHandler implements RequestHandlerInterface
$GLOBALS['BE_USER']->setBeUserByName($userName);
if (!$GLOBALS['BE_USER']->user['uid']) {
throw new \RuntimeException('No backend user named "' . $userName . '" was found!', 3);
throw new \RuntimeException('No backend user named "' . $userName . '" was found!', 1476107260);
}
$this->bootstrap
......
......@@ -654,7 +654,10 @@ class Bootstrap
break;
default:
// Throw exception if an invalid option is set.
throw new \RuntimeException('The option $TYPO3_CONF_VARS[SYS][displayErrors] is not set to "-1", "0" or "1".');
throw new \RuntimeException(
'The option $TYPO3_CONF_VARS[SYS][displayErrors] is not set to "-1", "0" or "1".',
1476046290
);
}
@ini_set('display_errors', $displayErrors);
......
......@@ -133,13 +133,15 @@ class BulkInsertQuery
if (!$namedValue && !$positionalValue) {
throw new \InvalidArgumentException(
sprintf('No value specified for column %s (index %d).', $column, $index)
sprintf('No value specified for column %s (index %d).', $column, $index),
1476049651
);
}
if ($namedValue && $positionalValue && $values[$column] !== $values[$index]) {
throw new \InvalidArgumentException(
sprintf('Multiple values specified for column %s (index %d).', $column, $index)
sprintf('Multiple values specified for column %s (index %d).', $column, $index),
1476049652
);
}
......@@ -151,7 +153,8 @@ class BulkInsertQuery
if ($namedType && $positionalType && $types[$column] !== $types[$index]) {
throw new \InvalidArgumentException(
sprintf('Multiple types specified for column %s (index %d).', $column, $index)
sprintf('Multiple types specified for column %s (index %d).', $column, $index),
1476049653
);
}
......@@ -192,7 +195,8 @@ class BulkInsertQuery
'You can only insert %d rows in a single INSERT statement with platform "%s".',
$insertMaxRows,
$platform->getName()
)
),
1476049654
);
}
......@@ -244,7 +248,10 @@ class BulkInsertQuery
public function getSQL(): string
{
if (empty($this->values)) {
throw new \LogicException('You need to add at least one set of values before generating the SQL.');
throw new \LogicException(
'You need to add at least one set of values before generating the SQL.',
1476049702
);
}
$connection = $this->connection;
......
......@@ -110,7 +110,7 @@ class ErrorHandler implements ErrorHandlerInterface
'line ' . $errorLine;
die($message);
}
throw new Exception($message, 1);
throw new Exception($message, 1476107295);
} else {
switch ($errorLevel) {
case E_USER_ERROR:
......
......@@ -81,7 +81,7 @@ class ExtDirectRouter
}
try {
if (!$validToken) {
throw new \TYPO3\CMS\Core\FormProtection\Exception('ExtDirect: Invalid Security Token!');
throw new \TYPO3\CMS\Core\FormProtection\Exception('ExtDirect: Invalid Security Token!', 1476046324);
}
$extResponse[$index]['type'] = 'rpc';
$extResponse[$index]['result'] = $this->processRpc($singleRequest, $namespace);
......
......@@ -413,7 +413,10 @@ class LocalDriver extends AbstractHierarchicalFilesystemDriver
if ($result === -1) {
return false;
} elseif ($result === false) {
throw new \RuntimeException('Could not apply file/folder name filter ' . $filter[0] . '::' . $filter[1]);
throw new \RuntimeException(
'Could not apply file/folder name filter ' . $filter[0] . '::' . $filter[1],
1476046425
);
}
}
}
......@@ -680,7 +683,7 @@ class LocalDriver extends AbstractHierarchicalFilesystemDriver
case 'folder_hash':
return $this->hashIdentifier($this->getParentFolderIdentifierOfIdentifier($identifier));
default:
throw new \InvalidArgumentException(sprintf('The information "%s" is not available.', $property));
throw new \InvalidArgumentException(sprintf('The information "%s" is not available.', $property), 1476047422);
}
}
......@@ -771,7 +774,10 @@ class LocalDriver extends AbstractHierarchicalFilesystemDriver
$result = copy($localFilePath, $targetPath);
}
if ($result === false || !file_exists($targetPath)) {
throw new \RuntimeException('Adding file ' . $localFilePath . ' at ' . $newFileIdentifier . ' failed.');
throw new \RuntimeException(
'Adding file ' . $localFilePath . ' at ' . $newFileIdentifier . ' failed.',
1476046453
);
}
clearstatcache();
// Change the permissions of the file
......
......@@ -57,7 +57,7 @@ class TaskTypeRegistry implements \TYPO3\CMS\Core\SingletonInterface
{
$taskClass = $this->getClassForTaskType($taskType);
if ($taskClass === null) {
throw new \RuntimeException('Unknown processing task "' . $taskType . '"');
throw new \RuntimeException('Unknown processing task "' . $taskType . '"', 1476049767);
}
return GeneralUtility::makeInstance($taskClass, $processedFile, $processingConfiguration);
......
......@@ -2028,7 +2028,7 @@ class ResourceStorage implements ResourceStorageInterface
*/
protected function moveFolderBetweenStorages(Folder $folderToMove, Folder $targetParentFolder, $newFolderName)
{
throw new \RuntimeException('Not yet implemented');
throw new \RuntimeException('Not yet implemented', 1476046361);
}
/**
......@@ -2085,7 +2085,7 @@ class ResourceStorage implements ResourceStorageInterface
*/
protected function copyFolderBetweenStorages(Folder $folderToCopy, Folder $targetParentFolder, $newFolderName)
{
throw new \RuntimeException('Not yet implemented.');
throw new \RuntimeException('Not yet implemented.', 1476046386);
}
/**
......
Supports Markdown
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