From 356b2781bcadf43aaf7e4d8086fcc8ab867a38cb Mon Sep 17 00:00:00 2001 From: Arturas Moskvinas Date: Thu, 2 Aug 2018 17:41:40 +0300 Subject: [PATCH] Gracefully fail request if non existing callsign is passed to getrecentcommitsbypath instead of crashing Summary: `diffusion.getrecentcommitsbypath` fails with 500 error when non existing callsign is passed: ``` >>> UNRECOVERABLE FATAL ERROR <<< Call to a member function getCommit() on null ``` Expected Behavior: Return more graceful error notifying caller that such callsign/repository does not exist Reproduction steps: Open conduit: https://secure.phabricator.com/conduit/method/diffusion.getrecentcommitsbypath/ Enter: callsign: "obviouslynotexisting" path: "/random" Click call method Test Plan: after applying patch - call no longer fails with 500s Reviewers: Pawka, epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: Korvin Differential Revision: https://secure.phabricator.com/D19558 --- ...DiffusionGetRecentCommitsByPathConduitAPIMethod.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/applications/diffusion/conduit/DiffusionGetRecentCommitsByPathConduitAPIMethod.php b/src/applications/diffusion/conduit/DiffusionGetRecentCommitsByPathConduitAPIMethod.php index 002805ac4e..65bc5f69da 100644 --- a/src/applications/diffusion/conduit/DiffusionGetRecentCommitsByPathConduitAPIMethod.php +++ b/src/applications/diffusion/conduit/DiffusionGetRecentCommitsByPathConduitAPIMethod.php @@ -23,6 +23,12 @@ final class DiffusionGetRecentCommitsByPathConduitAPIMethod ); } + protected function defineErrorTypes() { + return array( + 'ERR_NOT_FOUND' => pht('Repository was not found.'), + ); + } + protected function defineReturnType() { return 'nonempty list'; } @@ -36,6 +42,10 @@ final class DiffusionGetRecentCommitsByPathConduitAPIMethod 'branch' => $request->getValue('branch'), )); + if ($drequest === null) { + throw new ConduitException('ERR_NOT_FOUND'); + } + $limit = nonempty( $request->getValue('limit'), self::DEFAULT_LIMIT);