1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 23:02:42 +01:00

Use PhutilInvalidStateException

Summary: Use `PhutilInvalidStateException`. Depends on D12803.

Test Plan: Unit tests pass.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: Korvin, epriestley

Differential Revision: https://secure.phabricator.com/D12829
This commit is contained in:
Joshua Spence 2015-05-14 07:53:52 +10:00
parent acb45968d8
commit 61b178f44e
34 changed files with 47 additions and 74 deletions

View file

@ -15,8 +15,7 @@ abstract class PhabricatorAuthProvider {
public function getProviderConfig() {
if ($this->providerConfig === null) {
throw new Exception(
'Call attachProviderConfig() before getProviderConfig()!');
throw new PhutilInvalidStateException('attachProviderConfig');
}
return $this->providerConfig;
}

View file

@ -7,9 +7,7 @@ final class CelerityResourceGraph extends AbstractDirectedGraph {
protected function loadEdges(array $nodes) {
if (!$this->graphSet) {
throw new Exception(
'Call setResourceGraph before loading the graph!'
);
throw new PhutilInvalidStateException('setResourceGraph');
}
$graph = $this->getResourceGraph();

View file

@ -122,8 +122,7 @@ final class PhabricatorConfigOption
return $this->enumOptions;
}
throw new Exception(
'Call setEnumOptions() before trying to access them!');
throw new PhutilInvalidStateException('setEnumOptions');
}
public function setKey($key) {

View file

@ -11,7 +11,7 @@ final class PhabricatorConfigSchemaQuery extends Phobject {
protected function getAPI() {
if (!$this->api) {
throw new Exception(pht('Call setAPI() before issuing a query!'));
throw new PhutilInvalidStateException('setAPI');
}
return $this->api;
}

View file

@ -27,7 +27,7 @@ final class PhabricatorDaemonLogEventsView extends AphrontView {
$rows = array();
if (!$this->user) {
throw new Exception('Call setUser() before rendering!');
throw new PhutilInvalidStateException('setUser');
}
foreach ($this->events as $event) {

View file

@ -14,7 +14,7 @@ final class PhabricatorDaemonLogListView extends AphrontView {
$rows = array();
if (!$this->user) {
throw new Exception('Call setUser() before rendering!');
throw new PhutilInvalidStateException('setUser');
}
$env_hash = PhabricatorEnv::calculateEnvironmentHash();

View file

@ -19,7 +19,7 @@ final class DifferentialLocalCommitsView extends AphrontView {
public function render() {
$user = $this->user;
if (!$user) {
throw new Exception('Call setUser() before render()-ing this view.');
throw new PhutilInvalidStateException('setUser');
}
$local = $this->localCommits;

View file

@ -57,10 +57,9 @@ final class DifferentialRevisionListView extends AphrontView {
}
public function render() {
$user = $this->user;
if (!$user) {
throw new Exception('Call setUser() before render()!');
throw new PhutilInvalidStateException('setUser');
}
$fresh = PhabricatorEnv::getEnvConfig('differential.days-fresh');

View file

@ -23,11 +23,11 @@ final class DiffusionLintCountQuery extends PhabricatorQuery {
public function execute() {
if (!$this->paths) {
throw new Exception(pht('Call withPaths() before execute()!'));
throw new PhutilInvalidStateException('withPaths');
}
if (!$this->branchIDs) {
throw new Exception(pht('Call withBranchIDs() before execute()!'));
throw new PhutilInvalidStateException('withBranchIDs');
}
$conn_r = id(new PhabricatorRepositoryCommit())->establishConnection('r');

View file

@ -17,7 +17,7 @@ abstract class DiffusionLowLevelQuery extends Phobject {
public function execute() {
if (!$this->getRepository()) {
throw new Exception('Call setRepository() before execute()!');
throw new PhutilInvalidStateException('setRepository');
}
return $this->executeQuery();

View file

@ -95,16 +95,14 @@ final class DivinerAtom {
public function getDocblockText() {
if ($this->docblockText === null) {
throw new Exception(
pht('Call %s before %s!', 'setDocblockRaw()', 'getDocblockText()'));
throw new PhutilInvalidStateException('setDocblockRaw');
}
return $this->docblockText;
}
public function getDocblockMeta() {
if ($this->docblockMeta === null) {
throw new Exception(
pht('Call %s before %s!', 'setDocblockRaw()', 'getDocblockMeta()'));
throw new PhutilInvalidStateException('setDocblockRaw');
}
return $this->docblockMeta;
}

View file

@ -12,7 +12,7 @@ final class DoorkeeperTagView extends AphrontView {
public function render() {
$xobj = $this->xobj;
if (!$xobj) {
throw new Exception('Call setExternalObject() before render()!');
throw new PhutilInvalidStateException('setExternalObject');
}
$tag_id = celerity_generate_unique_node_id();

View file

@ -227,7 +227,7 @@ final class PhabricatorFileDataController extends PhabricatorFileController {
private function getFile() {
if (!$this->file) {
throw new Exception(pht('Call loadFile() before getFile()!'));
throw new PhutilInvalidStateException('loadFile');
}
return $this->file;
}

View file

@ -33,8 +33,7 @@ final class FundBackerCart extends PhortuneCartImplementation {
$initiative = $this->getInitiative();
if (!$initiative) {
throw new Exception(
pht('Call setInitiative() before building a cart!'));
throw new PhutilInvalidStateException('setInitiative');
}
$cart->setMetadataValue('initiativePHID', $initiative->getPHID());

View file

@ -88,7 +88,7 @@ final class MultimeterControl {
}
if ($this->sampleRate === null) {
throw new Exception(pht('Call setSampleRate() before saving events!'));
throw new PhutilInvalidStateException('setSampleRate');
}
$this->addServiceEvents();

View file

@ -28,7 +28,7 @@ final class PasteEmbedView extends AphrontView {
public function render() {
if (!$this->paste) {
throw new Exception('Call setPaste() before render()!');
throw new PhutilInvalidStateException('setPaste');
}
$lines = phutil_split_lines($this->paste->getContent());

View file

@ -78,7 +78,7 @@ final class PhabricatorObjectQuery
public function getNamedResults() {
if ($this->namedResults === null) {
throw new Exception('Call execute() before getNamedResults()!');
throw new PhutilInvalidStateException('execute');
}
return $this->namedResults;
}

View file

@ -17,7 +17,7 @@ final class PholioMockEmbedView extends AphrontView {
public function render() {
if (!$this->mock) {
throw new Exception('Call setMock() before render()!');
throw new PhutilInvalidStateException('setMock');
}
$mock = $this->mock;

View file

@ -34,8 +34,7 @@ final class PhortuneSubscriptionCart
$subscription = $this->getSubscription();
if (!$subscription) {
throw new Exception(
pht('Call setSubscription() before building a cart!'));
throw new PhutilInvalidStateException('setSubscription');
}
$cart->setMetadataValue('subscriptionPHID', $subscription->getPHID());

View file

@ -55,18 +55,12 @@ final class PhabricatorApplicationSearchController
$engine = $this->getSearchEngine();
if (!$engine) {
throw new Exception(
pht(
'Call %s before delegating to this controller!',
'setEngine()'));
throw new PhutilInvalidStateException('setEngine');
}
$nav = $this->getNavigation();
if (!$nav) {
throw new Exception(
pht(
'Call %s before delegating to this controller!',
'setNavigation()'));
throw new PhutilInvalidStateException('setNavigation');
}
$engine->setViewer($this->getRequest()->getUser());

View file

@ -33,7 +33,7 @@ abstract class PhabricatorApplicationSearchEngine {
protected function requireViewer() {
if (!$this->viewer) {
throw new Exception('Call setViewer() before using an engine!');
throw new PhutilInvalidStateException('setViewer');
}
return $this->viewer;
}

View file

@ -22,7 +22,7 @@ final class SlowvoteEmbedView extends AphrontView {
public function render() {
if (!$this->poll) {
throw new Exception('Call setPoll() before render()!');
throw new PhutilInvalidStateException('setPoll');
}
$poll = $this->poll;

View file

@ -56,7 +56,7 @@ final class PhabricatorSubscriptionsEditor extends PhabricatorEditor {
public function save() {
if (!$this->object) {
throw new Exception('Call setObject() before save()!');
throw new PhutilInvalidStateException('setObject');
}
$actor = $this->requireActor();

View file

@ -133,8 +133,7 @@ final class PhabricatorApplicationTransactionCommentEditor
}
if (!$this->getContentSource()) {
throw new Exception(
'Call setContentSource() before applyEdit()!');
throw new PhutilInvalidStateException('applyEdit');
}
$actor = $this->requireActor();

View file

@ -970,8 +970,7 @@ abstract class PhabricatorApplicationTransactionEditor
array $xactions) {
if (!$this->getContentSource()) {
throw new Exception(
'Call setContentSource() before applyTransactions()!');
throw new PhutilInvalidStateException('setContentSource');
}
// Do a bunch of sanity checks that the incoming transactions are fresh.

View file

@ -149,7 +149,7 @@ class PhabricatorApplicationTransactionCommentView extends AphrontView {
}
if (!$this->getObjectPHID()) {
throw new Exception('Call setObjectPHID() before render()!');
throw new PhutilInvalidStateException('setObjectPHID', 'render');
}
return id(new AphrontFormView())

View file

@ -76,10 +76,10 @@ final class PHUIDiffInlineCommentEditView
public function render() {
if (!$this->uri) {
throw new Exception('Call setSubmitURI() before render()!');
throw new PhutilInvalidStateException('setSubmitURI');
}
if (!$this->user) {
throw new Exception('Call setUser() before render()!');
throw new PhutilInvalidStateException('setUser');
}
$content = phabricator_form(

View file

@ -92,8 +92,7 @@ final class AphrontCursorPagerView extends AphrontView {
public function getFirstPageURI() {
if (!$this->uri) {
throw new Exception(
pht('You must call setURI() before you can call getFirstPageURI().'));
throw new PhutilInvalidStateException('setURI');
}
if (!$this->afterID && !($this->beforeID && $this->moreResults)) {
@ -107,8 +106,7 @@ final class AphrontCursorPagerView extends AphrontView {
public function getPrevPageURI() {
if (!$this->uri) {
throw new Exception(
pht('You must call setURI() before you can call getPrevPageURI().'));
throw new PhutilInvalidStateException('getPrevPageURI');
}
if (!$this->prevPageID) {
@ -122,8 +120,7 @@ final class AphrontCursorPagerView extends AphrontView {
public function getNextPageURI() {
if (!$this->uri) {
throw new Exception(
pht('You must call setURI() before you can call getNextPageURI().'));
throw new PhutilInvalidStateException('setURI');
}
if (!$this->nextPageID) {
@ -137,8 +134,7 @@ final class AphrontCursorPagerView extends AphrontView {
public function render() {
if (!$this->uri) {
throw new Exception(
pht('You must call setURI() before you can call render().'));
throw new PhutilInvalidStateException('setURI');
}
$links = array();

View file

@ -109,8 +109,7 @@ final class AphrontPagerView extends AphrontView {
public function render() {
if (!$this->uri) {
throw new Exception(
pht('You must call setURI() before you can call render().'));
throw new PhutilInvalidStateException('setURI');
}
require_celerity_resource('aphront-pager-view-css');

View file

@ -32,11 +32,7 @@ final class PHUIFormLayoutView extends AphrontView {
public function appendRemarkupInstructions($remarkup) {
if ($this->getUser() === null) {
throw new Exception(
pht(
'Call %s before appending Remarkup to %s.',
'setUser()',
__CLASS__));
throw new PhutilInvalidStateException('setUser');
}
return $this->appendInstructions(

View file

@ -24,11 +24,7 @@ final class PhabricatorRemarkupControl extends AphrontFormTextAreaControl {
$viewer = $this->getUser();
if (!$viewer) {
throw new Exception(
pht(
'Call %s before rendering a %s!',
'setUser()',
__CLASS__));
throw new PhutilInvalidStateException('setUser');
}
// We need to have this if previews render images, since Ajax can not

View file

@ -42,8 +42,11 @@ final class PHUIRemarkupPreviewPanel extends AphrontTagView {
);
if (empty($skins[$skin])) {
$valid = implode(', ', array_keys($skins));
throw new Exception("Invalid skin '{$skin}'. Valid skins are: {$valid}.");
throw new Exception(
pht(
"Invalid skin '%s'. Valid skins are: %s.",
$skin,
implode(', ', array_keys($skins))));
}
$this->skin = $skin;
@ -69,10 +72,10 @@ final class PHUIRemarkupPreviewPanel extends AphrontTagView {
protected function getTagContent() {
if ($this->previewURI === null) {
throw new Exception('Call setPreviewURI() before rendering!');
throw new PhutilInvalidStateException('setPreviewURI');
}
if ($this->controlID === null) {
throw new Exception('Call setControlID() before rendering!');
throw new PhutilInvalidStateException('setControlID');
}
$preview_id = celerity_generate_unique_node_id();

View file

@ -59,7 +59,7 @@ final class PHUICalendarMonthView extends AphrontView {
public function render() {
if (empty($this->user)) {
throw new Exception('Call setUser() before render()!');
throw new PhutilInvalidStateException('setUser');
}
$events = msort($this->events, 'getEpochStart');

View file

@ -62,7 +62,7 @@ final class PhabricatorHovercardView extends AphrontView {
public function render() {
if (!$this->handle) {
throw new Exception('Call setObjectHandle() before calling render()!');
throw new PhutilInvalidStateException('setObjectHandle');
}
$handle = $this->handle;