Skip to content

Commit

Permalink
Unwrap exceptions
Browse files Browse the repository at this point in the history
closes #28
  • Loading branch information
mathroc committed Nov 21, 2015
1 parent bf647c1 commit aac7c06
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 30 deletions.
10 changes: 8 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@
}
},
"require": {
"doctrine/dbal": "~2.5"
"doctrine/dbal": "dev-avoid-over-nesting-exceptions"
},
"require-dev": {
"behat/behat": "~3.0"
}
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/mathroc/dbal"
}
]
}
7 changes: 1 addition & 6 deletions features/bootstrap/MySQLContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,7 @@ private function retryStrategy($n)

private function errorCode($exception)
{
while ($exception !== null) {
if ($exception instanceof \Doctrine\DBAL\Exception\DriverException) {
return $exception->getErrorCode();
}
$exception = $exception->getPrevious();
}
return $exception->getErrorCode();
}

private function retryDriverClass()
Expand Down
10 changes: 2 additions & 8 deletions features/bootstrap/PostgreSQLContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,8 @@ private function retryStrategy($n)

private function errorCode($exception)
{
while ($exception !== null) {
if ($exception instanceof DriverException) {
preg_match("/SQLSTATE\[(?<errorCode>[A-Z0-9]*)\]/", $exception->getMessage(), $matches);
if (array_key_exists("errorCode", $matches)) {
return $matches["errorCode"];
}
}
$exception = $exception->getPrevious();
if(preg_match("/SQLSTATE\[(?<errorCode>[A-Z0-9]*)\]/", $exception->getMessage(), $matches)) {
return $matches["errorCode"];
}
}

Expand Down
7 changes: 1 addition & 6 deletions src/RetryStrategy/MysqlRetryStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ private function errorCodeStrategies() {

private function errorCode(DBALException $exception)
{
while ($exception !== null) {
if ($exception instanceof DriverException) {
return $exception->getErrorCode();
}
$exception = $exception->getPrevious();
}
return $exception->getErrorCode();
}
}
10 changes: 2 additions & 8 deletions src/RetryStrategy/PostgreSQLRetryStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,8 @@ private function errorCodeStrategies() {

private function errorCode(DBALException $exception)
{
while ($exception !== null) {
if ($exception instanceof DriverException) {
preg_match("/SQLSTATE\[(?<errorCode>[A-Z0-9]*)\]/", $exception->getMessage(), $matches);
if (array_key_exists("errorCode", $matches)) {
return $matches["errorCode"];
}
}
$exception = $exception->getPrevious();
if (preg_match("/SQLSTATE\[(?<errorCode>[A-Z0-9]*)\]/", $exception->getMessage(), $matches)) {
return $matches["errorCode"];
}
}
}

0 comments on commit aac7c06

Please sign in to comment.