[Pkg-owncloud-commits] [owncloud] 159/457: improve error messages displayed to the user

David Prévot taffit at moszumanska.debian.org
Sun Jun 28 20:05:54 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch stable8
in repository owncloud.

commit 5549641f1f977ab2b105b8f9d7b8c6829c0e6d02
Author: Bjoern Schiessle <schiessle at owncloud.com>
Date:   Wed May 27 10:37:12 2015 +0200

    improve error messages displayed to the user
---
 apps/encryption/lib/crypto/encryption.php               |  2 +-
 .../encryption/exceptions/decryptionfailedexception.php | 11 -----------
 lib/private/encryption/manager.php                      | 11 +++++++++--
 lib/private/server.php                                  |  2 +-
 .../exceptions/genericencryptionexception.php           | 17 +++++------------
 tests/lib/encryption/managertest.php                    |  6 +++++-
 6 files changed, 21 insertions(+), 28 deletions(-)

diff --git a/apps/encryption/lib/crypto/encryption.php b/apps/encryption/lib/crypto/encryption.php
index f527955..9094a84 100644
--- a/apps/encryption/lib/crypto/encryption.php
+++ b/apps/encryption/lib/crypto/encryption.php
@@ -387,7 +387,7 @@ class Encryption implements IEncryptionModule {
 					'" is not able to read ' . $path;
 				$hint = $this->l->t('Can not read this file, probably this is a shared file. Please ask the file owner to reshare the file with you.');
 				$this->logger->warning($msg);
-				throw new DecryptionFailedException($msg, 0, null, $hint);
+				throw new DecryptionFailedException($msg, $hint);
 			}
 			return false;
 		}
diff --git a/lib/private/encryption/exceptions/decryptionfailedexception.php b/lib/private/encryption/exceptions/decryptionfailedexception.php
index 7e9fa21..406ae12 100644
--- a/lib/private/encryption/exceptions/decryptionfailedexception.php
+++ b/lib/private/encryption/exceptions/decryptionfailedexception.php
@@ -27,15 +27,4 @@ use OCP\Encryption\Exceptions\GenericEncryptionException;
 
 class DecryptionFailedException extends GenericEncryptionException {
 
-	/**
-	 * @param string $message
-	 * @param int $code
-	 * @param \Exception $previous
-	 * @param string $hint
-	 */
-	public function __construct($message = '', $code = 0, \Exception $previous = null, $hint = '') {
-		parent::__construct($message, $code, $previous, $hint);
-
-}
-
 }
diff --git a/lib/private/encryption/manager.php b/lib/private/encryption/manager.php
index 45f4504..6942376 100644
--- a/lib/private/encryption/manager.php
+++ b/lib/private/encryption/manager.php
@@ -30,6 +30,7 @@ use OCP\Encryption\IEncryptionModule;
 use OCP\Encryption\IManager;
 use OCP\Files\Mount\IMountPoint;
 use OCP\IConfig;
+use OCP\IL10N;
 use OCP\ILogger;
 
 class Manager implements IManager {
@@ -43,14 +44,19 @@ class Manager implements IManager {
 	/** @var ILogger */
 	protected $logger;
 
+	/** @var Il10n */
+	protected $l;
+
 	/**
 	 * @param IConfig $config
 	 * @param ILogger $logger
+	 * @param IL10N $l10n
 	 */
-	public function __construct(IConfig $config, ILogger $logger) {
+	public function __construct(IConfig $config, ILogger $logger, IL10N $l10n) {
 		$this->encryptionModules = array();
 		$this->config = $config;
 		$this->logger = $logger;
+		$this->l = $l10n;
 	}
 
 	/**
@@ -145,7 +151,8 @@ class Manager implements IManager {
 				return call_user_func($this->encryptionModules[$moduleId]['callback']);
 			} else {
 				$message = "Module with id: $moduleId does not exists.";
-				throw new Exceptions\ModuleDoesNotExistsException($message);
+				$hint = $this->l->t('Module with id: %s does not exists. Please enable it in your apps settings or contact your administrator.', [$moduleId]);
+				throw new Exceptions\ModuleDoesNotExistsException($message, $hint);
 			}
 		} else {
 			return $this->getDefaultEncryptionModule();
diff --git a/lib/private/server.php b/lib/private/server.php
index 7fa668b..aeea4a6 100644
--- a/lib/private/server.php
+++ b/lib/private/server.php
@@ -84,7 +84,7 @@ class Server extends SimpleContainer implements IServerContainer {
 		});
 
 		$this->registerService('EncryptionManager', function (Server $c) {
-			return new Encryption\Manager($c->getConfig(), $c->getLogger());
+			return new Encryption\Manager($c->getConfig(), $c->getLogger(), $c->getL10N('core'));
 		});
 
 		$this->registerService('EncryptionFileHelper', function (Server $c) {
diff --git a/lib/public/encryption/exceptions/genericencryptionexception.php b/lib/public/encryption/exceptions/genericencryptionexception.php
index e97f00c..5648e5e 100644
--- a/lib/public/encryption/exceptions/genericencryptionexception.php
+++ b/lib/public/encryption/exceptions/genericencryptionexception.php
@@ -21,6 +21,7 @@
  */
 
 namespace OCP\Encryption\Exceptions;
+use OC\HintException;
 
 /**
  * Class GenericEncryptionException
@@ -28,28 +29,20 @@ namespace OCP\Encryption\Exceptions;
  * @package OCP\Encryption\Exceptions
  * @since 8.1.0
  */
-class GenericEncryptionException extends \Exception {
-
-	/** @var string */
-	protected $hint;
+class GenericEncryptionException extends HintException {
 
 	/**
 	 * @param string $message
+	 * @param string $hint
 	 * @param int $code
 	 * @param \Exception $previous
 	 * @since 8.1.0
 	 */
-	public function __construct($message = '', $code = 0, \Exception $previous = null, $hint = '') {
+	public function __construct($message = '', $hint = '', $code = 0, \Exception $previous = null) {
 		if (empty($message)) {
 			$message = 'Unspecified encryption exception';
 		}
-		parent::__construct($message, $code, $previous);
-
-		$this->hint = $hint;
-	}
-
-	public function getHint() {
-		return $this->hint;
+		parent::__construct($message, $hint, $code, $previous);
 	}
 
 }
diff --git a/tests/lib/encryption/managertest.php b/tests/lib/encryption/managertest.php
index faca647..3b1e07f 100644
--- a/tests/lib/encryption/managertest.php
+++ b/tests/lib/encryption/managertest.php
@@ -16,11 +16,15 @@ class ManagerTest extends TestCase {
 	/** @var \PHPUnit_Framework_MockObject_MockObject */
 	private $logger;
 
+	/** @var \PHPUnit_Framework_MockObject_MockObject */
+	private $l10n;
+
 	public function setUp() {
 		parent::setUp();
 		$this->config = $this->getMock('\OCP\IConfig');
 		$this->logger = $this->getMock('\OCP\ILogger');
-		$this->manager = new Manager($this->config, $this->logger);
+		$this->l10n = $this->getMock('\OCP\Il10n');
+		$this->manager = new Manager($this->config, $this->logger, $this->l10n);
 	}
 
 	public function testManagerIsDisabled() {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list