-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Conversation
By analyzing the blame information on this pull request, we identified @icewind1991, @bartv2 and @bantu to be potential reviewers. |
Cool 👍 Check it out @icewind1991 @Xenopathic |
$e->getMessage() | ||
); | ||
switch ($e->getCode()) { | ||
case 1: |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
working on it. Thank you all for your comments 👍 |
@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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! My fault ...
There was a problem hiding this comment.
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 😄
There was a problem hiding this comment.
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.
Thank you @Xenopathic , very good explanations |
@jmaciasportela NICE! Just move the existing |
@Xenopathic it feels little strange for me, something like this:
|
@jmaciasportela The alternative is to put the STATUS constants in \OCP\Files\Storage, the storage interface itself. That might be a better idea? |
Failing test:
|
@@ -38,6 +38,7 @@ | |||
use \OCP\Files\StorageNotAvailableException; | |||
use \OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException; | |||
use \OCA\Files_External\Service\BackendService; | |||
use \OCP\Files\StorageNotAvailableException; |
There was a problem hiding this comment.
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)
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 |
There was a problem hiding this comment.
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
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. 👍 |
@PVince81 fixed and exceptions was renamed. |
Thanks. Let's see what CI says |
👍 @icewind1991 @Xenopathic @DeepDiver1975 can this be merged ? |
👍 looks good (needs a rebase) |
👍 🚀 |
Let me fix this broken rebase. |
ac49126
to
9dd1109
Compare
Voila ... only the good parts of the failed rebase :) |
Thank you @MorrisJobke but tell me how, I hope not to broke it again |
@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. |
👍 looks good |
Add different storage status error codes managed by StoragedNotAvailableExc…
…eption
related to #20599
Be able to know which kind of error when StoragedNotAvailableException is thrown