Skip to content

Commit

Permalink
Improve consistency of exception message formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
jwage committed Apr 30, 2019
1 parent e46c09b commit ed00719
Show file tree
Hide file tree
Showing 72 changed files with 188 additions and 170 deletions.
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Cache/ArrayStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function rowCount() : int
public function setFetchMode($fetchMode, ...$args) : void
{
if (count($args) > 0) {
throw new InvalidArgumentException('Caching layer does not support 2nd/3rd argument to setFetchMode()');
throw new InvalidArgumentException('Caching layer does not support 2nd/3rd argument to setFetchMode().');
}

$this->defaultFetchMode = $fetchMode;
Expand Down
15 changes: 8 additions & 7 deletions lib/Doctrine/DBAL/DBALException.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,22 @@ class DBALException extends Exception
*/
public static function driverExceptionDuringQuery(Driver $driver, Throwable $driverEx, $sql, array $params = [])
{
$msg = "An exception occurred while executing '" . $sql . "'";
if ($params) {
$msg .= ' with params ' . self::formatParameters($params);
}
$msg .= ":\n\n" . $driverEx->getMessage();
$message = sprintf(
"An exception occurred while executing \"%s\"%s:\n\n%s.",
$sql,
$params !== [] ? sprintf(' with params %s', self::formatParameters($params)) : '',
$driverEx->getMessage()
);

return static::wrapException($driver, $driverEx, $msg);
return static::wrapException($driver, $driverEx, $message);
}

/**
* @return self
*/
public static function driverException(Driver $driver, Throwable $driverEx)
{
return static::wrapException($driver, $driverEx, 'An exception occurred in driver: ' . $driverEx->getMessage());
return static::wrapException($driver, $driverEx, sprintf('An exception occurred in driver "%s".', $driverEx->getMessage()));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ public function fetch($fetchMode = null, ...$args)
return (object) $assoc;

default:
throw new MysqliException(sprintf("Unknown fetch type '%s'", $fetchMode));
throw new MysqliException(sprintf('Unknown fetch type "%s".', $fetchMode));
}
}

Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public static function convertPositionalToNamedPlaceholders($statement)

if ($currentLiteralDelimiter) {
throw new OCI8Exception(sprintf(
'The statement contains non-terminated string literal starting at offset %d',
'The statement contains non-terminated string literal starting at offset "%d".',
$tokenOffset - 1
));
}
Expand Down Expand Up @@ -407,7 +407,7 @@ public function fetch($fetchMode = null, ...$args)
}

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

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

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

if (self::$fetchModeMap[$fetchMode] === OCI_BOTH) {
Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/DBAL/Driver/PDOStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ private function convertParamType(int $type) : int
if (! isset(self::PARAM_TYPE_MAP[$type])) {
// TODO: next major: throw an exception
@trigger_error(sprintf(
'Using a PDO parameter type (%d given) is deprecated and will cause an error in Doctrine 3.0',
'Using a PDO parameter type ("%d" given) is deprecated and will cause an error in Doctrine 3.0.',
$type
), E_USER_DEPRECATED);

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

Expand Down
8 changes: 4 additions & 4 deletions lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
public function __construct($conn, $sql)
{
if (! is_resource($conn)) {
throw new SQLAnywhereException('Invalid SQL Anywhere connection resource: ' . $conn);
throw new SQLAnywhereException(sprintf('Invalid SQL Anywhere connection resource "%s".', $conn));
}

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

default:
throw new SQLAnywhereException('Unknown type: ' . $type);
throw new SQLAnywhereException(sprintf('Unknown type "%s".', $type));
}

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

default:
throw new SQLAnywhereException('Fetch mode is not supported: ' . $fetchMode);
throw new SQLAnywhereException(sprintf('Fetch mode is not supported "%s".', $fetchMode));
}
}

Expand Down Expand Up @@ -314,7 +314,7 @@ private function castObject(stdClass $sourceObject, $destinationClass, array $ct
if (! is_string($destinationClass)) {
if (! is_object($destinationClass)) {
throw new SQLAnywhereException(sprintf(
'Destination class has to be of type string or object, %s given.',
'Destination class has to be of type string or object, "%s" given.',
gettype($destinationClass)
));
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Driver extends AbstractSQLServerDriver
public function connect(array $params, $username = null, $password = null, array $driverOptions = [])
{
if (! isset($params['host'])) {
throw new SQLSrvException("Missing 'host' in configuration for sqlsrv driver.");
throw new SQLSrvException('Missing "host" in configuration for sqlsrv driver.');
}

$serverName = $params['host'];
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ public function fetch($fetchMode = null, ...$args)
return sqlsrv_fetch_object($this->stmt, $className, $ctorArgs) ?: false;
}

throw new SQLSrvException('Fetch mode is not supported!');
throw new SQLSrvException('Fetch mode is not supported.');
}

/**
Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/DBAL/Exception/DriverRequired.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ public static function new(?string $url = null) : self
if ($url !== null) {
return new self(
sprintf(
"The options 'driver' or 'driverClass' are mandatory if a connection URL without scheme "
. 'is given to DriverManager::getConnection(). Given URL: %s',
'The options "driver" or "driverClass" are mandatory if a connection URL without scheme '
. 'is given to DriverManager::getConnection(). Given URL "%s".',
$url
)
);
}

return new self(
"The options 'driver' or 'driverClass' are mandatory if no PDO "
'The options "driver" or "driverClass" are mandatory if no PDO '
. 'instance is given to DriverManager::getConnection().'
);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Exception/EmptyCriteriaNotAllowed.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ final class EmptyCriteriaNotAllowed extends InvalidArgumentException
{
public static function new() : self
{
return new self('Empty criteria was used, expected non-empty criteria');
return new self('Empty criteria was used, expected non-empty criteria.');
}
}
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Exception/InvalidColumnIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ final class InvalidColumnIndex extends DBALException
public static function new(int $index, int $count) : self
{
return new self(sprintf(
'Invalid column index %d. The statement result contains %d column%s.',
'Invalid column index "%d". The statement result contains "%d" column%s.',
$index,
$count,
$count === 1 ? '' : 's'
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Exception/InvalidDriverClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static function new(string $driverClass) : self
{
return new self(
sprintf(
"The given 'driverClass' %s has to implement the %s interface.",
'The given "driverClass" "%s" has to implement the "%s" interface.',
$driverClass,
Driver::class
)
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Exception/InvalidPdoInstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ final class InvalidPdoInstance extends DBALException
{
public static function new() : self
{
return new self("The 'pdo' option was used in DriverManager::getConnection() but no instance of PDO was given.");
return new self('The "pdo" option was used in DriverManager::getConnection() but no instance of PDO was given.');
}
}
4 changes: 2 additions & 2 deletions lib/Doctrine/DBAL/Exception/InvalidPlatformType.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static function new($invalidPlatform) : self
if (is_object($invalidPlatform)) {
return new self(
sprintf(
"Option 'platform' must be a subtype of '%s', instance of '%s' given",
'Option "platform" must be a subtype of "%s", instance of "%s" given.',
AbstractPlatform::class,
get_class($invalidPlatform)
)
Expand All @@ -30,7 +30,7 @@ public static function new($invalidPlatform) : self

return new self(
sprintf(
"Option 'platform' must be an object and subtype of '%s'. Got '%s'",
'Option "platform" must be an object and subtype of "%s". Got "%s".',
AbstractPlatform::class,
gettype($invalidPlatform)
)
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Exception/InvalidWrapperClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static function new(string $wrapperClass) : self
{
return new self(
sprintf(
"The given 'wrapperClass' %s has to be a subtype of %s.",
'The given "wrapperClass" "%s" has to be a subtype of "%s".',
$wrapperClass,
Connection::class
)
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Exception/MissingSQLParam.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ final class MissingSQLParam extends SQLParserUtilsException
public static function new(string $paramName) : self
{
return new self(
sprintf('Value for :%1$s not found in params array. Params array key should be "%1$s"', $paramName)
sprintf('Value for :%1$s not found in params array. Params array key should be "%1$s"', $paramName) // what is this syntax?
);
}
}
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Exception/MissingSQLType.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ final class MissingSQLType extends SQLParserUtilsException
public static function new(string $typeName) : self
{
return new self(
sprintf('Value for :%1$s not found in types array. Types array key should be "%1$s"', $typeName)
sprintf('Value for :%1$s not found in types array. Types array key should be "%1$s"', $typeName) // what is this syntax?
);
}
}
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Exception/UnknownDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static function new(string $unknownDriverName, array $knownDrivers) : sel
{
return new self(
sprintf(
"The given 'driver' %s is unknown, Doctrine currently supports only the following drivers: %s",
'The given "driver" "%s" is unknown, Doctrine currently supports only the following drivers: %s',
$unknownDriverName,
implode(', ', $knownDrivers)
)
Expand Down
5 changes: 3 additions & 2 deletions lib/Doctrine/DBAL/Id/TableGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Throwable;
use const CASE_LOWER;
use function array_change_key_case;
use function sprintf;

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

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

return $value;
Expand Down
Loading

0 comments on commit ed00719

Please sign in to comment.