Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add different storage status error codes managed by StoragedNotAvailableExc… #20729

Merged
merged 8 commits into from
Dec 3, 2015

Conversation

jmaciasportela
Copy link
Contributor

…eption

related to #20599

Be able to know which kind of error when StoragedNotAvailableException is thrown

@mention-bot
Copy link

By analyzing the blame information on this pull request, we identified @icewind1991, @bartv2 and @bantu to be potential reviewers.

@PVince81
Copy link
Contributor

Cool 👍

Check it out @icewind1991 @Xenopathic

$e->getMessage()
);
switch ($e->getCode()) {
case 1:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the constants in the case statements to

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just thought it might be good to have these constants directly in the StorageNotAvailableException. This way the apps/storages that want to throw the exception can directly use these constants while throwing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that would be better, also since OC_Mount_Config is slowly being depricated

@jmaciasportela
Copy link
Contributor Author

working on it. Thank you all for your comments 👍

@jmaciasportela
Copy link
Contributor Author

@PVince81 @icewind1991 @Xenopathic Please note that new exceptions has fixed exception code to be used directly on storage->setStatus method. I 'm not sure if this is the right way

@@ -244,7 +244,27 @@ protected function updateStorageStatus(StorageConfig &$storage) {
} catch (StorageNotAvailableException $e) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the exceptions below extend this should this catch be at the bottom or otherwise this block catches all of them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! My fault ...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The good thing about deriving exceptions is that it allows us to do the logic within the exceptions themselves, rather than have multiple near-duplicate handlers. All of these catches are the same, so merge them all together into the StorageNotAvailableException catch, where the current hard-coded STATUS_ERROR is replaced with $e->getCode(). Since each exception has a different code (as you've defined) the correct status will be returned. And with less duplicate code 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, no need to translate a string containing only a placeholder. Just pass the string through directly.

@jmaciasportela
Copy link
Contributor Author

Thank you @Xenopathic , very good explanations

@RobinMcCorkell
Copy link
Member

@jmaciasportela NICE!

Just move the existing STATUS_* constants from OC_Mount_Config to StorageNotAvailableException, and this'll be good to go 😄

@jmaciasportela
Copy link
Contributor Author

@Xenopathic it feels little strange for me, something like this:

$newStorage->setStatus(StorageNotAvailableException::STATUS_SUCCESS);

@RobinMcCorkell
Copy link
Member

@jmaciasportela The alternative is to put the STATUS constants in \OCP\Files\Storage, the storage interface itself. That might be a better idea?

@PVince81
Copy link
Contributor

Failing test:

± % ./autotest-external.sh sqlite sftp-atmoz                                                                                                                                                                                         !10121
Using database oc_autotest
Setup environment for sqlite testing ...
Installing ....
ownCloud is not installed - only a limited number of commands are available
creating sqlite db
ownCloud was successfully installed
{"reqId":"fA5I7mMMR0WkAHJ08Vv6","remoteAddr":"","app":"PHP","message":"touch(): Unable to create file \/srv\/www\/htdocs\/owncloud\/data\/owncloud.log because Permission denied at \/srv\/www\/htdocs\/owncloud\/lib\/private\/log\/owncloud.php#53","level":3,"time":"2015-11-30T13:03:43+00:00"}
Testing with sqlite ...
Run only sftp-atmoz ...
files_external enabled
No coverage
PHPUnit 4.3.5 by Sebastian Bergmann.

Configuration read from /srv/www/htdocs/owncloud/tests/phpunit-autotest-external.xml

.............PHP Fatal error:  Cannot use OCP\Files\StorageNotAvailableException as StorageNotAvailableException because the name is already in use in /srv/www/htdocs/owncloud/apps/files_external/controller/storagescontroller.php on line 41
PHP Stack trace:
PHP   1. {main}() /home/vincent/.composer/vendor/phpunit/phpunit/phpunit:0
PHP   2. PHPUnit_TextUI_Command::main() /home/vincent/.composer/vendor/phpunit/phpunit/phpunit:56
PHP   3. PHPUnit_TextUI_Command->run() /home/vincent/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:138
PHP   4. PHPUnit_TextUI_TestRunner->doRun() /home/vincent/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:186
PHP   5. PHPUnit_Framework_TestSuite->run() /home/vincent/.composer/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:423
PHP   6. PHPUnit_Framework_TestSuite->run() /home/vincent/.composer/vendor/phpunit/phpunit/src/Framework/TestSuite.php:751
PHP   7. PHPUnit_Framework_TestCase->run() /home/vincent/.composer/vendor/phpunit/phpunit/src/Framework/TestSuite.php:751
PHP   8. PHPUnit_Framework_TestResult->run() /home/vincent/.composer/vendor/phpunit/phpunit/src/Framework/TestCase.php:711
PHP   9. PHPUnit_Framework_TestCase->runBare() /home/vincent/.composer/vendor/phpunit/phpunit/src/Framework/TestResult.php:643
PHP  10. OCA\Files_external\Tests\Controller\GlobalStoragesControllerTest->setUp() /home/vincent/.composer/vendor/phpunit/phpunit/src/Framework/TestCase.php:771
PHP  11. spl_autoload_call() /home/vincent/.composer/vendor/phpunit/phpunit/src/Framework/TestCase.php:40
PHP  12. OC\Autoloader->load() /home/vincent/.composer/vendor/phpunit/phpunit/src/Framework/TestCase.php:40
PHP  13. require_once() /srv/www/htdocs/owncloud/lib/autoloader.php:185
PHP  14. spl_autoload_call() /srv/www/htdocs/owncloud/lib/autoloader.php:41
PHP  15. OC\Autoloader->load() /srv/www/htdocs/owncloud/lib/autoloader.php:41

@@ -38,6 +38,7 @@
use \OCP\Files\StorageNotAvailableException;
use \OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException;
use \OCA\Files_External\Service\BackendService;
use \OCP\Files\StorageNotAvailableException;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate (causes the unit test errors @PVince81 saw)

@PVince81
Copy link
Contributor

PVince81 commented Dec 1, 2015

Is this still WIP ? If not, please rename the ticket.

Seems the unit test ran now.

Ready for review ?

namespace OCP\Files;

/**
* External Storage authentication exception
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHP doc doesn't match

@PVince81
Copy link
Contributor

PVince81 commented Dec 1, 2015

I'd probably have called the exceptions "StorageXXXException" instead of "ExtStorageXXException". But fine by me.

Please fix the exception's PHPDoc then this is good to do.

👍

@jmaciasportela
Copy link
Contributor Author

@PVince81 fixed and exceptions was renamed.

@PVince81
Copy link
Contributor

PVince81 commented Dec 1, 2015

Thanks. Let's see what CI says

@PVince81 PVince81 changed the title [WIP] Add different storage status error codes managed by StoragedNotAvailableExc… Add different storage status error codes managed by StoragedNotAvailableExc… Dec 2, 2015
@PVince81
Copy link
Contributor

PVince81 commented Dec 2, 2015

👍

@icewind1991 @Xenopathic @DeepDiver1975 can this be merged ?

@icewind1991
Copy link
Contributor

👍 looks good

(needs a rebase)

@RobinMcCorkell
Copy link
Member

👍 🚀

@MorrisJobke
Copy link
Contributor

Let me fix this broken rebase.

@MorrisJobke
Copy link
Contributor

Voila ... only the good parts of the failed rebase :)

@jmaciasportela
Copy link
Contributor Author

Thank you @MorrisJobke but tell me how, I hope not to broke it again

@MorrisJobke
Copy link
Contributor

@Xenopathic @icewind1991 @PVince81 Can one of you have a short look at the outcome. I compared the diff and it was identical but I want to be sure. Then this can be merged.

@PVince81
Copy link
Contributor

PVince81 commented Dec 3, 2015

👍 looks good

DeepDiver1975 added a commit that referenced this pull request Dec 3, 2015
Add different storage status error codes managed by StoragedNotAvailableExc…
@DeepDiver1975 DeepDiver1975 merged commit e62b6c1 into master Dec 3, 2015
@DeepDiver1975 DeepDiver1975 deleted the issue_20599 branch December 3, 2015 11:30
@lock lock bot locked as resolved and limited conversation to collaborators Aug 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants