From 9d474452f9c56f0ab8422be81beaef47854efda3 Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 6 Dec 2013 15:47:40 -0800 Subject: [PATCH] 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 --- src/infrastructure/storage/lisk/LiskDAO.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/infrastructure/storage/lisk/LiskDAO.php b/src/infrastructure/storage/lisk/LiskDAO.php index 4755b2f6ee..36aac50de2 100644 --- a/src/infrastructure/storage/lisk/LiskDAO.php +++ b/src/infrastructure/storage/lisk/LiskDAO.php @@ -1244,7 +1244,17 @@ abstract class LiskDAO { $columns = array_keys($data); foreach ($data as $key => $value) { - $data[$key] = qsprintf($conn, '%ns', $value); + try { + $data[$key] = qsprintf($conn, '%ns', $value); + } catch (AphrontQueryParameterException $parameter_exception) { + throw new PhutilProxyException( + pht( + "Unable to insert or update object of class %s, field '%s' ". + "has a nonscalar value.", + get_class($this), + $key), + $parameter_exception); + } } $data = implode(', ', $data);