diff --git a/src/Core/DB/DB.php b/src/Core/DB/DB.php index b2586a1225..3cd523a5d8 100644 --- a/src/Core/DB/DB.php +++ b/src/Core/DB/DB.php @@ -32,6 +32,7 @@ namespace App\Core\DB; +use App\Util\Exception\DuplicateFoundException; use App\Util\Exception\NotFoundException; use App\Util\Formatting; use Doctrine\Common\Collections\Criteria; @@ -163,7 +164,11 @@ abstract class DB if (count($res) == 1) { return $res[0]; } else { - throw new NotFoundException("No value in table {$table} matches the requested criteria"); + if (count($res) == 0) { + throw new NotFoundException("No value in table {$table} matches the requested criteria"); + } else { + throw new DuplicateFoundException("Multiple values in table {$table} match the requested criteria"); + } } } diff --git a/src/Util/Exception/DuplicateFoundException.php b/src/Util/Exception/DuplicateFoundException.php new file mode 100644 index 0000000000..5dda046991 --- /dev/null +++ b/src/Util/Exception/DuplicateFoundException.php @@ -0,0 +1,39 @@ +. +// }}} + +/** + * Duplicate value found in DB when not expected + * + * @category Exception + * @package GNUsocial + * + * @author Hugo Sales + * @copyright 2021 Free Software Foundation, Inc http://www.fsf.org + * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later + */ + +namespace App\Util\Exception; + +class DuplicateFoundException extends ServerException +{ + public function __construct(string $m) + { + parent::__construct($m); + } +}