Commit 5eb3e046 authored by Marco Pivetta's avatar Marco Pivetta

#869 - DBAL-1293 - Preserving exceptions for invalid conversions

parent a348e332
...@@ -41,7 +41,7 @@ class ConversionException extends \Doctrine\DBAL\DBALException ...@@ -41,7 +41,7 @@ class ConversionException extends \Doctrine\DBAL\DBALException
*/ */
static public function conversionFailed($value, $toType) static public function conversionFailed($value, $toType)
{ {
$value = (strlen($value) > 32) ? substr($value, 0, 20) . "..." : $value; $value = (strlen($value) > 32) ? substr($value, 0, 20) . '...' : $value;
return new self('Could not convert database value "' . $value . '" to Doctrine Type ' . $toType); return new self('Could not convert database value "' . $value . '" to Doctrine Type ' . $toType);
} }
...@@ -53,16 +53,19 @@ class ConversionException extends \Doctrine\DBAL\DBALException ...@@ -53,16 +53,19 @@ class ConversionException extends \Doctrine\DBAL\DBALException
* @param string $value * @param string $value
* @param string $toType * @param string $toType
* @param string $expectedFormat * @param string $expectedFormat
* @param \Exception|null $previous
* *
* @return \Doctrine\DBAL\Types\ConversionException * @return \Doctrine\DBAL\Types\ConversionException
*/ */
static public function conversionFailedFormat($value, $toType, $expectedFormat) static public function conversionFailedFormat($value, $toType, $expectedFormat, \Exception $previous = null)
{ {
$value = (strlen($value) > 32) ? substr($value, 0, 20) . "..." : $value; $value = (strlen($value) > 32) ? substr($value, 0, 20) . '...' : $value;
return new self( return new self(
'Could not convert database value "' . $value . '" to Doctrine Type ' . 'Could not convert database value "' . $value . '" to Doctrine Type ' .
$toType . '. Expected format: ' . $expectedFormat $toType . '. Expected format: ' . $expectedFormat,
0,
$previous
); );
} }
......
...@@ -57,8 +57,8 @@ class DateIntervalType extends Type ...@@ -57,8 +57,8 @@ class DateIntervalType extends Type
try { try {
$interval = new \DateInterval($value); $interval = new \DateInterval($value);
} catch (\Exception $e) { } catch (\Exception $exception) {
throw ConversionException::conversionFailedFormat($value, $this->getName(), 'PY-m-dTH:i:s'); throw ConversionException::conversionFailedFormat($value, $this->getName(), 'PY-m-dTH:i:s', $exception);
} }
return $interval; return $interval;
......
Markdown is supported
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