Skip to content

Commit 9d47445

Browse files
author
epriestley
committed
Make nonscalar field saves raise a more useful exception from LiskDAO
Summary: If you do something like this: // Missing $user->getPHID()! $object->setUserPHID($user)->save(); ...you get a very unhelpful exception: Expected a scalar or null for %s conversion. Query: %s This doesn't give you any hints about what's wrong. Instead, provide a more useful exception: Unable to insert or update object of class DifferentialRevision, field 'title' has a nonscalar value. Test Plan: {F87614} Reviewers: hach-que, btrahan Reviewed By: btrahan CC: aran Differential Revision: https://secure.phabricator.com/D7725
1 parent f697931 commit 9d47445

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/infrastructure/storage/lisk/LiskDAO.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1244,7 +1244,17 @@ protected function insertRecordIntoDatabase($mode) {
12441244
$columns = array_keys($data);
12451245

12461246
foreach ($data as $key => $value) {
1247-
$data[$key] = qsprintf($conn, '%ns', $value);
1247+
try {
1248+
$data[$key] = qsprintf($conn, '%ns', $value);
1249+
} catch (AphrontQueryParameterException $parameter_exception) {
1250+
throw new PhutilProxyException(
1251+
pht(
1252+
"Unable to insert or update object of class %s, field '%s' ".
1253+
"has a nonscalar value.",
1254+
get_class($this),
1255+
$key),
1256+
$parameter_exception);
1257+
}
12481258
}
12491259
$data = implode(', ', $data);
12501260

0 commit comments

Comments
 (0)