Skip to content

Commit

Permalink
Improve exception messages on AbstractModel
Browse files Browse the repository at this point in the history
Amends 16d41eb
  • Loading branch information
mcaskill committed Mar 3, 2020
1 parent 16d41eb commit 7771bd4
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/Charcoal/Model/AbstractModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,12 +368,22 @@ public function loadFromL10n($key, $value, array $langs)

$sth = $source->dbQuery($sql, $binds);
if ($sth === false) {
throw new PDOException('Could not load item.');
throw new PDOException(sprintf(
'Could not load model [%s] for localized column "%s" [%s]',
get_class($this),
$fieldName,
(is_object($value) ? get_class($value) : (is_string($value) ? $value : gettype($value)))
));
}

$data = $sth->fetch(PDO::FETCH_ASSOC);
if (!$data || !isset($data['_lang'])) {
throw new PDOException('Could not load item.');
throw new PDOException(sprintf(
'Unable to retrieve model [%s] data for localized column "%s" [%s]',
get_class($this),
$fieldName,
(is_object($value) ? get_class($value) : (is_string($value) ? $value : gettype($value)))
));
}

$lang = $data['_lang'];
Expand Down Expand Up @@ -481,7 +491,7 @@ protected function createSource()

if (!$sourceConfig) {
throw new UnexpectedValueException(sprintf(
'Can not create source for [%s]: invalid metadata (can not load source\'s configuration).',
'Can not create source for model [%s]: Invalid metadata (can not load source\'s configuration)',
get_class($this)
));
}
Expand Down

0 comments on commit 7771bd4

Please sign in to comment.