Skip to content

Commit ed00719

Browse files
committed
Improve consistency of exception message formatting.
1 parent e46c09b commit ed00719

File tree

72 files changed

+188
-170
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+188
-170
lines changed

lib/Doctrine/DBAL/Cache/ArrayStatement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function rowCount() : int
7777
public function setFetchMode($fetchMode, ...$args) : void
7878
{
7979
if (count($args) > 0) {
80-
throw new InvalidArgumentException('Caching layer does not support 2nd/3rd argument to setFetchMode()');
80+
throw new InvalidArgumentException('Caching layer does not support 2nd/3rd argument to setFetchMode().');
8181
}
8282

8383
$this->defaultFetchMode = $fetchMode;

lib/Doctrine/DBAL/DBALException.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,22 @@ class DBALException extends Exception
2828
*/
2929
public static function driverExceptionDuringQuery(Driver $driver, Throwable $driverEx, $sql, array $params = [])
3030
{
31-
$msg = "An exception occurred while executing '" . $sql . "'";
32-
if ($params) {
33-
$msg .= ' with params ' . self::formatParameters($params);
34-
}
35-
$msg .= ":\n\n" . $driverEx->getMessage();
31+
$message = sprintf(
32+
"An exception occurred while executing \"%s\"%s:\n\n%s.",
33+
$sql,
34+
$params !== [] ? sprintf(' with params %s', self::formatParameters($params)) : '',
35+
$driverEx->getMessage()
36+
);
3637

37-
return static::wrapException($driver, $driverEx, $msg);
38+
return static::wrapException($driver, $driverEx, $message);
3839
}
3940

4041
/**
4142
* @return self
4243
*/
4344
public static function driverException(Driver $driver, Throwable $driverEx)
4445
{
45-
return static::wrapException($driver, $driverEx, 'An exception occurred in driver: ' . $driverEx->getMessage());
46+
return static::wrapException($driver, $driverEx, sprintf('An exception occurred in driver "%s".', $driverEx->getMessage()));
4647
}
4748

4849
/**

lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ public function fetch($fetchMode = null, ...$args)
344344
return (object) $assoc;
345345

346346
default:
347-
throw new MysqliException(sprintf("Unknown fetch type '%s'", $fetchMode));
347+
throw new MysqliException(sprintf('Unknown fetch type "%s".', $fetchMode));
348348
}
349349
}
350350

lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public static function convertPositionalToNamedPlaceholders($statement)
156156

157157
if ($currentLiteralDelimiter) {
158158
throw new OCI8Exception(sprintf(
159-
'The statement contains non-terminated string literal starting at offset %d',
159+
'The statement contains non-terminated string literal starting at offset "%d".',
160160
$tokenOffset - 1
161161
));
162162
}
@@ -407,7 +407,7 @@ public function fetch($fetchMode = null, ...$args)
407407
}
408408

409409
if (! isset(self::$fetchModeMap[$fetchMode])) {
410-
throw new InvalidArgumentException('Invalid fetch style: ' . $fetchMode);
410+
throw new InvalidArgumentException(sprintf('Invalid fetch style "%s".', $fetchMode));
411411
}
412412

413413
return oci_fetch_array(
@@ -434,7 +434,7 @@ public function fetchAll($fetchMode = null, ...$args)
434434
}
435435

436436
if (! isset(self::$fetchModeMap[$fetchMode])) {
437-
throw new InvalidArgumentException('Invalid fetch style: ' . $fetchMode);
437+
throw new InvalidArgumentException(sprintf('Invalid fetch style "%s".', $fetchMode));
438438
}
439439

440440
if (self::$fetchModeMap[$fetchMode] === OCI_BOTH) {

lib/Doctrine/DBAL/Driver/PDOStatement.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ private function convertParamType(int $type) : int
206206
if (! isset(self::PARAM_TYPE_MAP[$type])) {
207207
// TODO: next major: throw an exception
208208
@trigger_error(sprintf(
209-
'Using a PDO parameter type (%d given) is deprecated and will cause an error in Doctrine 3.0',
209+
'Using a PDO parameter type ("%d" given) is deprecated and will cause an error in Doctrine 3.0.',
210210
$type
211211
), E_USER_DEPRECATED);
212212

@@ -226,8 +226,8 @@ private function convertFetchMode(int $fetchMode) : int
226226
if (! isset(self::FETCH_MODE_MAP[$fetchMode])) {
227227
// TODO: next major: throw an exception
228228
@trigger_error(sprintf(
229-
'Using a PDO fetch mode or their combination (%d given)' .
230-
' is deprecated and will cause an error in Doctrine 3.0',
229+
'Using a PDO fetch mode or their combination ("%d" given)' .
230+
' is deprecated and will cause an error in Doctrine 3.0.',
231231
$fetchMode
232232
), E_USER_DEPRECATED);
233233

lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
7373
public function __construct($conn, $sql)
7474
{
7575
if (! is_resource($conn)) {
76-
throw new SQLAnywhereException('Invalid SQL Anywhere connection resource: ' . $conn);
76+
throw new SQLAnywhereException(sprintf('Invalid SQL Anywhere connection resource "%s".', $conn));
7777
}
7878

7979
$this->conn = $conn;
@@ -108,7 +108,7 @@ public function bindParam($column, &$variable, $type = ParameterType::STRING, $l
108108
break;
109109

110110
default:
111-
throw new SQLAnywhereException('Unknown type: ' . $type);
111+
throw new SQLAnywhereException(sprintf('Unknown type "%s".', $type));
112112
}
113113

114114
$this->boundValues[$column] =& $variable;
@@ -215,7 +215,7 @@ public function fetch($fetchMode = null, ...$args)
215215
return sasql_fetch_object($this->result);
216216

217217
default:
218-
throw new SQLAnywhereException('Fetch mode is not supported: ' . $fetchMode);
218+
throw new SQLAnywhereException(sprintf('Fetch mode is not supported "%s".', $fetchMode));
219219
}
220220
}
221221

@@ -314,7 +314,7 @@ private function castObject(stdClass $sourceObject, $destinationClass, array $ct
314314
if (! is_string($destinationClass)) {
315315
if (! is_object($destinationClass)) {
316316
throw new SQLAnywhereException(sprintf(
317-
'Destination class has to be of type string or object, %s given.',
317+
'Destination class has to be of type string or object, "%s" given.',
318318
gettype($destinationClass)
319319
));
320320
}

lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Driver extends AbstractSQLServerDriver
1717
public function connect(array $params, $username = null, $password = null, array $driverOptions = [])
1818
{
1919
if (! isset($params['host'])) {
20-
throw new SQLSrvException("Missing 'host' in configuration for sqlsrv driver.");
20+
throw new SQLSrvException('Missing "host" in configuration for sqlsrv driver.');
2121
}
2222

2323
$serverName = $params['host'];

lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ public function fetch($fetchMode = null, ...$args)
345345
return sqlsrv_fetch_object($this->stmt, $className, $ctorArgs) ?: false;
346346
}
347347

348-
throw new SQLSrvException('Fetch mode is not supported!');
348+
throw new SQLSrvException('Fetch mode is not supported.');
349349
}
350350

351351
/**

lib/Doctrine/DBAL/Exception/DriverRequired.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ public static function new(?string $url = null) : self
1717
if ($url !== null) {
1818
return new self(
1919
sprintf(
20-
"The options 'driver' or 'driverClass' are mandatory if a connection URL without scheme "
21-
. 'is given to DriverManager::getConnection(). Given URL: %s',
20+
'The options "driver" or "driverClass" are mandatory if a connection URL without scheme '
21+
. 'is given to DriverManager::getConnection(). Given URL "%s".',
2222
$url
2323
)
2424
);
2525
}
2626

2727
return new self(
28-
"The options 'driver' or 'driverClass' are mandatory if no PDO "
28+
'The options "driver" or "driverClass" are mandatory if no PDO '
2929
. 'instance is given to DriverManager::getConnection().'
3030
);
3131
}

lib/Doctrine/DBAL/Exception/EmptyCriteriaNotAllowed.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ final class EmptyCriteriaNotAllowed extends InvalidArgumentException
88
{
99
public static function new() : self
1010
{
11-
return new self('Empty criteria was used, expected non-empty criteria');
11+
return new self('Empty criteria was used, expected non-empty criteria.');
1212
}
1313
}

lib/Doctrine/DBAL/Exception/InvalidColumnIndex.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ final class InvalidColumnIndex extends DBALException
1212
public static function new(int $index, int $count) : self
1313
{
1414
return new self(sprintf(
15-
'Invalid column index %d. The statement result contains %d column%s.',
15+
'Invalid column index "%d". The statement result contains "%d" column%s.',
1616
$index,
1717
$count,
1818
$count === 1 ? '' : 's'

lib/Doctrine/DBAL/Exception/InvalidDriverClass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public static function new(string $driverClass) : self
1414
{
1515
return new self(
1616
sprintf(
17-
"The given 'driverClass' %s has to implement the %s interface.",
17+
'The given "driverClass" "%s" has to implement the "%s" interface.',
1818
$driverClass,
1919
Driver::class
2020
)

lib/Doctrine/DBAL/Exception/InvalidPdoInstance.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ final class InvalidPdoInstance extends DBALException
1010
{
1111
public static function new() : self
1212
{
13-
return new self("The 'pdo' option was used in DriverManager::getConnection() but no instance of PDO was given.");
13+
return new self('The "pdo" option was used in DriverManager::getConnection() but no instance of PDO was given.');
1414
}
1515
}

lib/Doctrine/DBAL/Exception/InvalidPlatformType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static function new($invalidPlatform) : self
2121
if (is_object($invalidPlatform)) {
2222
return new self(
2323
sprintf(
24-
"Option 'platform' must be a subtype of '%s', instance of '%s' given",
24+
'Option "platform" must be a subtype of "%s", instance of "%s" given.',
2525
AbstractPlatform::class,
2626
get_class($invalidPlatform)
2727
)
@@ -30,7 +30,7 @@ public static function new($invalidPlatform) : self
3030

3131
return new self(
3232
sprintf(
33-
"Option 'platform' must be an object and subtype of '%s'. Got '%s'",
33+
'Option "platform" must be an object and subtype of "%s". Got "%s".',
3434
AbstractPlatform::class,
3535
gettype($invalidPlatform)
3636
)

lib/Doctrine/DBAL/Exception/InvalidWrapperClass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public static function new(string $wrapperClass) : self
1414
{
1515
return new self(
1616
sprintf(
17-
"The given 'wrapperClass' %s has to be a subtype of %s.",
17+
'The given "wrapperClass" "%s" has to be a subtype of "%s".',
1818
$wrapperClass,
1919
Connection::class
2020
)

lib/Doctrine/DBAL/Exception/MissingSQLParam.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ final class MissingSQLParam extends SQLParserUtilsException
1212
public static function new(string $paramName) : self
1313
{
1414
return new self(
15-
sprintf('Value for :%1$s not found in params array. Params array key should be "%1$s"', $paramName)
15+
sprintf('Value for :%1$s not found in params array. Params array key should be "%1$s"', $paramName) // what is this syntax?
1616
);
1717
}
1818
}

lib/Doctrine/DBAL/Exception/MissingSQLType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ final class MissingSQLType extends SQLParserUtilsException
1212
public static function new(string $typeName) : self
1313
{
1414
return new self(
15-
sprintf('Value for :%1$s not found in types array. Types array key should be "%1$s"', $typeName)
15+
sprintf('Value for :%1$s not found in types array. Types array key should be "%1$s"', $typeName) // what is this syntax?
1616
);
1717
}
1818
}

lib/Doctrine/DBAL/Exception/UnknownDriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static function new(string $unknownDriverName, array $knownDrivers) : sel
1717
{
1818
return new self(
1919
sprintf(
20-
"The given 'driver' %s is unknown, Doctrine currently supports only the following drivers: %s",
20+
'The given "driver" "%s" is unknown, Doctrine currently supports only the following drivers: %s',
2121
$unknownDriverName,
2222
implode(', ', $knownDrivers)
2323
)

lib/Doctrine/DBAL/Id/TableGenerator.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Throwable;
1313
use const CASE_LOWER;
1414
use function array_change_key_case;
15+
use function sprintf;
1516

1617
/**
1718
* Table ID Generator for those poor languages that are missing sequences.
@@ -126,7 +127,7 @@ public function nextValue($sequenceName)
126127
$rows = $this->conn->executeUpdate($sql, [$sequenceName, $row['sequence_value']]);
127128

128129
if ($rows !== 1) {
129-
throw new DBALException('Race-condition detected while updating sequence. Aborting generation');
130+
throw new DBALException('Race-condition detected while updating sequence. Aborting generation.');
130131
}
131132
} else {
132133
$this->conn->insert(
@@ -139,7 +140,7 @@ public function nextValue($sequenceName)
139140
$this->conn->commit();
140141
} catch (Throwable $e) {
141142
$this->conn->rollBack();
142-
throw new DBALException('Error occurred while generating ID with TableGenerator, aborted generation: ' . $e->getMessage(), 0, $e);
143+
throw new DBALException(sprintf('Error occurred while generating ID with TableGenerator, aborted generation with error "%s".', $e->getMessage()), 0, $e);
143144
}
144145

145146
return $value;

0 commit comments

Comments
 (0)