summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorBernhard Posselt <BernhardPosselt@users.noreply.github.com>2016-04-04 10:55:46 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2016-04-04 10:55:46 +0200
commit4887f0f9b5b9dc58e9b8af0a871a81ee85974694 (patch)
tree70c33a2e50d150bae015ebe2350025e36091bd77 /lib
parent64d68eb2da2c7a190eb7dda1f78df821b907ce83 (diff)
downloadnextcloud-server-4887f0f9b5b9dc58e9b8af0a871a81ee85974694.tar.gz
nextcloud-server-4887f0f9b5b9dc58e9b8af0a871a81ee85974694.zip
Add better messages for sometimes obscure exceptions
* add better messages for sometimes obscure exceptions * fix formatting
Diffstat (limited to 'lib')
-rw-r--r--lib/public/appframework/db/mapper.php29
1 files changed, 27 insertions, 2 deletions
diff --git a/lib/public/appframework/db/mapper.php b/lib/public/appframework/db/mapper.php
index 3bc9fbcefc6..2e97b06802a 100644
--- a/lib/public/appframework/db/mapper.php
+++ b/lib/public/appframework/db/mapper.php
@@ -282,18 +282,43 @@ abstract class Mapper {
if($row === false || $row === null){
$stmt->closeCursor();
- throw new DoesNotExistException('No matching entry found');
+ $msg = $this->buildDebugMessage(
+ 'Did expect one result but found none when executing', $sql, $params, $limit, $offset
+ );
+ throw new DoesNotExistException($msg);
}
$row2 = $stmt->fetch();
$stmt->closeCursor();
//MDB2 returns null, PDO and doctrine false when no row is available
if( ! ($row2 === false || $row2 === null )) {
- throw new MultipleObjectsReturnedException('More than one result');
+ $msg = $this->buildDebugMessage(
+ 'Did not expect more than one result when executing', $sql, $params, $limit, $offset
+ );
+ throw new MultipleObjectsReturnedException($msg);
} else {
return $row;
}
}
+ /**
+ * Builds an error message by prepending the $msg to an error message which
+ * has the parameters
+ * @see findEntity
+ * @param string $sql the sql query
+ * @param array $params the parameters of the sql query
+ * @param int $limit the maximum number of rows
+ * @param int $offset from which row we want to start
+ * @return string formatted error message string
+ * @since 9.1.0
+ */
+ private function buildDebugMessage($msg, $sql, array $params=[], $limit=null, $offset=null) {
+ return $msg .
+ ': query "' . $sql . '"; ' .
+ 'parameters ' . print_r($params, true) . '; ' .
+ 'limit "' . $limit . '"; '.
+ 'offset "' . $offset . '"';
+ }
+
/**
* Creates an entity from a row. Automatically determines the entity class