Skip to content

Commit

Permalink
Merge pull request #11764 from cakephp/3.next-better-exception-msg
Browse files Browse the repository at this point in the history
Improving exception msgs for database types
  • Loading branch information
markstory committed Feb 27, 2018
2 parents d5c11df + c9c0eef commit bb5e86f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/Database/Type/BoolType.php
Expand Up @@ -67,7 +67,10 @@ public function toDatabase($value, Driver $driver)
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)
));
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/Database/Type/DecimalType.php
Expand Up @@ -80,7 +80,10 @@ public function toDatabase($value, Driver $driver)
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;
Expand Down
5 changes: 4 additions & 1 deletion src/Database/Type/IntegerType.php
Expand Up @@ -64,7 +64,10 @@ public function toDatabase($value, Driver $driver)
}

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;
Expand Down
5 changes: 4 additions & 1 deletion src/Database/Type/StringType.php
Expand Up @@ -49,7 +49,10 @@ public function toDatabase($value, Driver $driver)
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)
));
}

/**
Expand Down

0 comments on commit bb5e86f

Please sign in to comment.