From 6d99ad01d72e32a97cb142e27f729f34d47a590a Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Fri, 7 Oct 2022 23:46:08 -0700 Subject: [PATCH] Catch transform errors --- lib/Controller/ApiController.php | 54 ++++++++++++++++++-------------- lib/Db/TimelineQueryFaces.php | 8 ++--- lib/Db/TimelineQueryTags.php | 2 +- 3 files changed, 36 insertions(+), 28 deletions(-) diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php index 8e6f61fa..8ecdba26 100644 --- a/lib/Controller/ApiController.php +++ b/lib/Controller/ApiController.php @@ -178,23 +178,27 @@ class ApiController extends Controller { } // Run actual query - $list = $this->timelineQuery->getDays( - $folder, - $uid, - $recursive, - $archive, - $this->getTransformations(), - ); + try { + $list = $this->timelineQuery->getDays( + $folder, + $uid, + $recursive, + $archive, + $this->getTransformations(), + ); - // Preload some day responses - $this->preloadDays($list, $folder, $recursive, $archive); + // Preload some day responses + $this->preloadDays($list, $folder, $recursive, $archive); - // Add subfolder info if querying non-recursively - if (!$recursive) { - array_unshift($list, $this->getSubfoldersEntry($folder)); + // Add subfolder info if querying non-recursively + if (!$recursive) { + array_unshift($list, $this->getSubfoldersEntry($folder)); + } + + return new JSONResponse($list, Http::STATUS_OK); + } catch (\Exception $e) { + return new JSONResponse(["message" => $e->getMessage()], Http::STATUS_INTERNAL_SERVER_ERROR); } - - return new JSONResponse($list, Http::STATUS_OK); } /** @@ -247,15 +251,19 @@ class ApiController extends Controller { } // Run actual query - $list = $this->timelineQuery->getDay( - $folder, - $uid, - $day_ids, - $recursive, - $archive, - $this->getTransformations(), - ); - return new JSONResponse($list, Http::STATUS_OK); + try { + $list = $this->timelineQuery->getDay( + $folder, + $uid, + $day_ids, + $recursive, + $archive, + $this->getTransformations(), + ); + return new JSONResponse($list, Http::STATUS_OK); + } catch (\Exception $e) { + return new JSONResponse(["message" => $e->getMessage()], Http::STATUS_INTERNAL_SERVER_ERROR); + } } /** diff --git a/lib/Db/TimelineQueryFaces.php b/lib/Db/TimelineQueryFaces.php index a0b12231..ddb4b3bf 100644 --- a/lib/Db/TimelineQueryFaces.php +++ b/lib/Db/TimelineQueryFaces.php @@ -10,10 +10,10 @@ use OCP\Files\Folder; trait TimelineQueryFaces { protected IDBConnection $connection; - public function transformFaceFilter(IQueryBuilder &$query, string $userId, string $faceName) { + public function transformFaceFilter(IQueryBuilder &$query, string $userId, string $faceStr) { // Get title and uid of face user - $faceNames = explode('/', $faceName); - if (count($faceNames) !== 2) return; + $faceNames = explode('/', $faceStr); + if (count($faceNames) !== 2) throw new \Exception("Invalid face query"); $faceUid = $faceNames[0]; $faceName = $faceNames[1]; @@ -23,7 +23,7 @@ trait TimelineQueryFaces { ->where($query->expr()->eq('user_id', $sq->createNamedParameter($faceUid))) ->andWhere($query->expr()->eq('title', $sq->createNamedParameter($faceName))) ->executeQuery()->fetchOne(); - if (!$id) return; + if (!$id) throw new \Exception("Unknown person: $faceStr"); // Join with cluster $query->innerJoin('m', 'recognize_face_detections', 'rfd', $query->expr()->andX( diff --git a/lib/Db/TimelineQueryTags.php b/lib/Db/TimelineQueryTags.php index d89f1714..278bde8b 100644 --- a/lib/Db/TimelineQueryTags.php +++ b/lib/Db/TimelineQueryTags.php @@ -22,7 +22,7 @@ trait TimelineQueryTags { public function transformTagFilter(IQueryBuilder &$query, string $userId, string $tagName) { $tagId = $this->getSystemTagId($query, $tagName); if ($tagId === FALSE) { - $tagId = 0; // cannot abort here; that will show up everything in the response + throw new \Exception("Tag $tagName not found"); } $query->innerJoin('m', 'systemtag_object_mapping', 'stom', $query->expr()->andX(