From b80b851600cbf3832ab93a9e0e0b1e3a16d44311 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 13 May 2014 13:52:33 -0700 Subject: [PATCH] Throw a more tailored exception after failing to resolve a ref Summary: Ref T2683. Throw a more tailored exception to allow callers to distinguish between bad refs (which are expected, if users try to visit garbage branches) and other types of errors. Test Plan: Tried to view branch "alksndfklansdf". Viewed branch "master". Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T2683 Differential Revision: https://secure.phabricator.com/D9094 --- src/__phutil_library_map__.php | 2 ++ .../exception/DiffusionRefNotFoundException.php | 16 ++++++++++++++++ .../diffusion/request/DiffusionRequest.php | 16 +++++++--------- 3 files changed, 25 insertions(+), 9 deletions(-) create mode 100644 src/applications/diffusion/exception/DiffusionRefNotFoundException.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 080ba7456f..fd8be406e7 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -530,6 +530,7 @@ phutil_register_library_map(array( 'DiffusionPushLogListController' => 'applications/diffusion/controller/DiffusionPushLogListController.php', 'DiffusionQuery' => 'applications/diffusion/query/DiffusionQuery.php', 'DiffusionRawDiffQuery' => 'applications/diffusion/query/rawdiff/DiffusionRawDiffQuery.php', + 'DiffusionRefNotFoundException' => 'applications/diffusion/exception/DiffusionRefNotFoundException.php', 'DiffusionRenameHistoryQuery' => 'applications/diffusion/query/DiffusionRenameHistoryQuery.php', 'DiffusionRepositoryController' => 'applications/diffusion/controller/DiffusionRepositoryController.php', 'DiffusionRepositoryCreateController' => 'applications/diffusion/controller/DiffusionRepositoryCreateController.php', @@ -3172,6 +3173,7 @@ phutil_register_library_map(array( ), 'DiffusionQuery' => 'PhabricatorQuery', 'DiffusionRawDiffQuery' => 'DiffusionQuery', + 'DiffusionRefNotFoundException' => 'Exception', 'DiffusionRepositoryController' => 'DiffusionController', 'DiffusionRepositoryCreateController' => 'DiffusionRepositoryEditController', 'DiffusionRepositoryDefaultController' => 'DiffusionController', diff --git a/src/applications/diffusion/exception/DiffusionRefNotFoundException.php b/src/applications/diffusion/exception/DiffusionRefNotFoundException.php new file mode 100644 index 0000000000..8dda27d072 --- /dev/null +++ b/src/applications/diffusion/exception/DiffusionRefNotFoundException.php @@ -0,0 +1,16 @@ +ref = $ref; + return $this; + } + + public function getRef() { + return $this->ref; + } + +} diff --git a/src/applications/diffusion/request/DiffusionRequest.php b/src/applications/diffusion/request/DiffusionRequest.php index db64e1841c..dd20d7380e 100644 --- a/src/applications/diffusion/request/DiffusionRequest.php +++ b/src/applications/diffusion/request/DiffusionRequest.php @@ -4,11 +4,8 @@ * Contains logic to parse Diffusion requests, which have a complicated URI * structure. * - * * @task new Creating Requests * @task uri Managing Diffusion URIs - * - * @group diffusion */ abstract class DiffusionRequest { @@ -644,17 +641,18 @@ abstract class DiffusionRequest { } if ($this->getSupportsBranches()) { - $branch = $this->getResolvableBranchName($this->getBranch()); + $ref = $this->getResolvableBranchName($this->getBranch()); } else { - $branch = 'HEAD'; + $ref = 'HEAD'; } - $results = $this->resolveRefs(array($branch)); + $results = $this->resolveRefs(array($ref)); - $matches = idx($results, $branch, array()); + $matches = idx($results, $ref, array()); if (count($matches) !== 1) { - throw new Exception( - pht('Ref "%s" is ambiguous or does not exist.', $branch)); + $message = pht('Ref "%s" is ambiguous or does not exist.', $ref); + throw id(new DiffusionRefNotFoundException($message)) + ->setRef($ref); } $this->stableCommit = idx(head($matches), 'identifier'); -- 2.51.2