Merge pull request #20497 from owncloud/bubble_up_hint_exception

Bubble up hint exceptions in hooks, so the user can see the hint
This commit is contained in:
Thomas Müller 2016-01-13 17:36:42 +01:00
commit d1010696a1
2 changed files with 36 additions and 33 deletions

View File

@ -56,7 +56,7 @@ class OC_Hook{
self::$registered[$signalClass][$signalName] = array(); self::$registered[$signalClass][$signalName] = array();
} }
// dont connect hooks twice // don't connect hooks twice
foreach (self::$registered[$signalClass][$signalName] as $hook) { foreach (self::$registered[$signalClass][$signalName] as $hook) {
if ($hook['class'] === $slotClass and $hook['name'] === $slotName) { if ($hook['class'] === $slotClass and $hook['name'] === $slotName) {
return false; return false;
@ -79,8 +79,8 @@ class OC_Hook{
* @param string $signalName name of signal * @param string $signalName name of signal
* @param mixed $params default: array() array with additional data * @param mixed $params default: array() array with additional data
* @return bool true if slots exists or false if not * @return bool true if slots exists or false if not
* @throws \OC\ServerNotAvailableException * @throws \OC\HintException
* Emits a signal. To get data from the slot use references! * @throws \OC\ServerNotAvailableException Emits a signal. To get data from the slot use references!
* *
* TODO: write example * TODO: write example
*/ */
@ -104,38 +104,30 @@ class OC_Hook{
call_user_func( array( $i["class"], $i["name"] ), $params ); call_user_func( array( $i["class"], $i["name"] ), $params );
} catch (Exception $e){ } catch (Exception $e){
self::$thrownExceptions[] = $e; self::$thrownExceptions[] = $e;
$class = $i["class"]; \OC::$server->getLogger()->logException($e);
if (is_object($i["class"])) { if($e instanceof \OC\HintException) {
$class = get_class($i["class"]); throw $e;
} }
$message = $e->getMessage();
if (empty($message)) {
$message = get_class($e);
}
\OCP\Util::writeLog('hook',
'error while running hook (' . $class . '::' . $i["name"] . '): ' . $message,
\OCP\Util::ERROR);
if($e instanceof \OC\ServerNotAvailableException) { if($e instanceof \OC\ServerNotAvailableException) {
throw $e; throw $e;
} }
} }
} }
// return true
return true; return true;
} }
/** /**
* clear hooks * clear hooks
* @param string $signalclass * @param string $signalClass
* @param string $signalname * @param string $signalName
*/ */
static public function clear($signalclass='', $signalname='') { static public function clear($signalClass='', $signalName='') {
if($signalclass) { if ($signalClass) {
if($signalname) { if ($signalName) {
self::$registered[$signalclass][$signalname]=array(); self::$registered[$signalClass][$signalName]=array();
}else{ }else{
self::$registered[$signalclass]=array(); self::$registered[$signalClass]=array();
} }
}else{ }else{
self::$registered=array(); self::$registered=array();

View File

@ -32,6 +32,7 @@ use InterfaSys\LogNormalizer\Normalizer;
use \OCP\ILogger; use \OCP\ILogger;
use OCP\Security\StringUtils; use OCP\Security\StringUtils;
use OCP\Util;
/** /**
* logging utilities * logging utilities
@ -47,11 +48,13 @@ class Log implements ILogger {
/** @var string */ /** @var string */
private $logger; private $logger;
/** @var SystemConfig */ /** @var SystemConfig */
private $config; private $config;
/** @var boolean|null cache the result of the log condition check for the request */ /** @var boolean|null cache the result of the log condition check for the request */
private $logConditionSatisfied = null; private $logConditionSatisfied = null;
/** @var Normalizer */ /** @var Normalizer */
private $normalizer; private $normalizer;
@ -83,15 +86,15 @@ class Log implements ILogger {
} }
/** /**
* System is unusable. * System is unusable.
* *
* @param string $message * @param string $message
* @param array $context * @param array $context
* @return void
*/ */
public function emergency($message, array $context = array()) { public function emergency($message, array $context = array()) {
$this->log(\OCP\Util::FATAL, $message, $context); $this->log(Util::FATAL, $message, $context);
} }
/** /**
@ -102,9 +105,10 @@ class Log implements ILogger {
* *
* @param string $message * @param string $message
* @param array $context * @param array $context
* @return void
*/ */
public function alert($message, array $context = array()) { public function alert($message, array $context = array()) {
$this->log(\OCP\Util::ERROR, $message, $context); $this->log(Util::ERROR, $message, $context);
} }
/** /**
@ -114,9 +118,10 @@ class Log implements ILogger {
* *
* @param string $message * @param string $message
* @param array $context * @param array $context
* @return void
*/ */
public function critical($message, array $context = array()) { public function critical($message, array $context = array()) {
$this->log(\OCP\Util::ERROR, $message, $context); $this->log(Util::ERROR, $message, $context);
} }
/** /**
@ -125,9 +130,10 @@ class Log implements ILogger {
* *
* @param string $message * @param string $message
* @param array $context * @param array $context
* @return void
*/ */
public function error($message, array $context = array()) { public function error($message, array $context = array()) {
$this->log(\OCP\Util::ERROR, $message, $context); $this->log(Util::ERROR, $message, $context);
} }
/** /**
@ -138,9 +144,10 @@ class Log implements ILogger {
* *
* @param string $message * @param string $message
* @param array $context * @param array $context
* @return void
*/ */
public function warning($message, array $context = array()) { public function warning($message, array $context = array()) {
$this->log(\OCP\Util::WARN, $message, $context); $this->log(Util::WARN, $message, $context);
} }
/** /**
@ -148,9 +155,10 @@ class Log implements ILogger {
* *
* @param string $message * @param string $message
* @param array $context * @param array $context
* @return void
*/ */
public function notice($message, array $context = array()) { public function notice($message, array $context = array()) {
$this->log(\OCP\Util::INFO, $message, $context); $this->log(Util::INFO, $message, $context);
} }
/** /**
@ -160,9 +168,10 @@ class Log implements ILogger {
* *
* @param string $message * @param string $message
* @param array $context * @param array $context
* @return void
*/ */
public function info($message, array $context = array()) { public function info($message, array $context = array()) {
$this->log(\OCP\Util::INFO, $message, $context); $this->log(Util::INFO, $message, $context);
} }
/** /**
@ -170,9 +179,10 @@ class Log implements ILogger {
* *
* @param string $message * @param string $message
* @param array $context * @param array $context
* @return void
*/ */
public function debug($message, array $context = array()) { public function debug($message, array $context = array()) {
$this->log(\OCP\Util::DEBUG, $message, $context); $this->log(Util::DEBUG, $message, $context);
} }
@ -182,9 +192,10 @@ class Log implements ILogger {
* @param mixed $level * @param mixed $level
* @param string $message * @param string $message
* @param array $context * @param array $context
* @return void
*/ */
public function log($level, $message, array $context = array()) { public function log($level, $message, array $context = array()) {
$minLevel = min($this->config->getValue('loglevel', \OCP\Util::WARN), \OCP\Util::ERROR); $minLevel = min($this->config->getValue('loglevel', Util::WARN), Util::ERROR);
$logCondition = $this->config->getValue('log.condition', []); $logCondition = $this->config->getValue('log.condition', []);
array_walk($context, [$this->normalizer, 'format']); array_walk($context, [$this->normalizer, 'format']);
@ -199,7 +210,7 @@ class Log implements ILogger {
if(!empty($logCondition) if(!empty($logCondition)
&& isset($logCondition['apps']) && isset($logCondition['apps'])
&& in_array($app, $logCondition['apps'], true)) { && in_array($app, $logCondition['apps'], true)) {
$minLevel = \OCP\Util::DEBUG; $minLevel = Util::DEBUG;
} }
} else { } else {
@ -247,7 +258,7 @@ class Log implements ILogger {
// if log condition is satisfied change the required log level to DEBUG // if log condition is satisfied change the required log level to DEBUG
if($this->logConditionSatisfied) { if($this->logConditionSatisfied) {
$minLevel = \OCP\Util::DEBUG; $minLevel = Util::DEBUG;
} }
if ($level >= $minLevel) { if ($level >= $minLevel) {