summaryrefslogtreecommitdiffstats
path: root/lib/private/CapabilitiesManager.php
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/CapabilitiesManager.php
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/CapabilitiesManager.php')
-rw-r--r--lib/private/CapabilitiesManager.php21
1 files changed, 17 insertions, 4 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 {