]> source.dussan.org Git - nextcloud-server.git/commitdiff
Don't use a generic exception
authorJoas Schilling <coding@schilljs.com>
Mon, 20 Mar 2017 09:02:05 +0000 (10:02 +0100)
committerJoas Schilling <coding@schilljs.com>
Mon, 20 Mar 2017 09:33:16 +0000 (10:33 +0100)
Signed-off-by: Joas Schilling <coding@schilljs.com>
lib/private/App/AppManager.php
lib/public/App/IAppManager.php
tests/lib/App/ManagerTest.php

index 6c1f5ba6940b013bfd561318cff55ff071dfeb62..42777266249e5895f62b8ccb10d64499428249ef 100644 (file)
@@ -32,7 +32,6 @@
 namespace OC\App;
 
 use OCP\App\AppPathNotFoundException;
-use OC_App;
 use OCP\App\IAppManager;
 use OCP\App\ManagerEvent;
 use OCP\IAppConfig;
@@ -211,12 +210,12 @@ class AppManager implements IAppManager {
         * Enable an app for every user
         *
         * @param string $appId
-        * @throws \Exception
+        * @throws AppPathNotFoundException
         */
        public function enableApp($appId) {
-               if(OC_App::getAppPath($appId) === false) {
-                       throw new \Exception("$appId can't be enabled since it is not installed.");
-               }
+               // Check if app exists
+               $this->getAppPath($appId);
+
                $this->installedAppsCache[$appId] = 'yes';
                $this->appConfig->setValue($appId, 'enabled', 'yes');
                $this->dispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE, new ManagerEvent(
index 72c99777124a945ec15606c661d9d416d288f47d..107297bc890c7c7809f4d38ae27ef9de2941d45e 100644 (file)
@@ -57,6 +57,7 @@ interface IAppManager {
         * Enable an app for every user
         *
         * @param string $appId
+        * @throws AppPathNotFoundException
         * @since 8.0.0
         */
        public function enableApp($appId);
index 8b23168938c24bf786ef2108e4b3f27d81ea31b0..59ef9a36bf2243d89c3be77d013d1fb91c61c487 100644 (file)
@@ -134,10 +134,11 @@ class ManagerTest extends TestCase {
                try {
                        $this->manager->enableApp('some_random_name_which_i_hope_is_not_an_app');
                        $this->assertFalse(true, 'If this line is reached the expected exception is not thrown.');
-               } catch (\Exception $e) {
-                       // excpetion is expected
-                       $this->assertEquals("some_random_name_which_i_hope_is_not_an_app can't be enabled since it is not installed.", $e->getMessage());
+               } catch (AppPathNotFoundException $e) {
+                       // Exception is expected
+                       $this->assertEquals('Could not find path for some_random_name_which_i_hope_is_not_an_app', $e->getMessage());
                }
+
                $this->assertEquals('no', $this->appConfig->getValue(
                        'some_random_name_which_i_hope_is_not_an_app', 'enabled', 'no'
                ));