summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2016-08-15 20:22:48 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2016-08-15 20:37:19 +0200
commitc044aa34fa06ecef90dde2f6793e5e4d77f5200b (patch)
treec4badcdd7be65e3de64c6597b05ad9de16a78b11 /lib/private
parent396678c9ce98c901384c827e3a45173cf6c8c5bb (diff)
downloadnextcloud-server-c044aa34fa06ecef90dde2f6793e5e4d77f5200b.tar.gz
nextcloud-server-c044aa34fa06ecef90dde2f6793e5e4d77f5200b.zip
Make the capabilities manager more error proof
If an app registers an invalid capabilty we should not crash hard. Instead we should catch the exception. Log it (error) and carry on. * Added tests
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/CapabilitiesManager.php21
-rw-r--r--lib/private/Server.php2
2 files changed, 18 insertions, 5 deletions
diff --git a/lib/private/CapabilitiesManager.php b/lib/private/CapabilitiesManager.php
index 99a37d652a1..159fa97c708 100644
--- a/lib/private/CapabilitiesManager.php
+++ b/lib/private/CapabilitiesManager.php
@@ -22,15 +22,22 @@
namespace OC;
+use OCP\AppFramework\QueryException;
use OCP\Capabilities\ICapability;
+use OCP\ILogger;
class CapabilitiesManager {
- /**
- * @var \Closure[]
- */
+ /** @var \Closure[] */
private $capabilities = array();
+ /** @var ILogger */
+ private $logger;
+
+ public function __construct(ILogger $logger) {
+ $this->logger = $logger;
+ }
+
/**
* Get an array of al the capabilities that are registered at this manager
*
@@ -40,7 +47,13 @@ class CapabilitiesManager {
public function getCapabilities() {
$capabilities = [];
foreach($this->capabilities as $capability) {
- $c = $capability();
+ try {
+ $c = $capability();
+ } catch (QueryException $e) {
+ $this->logger->error('CapabilitiesManager: {message}', ['app' => 'core', 'message' => $e->getMessage()]);
+ continue;
+ }
+
if ($c instanceof ICapability) {
$capabilities = array_replace_recursive($capabilities, $c->getCapabilities());
} else {
diff --git a/lib/private/Server.php b/lib/private/Server.php
index d5808d7f17c..03c3633c9f2 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -629,7 +629,7 @@ class Server extends ServerContainer implements IServerContainer {
return new Manager();
});
$this->registerService('CapabilitiesManager', function (Server $c) {
- $manager = new \OC\CapabilitiesManager();
+ $manager = new \OC\CapabilitiesManager($c->getLogger());
$manager->registerCapability(function () use ($c) {
return new \OC\OCS\CoreCapabilities($c->getConfig());
});