Skip to content

Commit aa50390

Browse files
committed
make sql exception more generic
1 parent 567d9d2 commit aa50390

File tree

5 files changed

+14
-10
lines changed

5 files changed

+14
-10
lines changed

resources/autoload.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
require_once __DIR__ . "/lib/UnityRedis.php";
2626
require_once __DIR__ . "/lib/UnityGithub.php";
2727
require_once __DIR__ . "/lib/exceptions/PhpUnitNoDieException.php";
28-
require_once __DIR__ . "/lib/exceptions/UnitySQLNoSuchRequestException.php";
28+
require_once __DIR__ . "/lib/exceptions/UnitySQLRecordNotFound.php";
2929

3030
// run init script
3131
require __DIR__ . "/init.php";

resources/lib/UnitySQL.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use PDO;
66
use PDOException;
7-
use UnityWebPortal\lib\exceptions\UnitySQLNoSuchRequestException;
7+
use UnityWebPortal\lib\exceptions\UnitySQLRecordNotFound;
88

99
class UnitySQL
1010
{
@@ -147,7 +147,7 @@ public function getRequest($user, $dest)
147147
{
148148
$results = $this->search(self::TABLE_REQS, ["request_for" => $dest]);
149149
if (count($results) == 0) {
150-
throw new UnitySQLNoSuchRequestException("no such request: uid='$user' request_for='$dest'");
150+
throw new UnitySQLRecordNotFound("no such request: uid='$user' request_for='$dest'");
151151
}
152152
if (count($results) > 1) {
153153
throw new Exception("too many requests for uid='$user' request_for='$dest'");
@@ -160,7 +160,7 @@ public function requestExists($requestor, $dest = self::REQUEST_BECOME_PI)
160160
try {
161161
self::getRequest($requestor, $dest);
162162
return true;
163-
} catch (UnitySQLNoSuchRequestException) {
163+
} catch (UnitySQLRecordNotFound) {
164164
return false;
165165
}
166166
}
@@ -266,6 +266,9 @@ public function deleteAccountDeletionRequest($uid)
266266
public function getSiteVar($name): string
267267
{
268268
$results = $this->search(self::TABLE_SITEVARS, ["name" => $name]);
269+
if (count($results) == 0) {
270+
throw new UnitySQLRecordNotFound($name);
271+
}
269272
assert(count($results) == 1);
270273
return $results[0]["value"];
271274
}

resources/lib/exceptions/UnitySQLNoSuchRequestException.php

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
namespace UnityWebPortal\lib\exceptions;
3+
4+
class UnitySQLRecordNotFound extends \Exception
5+
{
6+
}

test/phpunit-bootstrap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
require_once __DIR__ . "/../resources/lib/UnityRedis.php";
2020
require_once __DIR__ . "/../resources/lib/UnityGithub.php";
2121
require_once __DIR__ . "/../resources/lib/exceptions/PhpUnitNoDieException.php";
22+
require_once __DIR__ . "/../resources/lib/exceptions/UnitySQLRecordNotFound.php";
2223

2324
$GLOBALS["PHPUNIT_NO_DIE_PLEASE"] = true;
2425

0 commit comments

Comments
 (0)