Skip to content

Standardize the name of the exception variables #14937

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/TwigBundle/TwigEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function render($name, array $parameters = array())
try {
// try to get the real file name of the template where the error occurred
$e->setTemplateFile(sprintf('%s', $this->locator->locate($this->parser->parse($e->getTemplateFile()))));
} catch (\Exception $ex) {
} catch (\Exception $e2) {
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Config/Definition/ArrayNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ protected function finalizeValue($value)

try {
$value[$name] = $child->finalize($value[$name]);
} catch (UnsetKeyException $unset) {
} catch (UnsetKeyException $e) {
unset($value[$name]);
}
}
Expand Down
12 changes: 4 additions & 8 deletions src/Symfony/Component/Config/Definition/BaseNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,10 @@ final public function finalize($value)
foreach ($this->finalValidationClosures as $closure) {
try {
$value = $closure($value);
} catch (Exception $correctEx) {
throw $correctEx;
} catch (\Exception $invalid) {
throw new InvalidConfigurationException(sprintf(
'Invalid configuration for path "%s": %s',
$this->getPath(),
$invalid->getMessage()
), $invalid->getCode(), $invalid);
} catch (Exception $e) {
throw $e;
} catch (\Exception $e) {
throw new InvalidConfigurationException(sprintf('Invalid configuration for path "%s": %s', $this->getPath(), $e->getMessage()), $e->getCode(), $e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ protected function finalizeValue($value)
$this->prototype->setName($k);
try {
$value[$k] = $this->prototype->finalize($v);
} catch (UnsetKeyException $unset) {
} catch (UnsetKeyException $e) {
unset($value[$k]);
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/Symfony/Component/Console/Helper/DialogHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -452,18 +452,18 @@ private function hasSttyAvailable()
*/
private function validateAttempts($interviewer, OutputInterface $output, $validator, $attempts)
{
$error = null;
$e = null;
while (false === $attempts || $attempts--) {
if (null !== $error) {
$output->writeln($this->getHelperSet()->get('formatter')->formatBlock($error->getMessage(), 'error'));
if (null !== $e) {
$output->writeln($this->getHelperSet()->get('formatter')->formatBlock($e->getMessage(), 'error'));
}

try {
return call_user_func($validator, $interviewer());
} catch (\Exception $error) {
} catch (\Exception $e) {
}
}

throw $error;
throw $e;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function process(ContainerBuilder $container)
foreach ($definition->getMethodCalls() as $call) {
try {
$calls[] = array($call[0], $this->processArguments($call[1], true));
} catch (RuntimeException $ignore) {
} catch (RuntimeException $e) {
// this call is simply removed
}
}
Expand All @@ -58,7 +58,7 @@ public function process(ContainerBuilder $container)
try {
$value = $this->processArguments(array($value), true);
$properties[$name] = reset($value);
} catch (RuntimeException $ignore) {
} catch (RuntimeException $e) {
// ignore property
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function collect(Request $request, Response $response, \Exception $except
'file' => $r->getFileName(),
'line' => $r->getStartLine(),
);
} catch (\ReflectionException $re) {
} catch (\ReflectionException $e) {
if (is_callable($controller)) {
// using __call or __callStatic
$this->data['controller'] = array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ public function testHandleRestoresThePreviousRequestOnException($type)
try {
$kernel->handle($request, $type);
$this->fail('->handle() suppresses the controller exception');
} catch (\PHPUnit_Framework_Exception $exception) {
throw $exception;
} catch (\Exception $actual) {
$this->assertSame($expected, $actual, '->handle() throws the controller exception');
} catch (\PHPUnit_Framework_Exception $e) {
throw $e;
} catch (\Exception $e) {
$this->assertSame($expected, $e, '->handle() throws the controller exception');
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Security/Acl/Dbal/AclProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,13 @@ public function findAcls(array $oids, array $sids = array())
if ($currentBatchesCount > 0 && (self::MAX_BATCH_SIZE === $currentBatchesCount || ($i + 1) === $c)) {
try {
$loadedBatch = $this->lookupObjectIdentities($currentBatch, $sids, $oidLookup);
} catch (AclNotFoundException $aclNotFoundexception) {
} catch (AclNotFoundException $e) {
if ($result->count()) {
$partialResultException = new NotAllAclsFoundException('The provider could not find ACLs for all object identities.');
$partialResultException->setPartialResult($result);
throw $partialResultException;
} else {
throw $aclNotFoundexception;
throw $e;
}
}
foreach ($loadedBatch as $loadedOid) {
Expand Down
12 changes: 6 additions & 6 deletions src/Symfony/Component/Security/Acl/Dbal/MutableAclProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ public function createAcl(ObjectIdentityInterface $oid)
$this->connection->executeQuery($this->getInsertObjectIdentityRelationSql($pk, $pk));

$this->connection->commit();
} catch (\Exception $failed) {
} catch (\Exception $e) {
$this->connection->rollBack();

throw $failed;
throw $e;
}

// re-read the ACL from the database to ensure proper caching, etc.
Expand All @@ -90,10 +90,10 @@ public function deleteAcl(ObjectIdentityInterface $oid)
$this->deleteObjectIdentity($oidPK);

$this->connection->commit();
} catch (\Exception $failed) {
} catch (\Exception $e) {
$this->connection->rollBack();

throw $failed;
throw $e;
}

// evict the ACL from the in-memory identity map
Expand Down Expand Up @@ -324,10 +324,10 @@ public function updateAcl(MutableAclInterface $acl)
}

$this->connection->commit();
} catch (\Exception $failed) {
} catch (\Exception $e) {
$this->connection->rollBack();

throw $failed;
throw $e;
}

$this->propertyChanges->offsetSet($acl, array());
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Security/Acl/Domain/ObjectIdentity.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public static function fromDomainObject($domainObject)
} elseif (method_exists($domainObject, 'getId')) {
return new self((string) $domainObject->getId(), ClassUtils::getRealClass($domainObject));
}
} catch (\InvalidArgumentException $invalid) {
throw new InvalidDomainObjectException($invalid->getMessage(), 0, $invalid);
} catch (\InvalidArgumentException $e) {
throw new InvalidDomainObjectException($e->getMessage(), 0, $e);
}

throw new InvalidDomainObjectException('$domainObject must either implement the DomainObjectInterface, or have a method named "getId".');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function getObjectIdentity($domainObject)
{
try {
return ObjectIdentity::fromDomainObject($domainObject);
} catch (InvalidDomainObjectException $failed) {
} catch (InvalidDomainObjectException $e) {
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,21 @@ public function isGranted(AclInterface $acl, array $masks, array $sids, $adminis
}

return $this->hasSufficientPermissions($acl, $aces, $masks, $sids, $administrativeMode);
} catch (NoAceFoundException $noObjectAce) {
} catch (NoAceFoundException $e) {
$aces = $acl->getClassAces();

if (!$aces) {
throw $noObjectAce;
throw $e;
}

return $this->hasSufficientPermissions($acl, $aces, $masks, $sids, $administrativeMode);
}
} catch (NoAceFoundException $noClassAce) {
} catch (NoAceFoundException $e) {
if ($acl->isEntriesInheriting() && null !== $parentAcl = $acl->getParentAcl()) {
return $parentAcl->isGranted($masks, $sids, $administrativeMode);
}

throw $noClassAce;
throw $e;
}
}

Expand All @@ -86,20 +86,20 @@ public function isFieldGranted(AclInterface $acl, $field, array $masks, array $s
}

return $this->hasSufficientPermissions($acl, $aces, $masks, $sids, $administrativeMode);
} catch (NoAceFoundException $noObjectAces) {
} catch (NoAceFoundException $e) {
$aces = $acl->getClassFieldAces($field);
if (!$aces) {
throw $noObjectAces;
throw $e;
}

return $this->hasSufficientPermissions($acl, $aces, $masks, $sids, $administrativeMode);
}
} catch (NoAceFoundException $noClassAces) {
} catch (NoAceFoundException $e) {
if ($acl->isEntriesInheriting() && null !== $parentAcl = $acl->getParentAcl()) {
return $parentAcl->isFieldGranted($field, $masks, $sids, $administrativeMode);
}

throw $noClassAces;
throw $e;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function getSecurityIdentities(TokenInterface $token)
if (!$token instanceof AnonymousToken) {
try {
$sids[] = UserSecurityIdentity::fromToken($token);
} catch (\InvalidArgumentException $invalid) {
} catch (\InvalidArgumentException $e) {
// ignore, user has no user security identity
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function getPattern()
if ('1' === $bitmask[$i]) {
try {
$pattern[$i] = self::getCode(1 << ($length - $i - 1));
} catch (\Exception $notPredefined) {
} catch (\Exception $e) {
$pattern[$i] = self::ON;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Security/Acl/Voter/AclVoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ public function vote(TokenInterface $token, $object, array $attributes)
}

return self::ACCESS_DENIED;
} catch (AclNotFoundException $noAcl) {
} catch (AclNotFoundException $e) {
if (null !== $this->logger) {
$this->logger->debug('No ACL found for the object identity. Voting to deny access.');
}

return self::ACCESS_DENIED;
} catch (NoAceFoundException $noAce) {
} catch (NoAceFoundException $e) {
if (null !== $this->logger) {
$this->logger->debug('ACL found, no ACE applicable. Voting to deny access.');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ protected function retrieveUser($username, UsernamePasswordToken $token)
}

return $user;
} catch (UsernameNotFoundException $notFound) {
$notFound->setUsername($username);
throw $notFound;
} catch (\Exception $repositoryProblem) {
$ex = new AuthenticationServiceException($repositoryProblem->getMessage(), 0, $repositoryProblem);
$ex->setToken($token);
throw $ex;
} catch (UsernameNotFoundException $e) {
$e->setUsername($username);
throw $e;
} catch (\Exception $e) {
$e = new AuthenticationServiceException($e->getMessage(), 0, $e);
$e->setToken($token);
throw $e;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ public function authenticate(TokenInterface $token)

try {
$user = $this->retrieveUser($username, $token);
} catch (UsernameNotFoundException $notFound) {
} catch (UsernameNotFoundException $e) {
if ($this->hideUserNotFoundExceptions) {
throw new BadCredentialsException('Bad credentials', 0, $notFound);
throw new BadCredentialsException('Bad credentials', 0, $e);
}
$notFound->setUsername($username);
$e->setUsername($username);

throw $notFound;
throw $e;
}

if (!$user instanceof UserInterface) {
Expand Down
12 changes: 6 additions & 6 deletions src/Symfony/Component/Security/Core/User/ChainUserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function loadUserByUsername($username)
foreach ($this->providers as $provider) {
try {
return $provider->loadUserByUsername($username);
} catch (UsernameNotFoundException $notFound) {
} catch (UsernameNotFoundException $e) {
// try next one
}
}
Expand All @@ -67,18 +67,18 @@ public function refreshUser(UserInterface $user)
foreach ($this->providers as $provider) {
try {
return $provider->refreshUser($user);
} catch (UnsupportedUserException $unsupported) {
} catch (UnsupportedUserException $e) {
// try next one
} catch (UsernameNotFoundException $notFound) {
} catch (UsernameNotFoundException $e) {
$supportedUserFound = true;
// try next one
}
}

if ($supportedUserFound) {
$ex = new UsernameNotFoundException(sprintf('There is no user with name "%s".', $user->getUsername()));
$ex->setUsername($user->getUsername());
throw $ex;
$e = new UsernameNotFoundException(sprintf('There is no user with name "%s".', $user->getUsername()));
$e->setUsername($user->getUsername());
throw $e;
} else {
throw new UnsupportedUserException(sprintf('The account "%s" is not supported.', get_class($user)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ final public function handle(GetResponseEvent $event)

try {
list($user, $credentials) = $this->getPreAuthenticatedData($request);
} catch (BadCredentialsException $exception) {
$this->clearToken($exception);
} catch (BadCredentialsException $e) {
$this->clearToken($e);

return;
}
Expand All @@ -90,8 +90,8 @@ final public function handle(GetResponseEvent $event)
$loginEvent = new InteractiveLoginEvent($request, $token);
$this->dispatcher->dispatch(SecurityEvents::INTERACTIVE_LOGIN, $loginEvent);
}
} catch (AuthenticationException $failed) {
$this->clearToken($failed);
} catch (AuthenticationException $e) {
$this->clearToken($e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,21 @@ public function handle(GetResponseEvent $event)
try {
$token = $this->authenticationManager->authenticate(new UsernamePasswordToken($username, $request->headers->get('PHP_AUTH_PW'), $this->providerKey));
$this->securityContext->setToken($token);
} catch (AuthenticationException $failed) {
} catch (AuthenticationException $e) {
$token = $this->securityContext->getToken();
if ($token instanceof UsernamePasswordToken && $this->providerKey === $token->getProviderKey()) {
$this->securityContext->setToken(null);
}

if (null !== $this->logger) {
$this->logger->info(sprintf('Authentication request failed for user "%s": %s', $username, $failed->getMessage()));
$this->logger->info(sprintf('Authentication request failed for user "%s": %s', $username, $e->getMessage()));
}

if ($this->ignoreFailure) {
return;
}

$event->setResponse($this->authenticationEntryPoint->start($request, $failed));
$event->setResponse($this->authenticationEntryPoint->start($request, $e));
}
}
}
Loading