Browse Source

Merge pull request #11764 from cakephp/3.next-better-exception-msg

Improving exception msgs for database types
Mark Story 8 years ago
parent
commit
bb5e86f030

+ 4 - 1
src/Database/Type/BoolType.php

@@ -67,7 +67,10 @@ class BoolType extends Type implements TypeInterface
             return (bool)$value;
         }
 
-        throw new InvalidArgumentException('Cannot convert value to bool');
+        throw new InvalidArgumentException(sprintf(
+            'Cannot convert value of type `%s` to bool',
+            getTypeName($value)
+        ));
     }
 
     /**

+ 4 - 1
src/Database/Type/DecimalType.php

@@ -80,7 +80,10 @@ class DecimalType extends Type implements TypeInterface
             return null;
         }
         if (!is_scalar($value)) {
-            throw new InvalidArgumentException('Cannot convert value to a decimal.');
+            throw new InvalidArgumentException(sprintf(
+                'Cannot convert value of type `%s` to a decimal',
+                getTypeName($value)
+            ));
         }
         if (is_string($value) && is_numeric($value)) {
             return $value;

+ 4 - 1
src/Database/Type/IntegerType.php

@@ -64,7 +64,10 @@ class IntegerType extends Type implements TypeInterface
         }
 
         if (!is_scalar($value)) {
-            throw new InvalidArgumentException('Cannot convert value to integer');
+            throw new InvalidArgumentException(sprintf(
+                'Cannot convert value of type `%s` to integer',
+                getTypeName($value)
+            ));
         }
 
         return (int)$value;

+ 4 - 1
src/Database/Type/StringType.php

@@ -49,7 +49,10 @@ class StringType extends Type implements OptionalConvertInterface, TypeInterface
             return (string)$value;
         }
 
-        throw new InvalidArgumentException('Cannot convert value to string');
+        throw new InvalidArgumentException(sprintf(
+            'Cannot convert value of type `%s` to string',
+            getTypeName($value)
+        ));
     }
 
     /**