mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-18 21:02:41 +01:00
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
This commit is contained in:
parent
ce3f9211e4
commit
b80b851600
3 changed files with 25 additions and 9 deletions
|
@ -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',
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
final class DiffusionRefNotFoundException extends Exception {
|
||||
|
||||
private $ref;
|
||||
|
||||
public function setRef($ref) {
|
||||
$this->ref = $ref;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getRef() {
|
||||
return $this->ref;
|
||||
}
|
||||
|
||||
}
|
|
@ -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');
|
||||
|
|
Loading…
Reference in a new issue