From 4761cb8d739036956fea43779f3f426448d01a27 Mon Sep 17 00:00:00 2001 From: Joshua Spence Date: Thu, 18 Jun 2015 07:06:37 +1000 Subject: [PATCH] Use PhutilInvalidStateException Summary: Use `PhutilInvalidStateException` where appropriate. Test Plan: Eyeball it. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: epriestley, Korvin Differential Revision: https://secure.phabricator.com/D13327 --- src/aphront/AphrontController.php | 16 ++++++++++------ .../auth/engine/PhabricatorAuthInviteEngine.php | 2 +- .../view/ConpherenceTransactionView.php | 2 +- .../PhabricatorDashboardPanelRenderingEngine.php | 4 +--- .../markup/PhabricatorMarkupEngine.php | 5 +---- .../form/control/AphrontFormPolicyControl.php | 4 ++-- .../form/control/AphrontFormTokenizerControl.php | 7 +++++-- src/view/layout/AphrontSideNavFilterView.php | 4 ++-- src/view/layout/PhabricatorActionListView.php | 2 +- src/view/phui/PHUITagView.php | 2 +- 10 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/aphront/AphrontController.php b/src/aphront/AphrontController.php index 55c2f9f30e..df6cff6abc 100644 --- a/src/aphront/AphrontController.php +++ b/src/aphront/AphrontController.php @@ -35,8 +35,10 @@ abstract class AphrontController extends Phobject { throw new PhutilMethodNotImplementedException( pht( - 'Controllers must implement either handleRequest() (recommended) '. - 'or processRequest() (deprecated).')); + 'Controllers must implement either %s (recommended) '. + 'or %s (deprecated).', + 'handleRequest()', + 'processRequest()')); } final public function setRequest(AphrontRequest $request) { @@ -46,7 +48,7 @@ abstract class AphrontController extends Phobject { final public function getRequest() { if (!$this->request) { - throw new Exception(pht('Call setRequest() before getRequest()!')); + throw new PhutilInvalidStateException('setRequest'); } return $this->request; } @@ -81,10 +83,12 @@ abstract class AphrontController extends Phobject { } public function getDefaultResourceSource() { - throw new Exception( + throw new MethodNotImplementedException( pht( - 'A Controller must implement getDefaultResourceSource() before you '. - 'can invoke requireResource() or initBehavior().')); + 'A Controller must implement %s before you can invoke %s or %s.', + 'getDefaultResourceSource()', + 'requireResource()', + 'initBehavior()')); } public function requireResource($symbol) { diff --git a/src/applications/auth/engine/PhabricatorAuthInviteEngine.php b/src/applications/auth/engine/PhabricatorAuthInviteEngine.php index bbdb6000f8..f1cb45483e 100644 --- a/src/applications/auth/engine/PhabricatorAuthInviteEngine.php +++ b/src/applications/auth/engine/PhabricatorAuthInviteEngine.php @@ -18,7 +18,7 @@ final class PhabricatorAuthInviteEngine extends Phobject { public function getViewer() { if (!$this->viewer) { - throw new Exception(pht('Call setViewer() before getViewer()!')); + throw new PhutilInvalidStateException('setViewer'); } return $this->viewer; } diff --git a/src/applications/conpherence/view/ConpherenceTransactionView.php b/src/applications/conpherence/view/ConpherenceTransactionView.php index 57bec773fc..fa94b26ba6 100644 --- a/src/applications/conpherence/view/ConpherenceTransactionView.php +++ b/src/applications/conpherence/view/ConpherenceTransactionView.php @@ -64,7 +64,7 @@ final class ConpherenceTransactionView extends AphrontView { public function render() { $viewer = $this->getUser(); if (!$viewer) { - throw new Exception(pht('Call setUser() before render()!')); + throw new PhutilInvalidStateException('setUser'); } require_celerity_resource('conpherence-transaction-css'); diff --git a/src/applications/dashboard/engine/PhabricatorDashboardPanelRenderingEngine.php b/src/applications/dashboard/engine/PhabricatorDashboardPanelRenderingEngine.php index dfba37eaa5..fcf1e3d7c9 100644 --- a/src/applications/dashboard/engine/PhabricatorDashboardPanelRenderingEngine.php +++ b/src/applications/dashboard/engine/PhabricatorDashboardPanelRenderingEngine.php @@ -277,9 +277,7 @@ final class PhabricatorDashboardPanelRenderingEngine extends Phobject { */ private function detectRenderingCycle(PhabricatorDashboardPanel $panel) { if ($this->parentPanelPHIDs === null) { - throw new Exception( - pht( - 'You must call setParentPanelPHIDs() before rendering panels.')); + throw new PhutilInvalidStateException('setParentPanelPHIDs'); } $max_depth = 4; diff --git a/src/infrastructure/markup/PhabricatorMarkupEngine.php b/src/infrastructure/markup/PhabricatorMarkupEngine.php index 1694d42db0..f00c8a1ef5 100644 --- a/src/infrastructure/markup/PhabricatorMarkupEngine.php +++ b/src/infrastructure/markup/PhabricatorMarkupEngine.php @@ -198,10 +198,7 @@ final class PhabricatorMarkupEngine extends Phobject { } if (!isset($this->objects[$key]['output'])) { - throw new Exception( - pht( - 'Call %s before using results.', - 'process()')); + throw new PhutilInvalidStateException('process'); } } diff --git a/src/view/form/control/AphrontFormPolicyControl.php b/src/view/form/control/AphrontFormPolicyControl.php index 7c4fefcac6..f062bb1b5a 100644 --- a/src/view/form/control/AphrontFormPolicyControl.php +++ b/src/view/form/control/AphrontFormPolicyControl.php @@ -162,10 +162,10 @@ final class AphrontFormPolicyControl extends AphrontFormControl { protected function renderInput() { if (!$this->object) { - throw new Exception(pht('Call setPolicyObject() before rendering!')); + throw new PhutilInvalidStateException('setPolicyObject'); } if (!$this->capability) { - throw new Exception(pht('Call setCapability() before rendering!')); + throw new PhutilInvalidStateException('setCapability'); } $policy = $this->object->getPolicy($this->capability); diff --git a/src/view/form/control/AphrontFormTokenizerControl.php b/src/view/form/control/AphrontFormTokenizerControl.php index 841c1006e5..fd25f66a1f 100644 --- a/src/view/form/control/AphrontFormTokenizerControl.php +++ b/src/view/form/control/AphrontFormTokenizerControl.php @@ -109,8 +109,11 @@ final class AphrontFormTokenizerControl extends AphrontFormControl { if (!$viewer) { throw new Exception( pht( - 'Call setUser() before rendering tokenizers. Use appendControl() '. - 'on AphrontFormView to do this easily.')); + 'Call %s before rendering tokenizers. '. + 'Use %s on %s to do this easily.', + 'setUser()', + 'appendControl()', + 'AphrontFormView')); } $values = nonempty($this->getValue(), array()); diff --git a/src/view/layout/AphrontSideNavFilterView.php b/src/view/layout/AphrontSideNavFilterView.php index fe8025026b..5e85f89254 100644 --- a/src/view/layout/AphrontSideNavFilterView.php +++ b/src/view/layout/AphrontSideNavFilterView.php @@ -187,10 +187,10 @@ final class AphrontSideNavFilterView extends AphrontView { public function render() { if ($this->menu->getItems()) { if (!$this->baseURI) { - throw new Exception(pht('Call setBaseURI() before render()!')); + throw new PhutilInvalidStateException('setBaseURI'); } if ($this->selectedFilter === false) { - throw new Exception(pht('Call selectFilter() before render()!')); + throw new PhutilInvalidStateException('selectFilter'); } } diff --git a/src/view/layout/PhabricatorActionListView.php b/src/view/layout/PhabricatorActionListView.php index 6db62c129e..82449951d7 100644 --- a/src/view/layout/PhabricatorActionListView.php +++ b/src/view/layout/PhabricatorActionListView.php @@ -29,7 +29,7 @@ final class PhabricatorActionListView extends AphrontView { public function render() { if (!$this->user) { - throw new Exception(pht('Call setUser() before render()!')); + throw new PhutilInvalidStateException('setUser'); } $event = new PhabricatorEvent( diff --git a/src/view/phui/PHUITagView.php b/src/view/phui/PHUITagView.php index 8f49caa82a..439feb77c5 100644 --- a/src/view/phui/PHUITagView.php +++ b/src/view/phui/PHUITagView.php @@ -144,7 +144,7 @@ final class PHUITagView extends AphrontTagView { protected function getTagContent() { if (!$this->type) { - throw new Exception(pht('You must call setType() before render()!')); + throw new PhutilInvalidStateException('setType', 'render'); } $color = null;