Page MenuHomePhabricator

D12803.id30847.diff
No OneTemporary

D12803.id30847.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -190,6 +190,8 @@
'PhutilInRequestKeyValueCache' => 'cache/PhutilInRequestKeyValueCache.php',
'PhutilInteractiveEditor' => 'console/PhutilInteractiveEditor.php',
'PhutilInvalidRuleParserGeneratorException' => 'parser/generator/exception/PhutilInvalidRuleParserGeneratorException.php',
+ 'PhutilInvalidStateException' => 'exception/PhutilInvalidStateException.php',
+ 'PhutilInvalidStateExceptionTestCase' => 'exception/__tests__/PhutilInvalidStateExceptionTestCase.php',
'PhutilInvisibleSyntaxHighlighter' => 'markup/syntax/highlighter/PhutilInvisibleSyntaxHighlighter.php',
'PhutilIrreducibleRuleParserGeneratorException' => 'parser/generator/exception/PhutilIrreducibleRuleParserGeneratorException.php',
'PhutilJIRAAuthAdapter' => 'auth/PhutilJIRAAuthAdapter.php',
@@ -621,6 +623,8 @@
'PhutilIPAddressTestCase' => 'PhutilTestCase',
'PhutilInRequestKeyValueCache' => 'PhutilKeyValueCache',
'PhutilInvalidRuleParserGeneratorException' => 'PhutilParserGeneratorException',
+ 'PhutilInvalidStateException' => 'Exception',
+ 'PhutilInvalidStateExceptionTestCase' => 'PhutilTestCase',
'PhutilIrreducibleRuleParserGeneratorException' => 'PhutilParserGeneratorException',
'PhutilJIRAAuthAdapter' => 'PhutilOAuth1AuthAdapter',
'PhutilJSONParserException' => 'Exception',
diff --git a/src/exception/PhutilInvalidStateException.php b/src/exception/PhutilInvalidStateException.php
new file mode 100644
--- /dev/null
+++ b/src/exception/PhutilInvalidStateException.php
@@ -0,0 +1,30 @@
+<?php
+
+final class PhutilInvalidStateException extends Exception {
+ private $callee;
+ private $function;
+
+ public function __construct($function, $callee = null) {
+ if ($callee === null) {
+ $callee = idx(debug_backtrace(), 1);
+ $callee = idx($callee, 'function');
+ }
+
+ $this->callee = $callee;
+ $this->function = $function;
+
+ parent::__construct(
+ pht(
+ 'Call %s before calling %s!',
+ $this->function.'()',
+ $this->callee.'()'));
+ }
+
+ public function getCallee() {
+ return $this->callee;
+ }
+
+ public function getFunction() {
+ return $this->function;
+ }
+}
diff --git a/src/exception/__tests__/PhutilInvalidStateExceptionTestCase.php b/src/exception/__tests__/PhutilInvalidStateExceptionTestCase.php
new file mode 100644
--- /dev/null
+++ b/src/exception/__tests__/PhutilInvalidStateExceptionTestCase.php
@@ -0,0 +1,17 @@
+<?php
+
+final class PhutilInvalidStateExceptionTestCase extends PhutilTestCase {
+
+ public function testException() {
+ try {
+ throw new PhutilInvalidStateException('someMethod');
+ } catch (PhutilInvalidStateException $ex) {
+ $this->assertEqual(
+ __FUNCTION__,
+ $ex->getCallee());
+ $this->assertEqual(
+ 'someMethod',
+ $ex->getFunction());
+ }
+ }
+}

File Metadata

Mime Type
text/plain
Expires
Mar 20 2025, 8:29 PM (6 w, 4 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7714445
Default Alt Text
D12803.id30847.diff (2 KB)

Event Timeline