You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Storage API must work with exceptions, not booleans #13792
Currently the Storage API is similar to the one from PHP and simply returns false when an error occurred.
This makes it difficult to distinguish whether "false" means "File not found" or "Storage not available".
We should move to using exceptions in such cases and get rid of booleans.
I think it comes down to catching 3rd party exceptions then wrapping them into our exceptions. Perhaps some system for a storage to define what exceptions may be thrown from it, and what they should 'map' to? For example, the DAV storage backend would map Sabre\DAV\Exception\NotFound to OCP\Files\NotFoundException. Then, without any extra try catch blocks in the storages themselves, a wrapper or the filesystem itself would catch such errors, then wrap them in our exceptions.
try {
$storage->doSomething();
} catch (\Exception $e) {
foreach ($storage->getExceptionMap() as $orig => $wrapper) {
if (is_instance($e, $orig)) {
throw new $wrapper(..., $e);
}
}
throw new \OCP\Files\UnknownFailureException(..., $e);
}
Activity
RobinMcCorkell commentedon Jan 30, 2015
I think it comes down to catching 3rd party exceptions then wrapping them into our exceptions. Perhaps some system for a storage to define what exceptions may be thrown from it, and what they should 'map' to? For example, the DAV storage backend would map
Sabre\DAV\Exception\NotFoundtoOCP\Files\NotFoundException. Then, without any extratry catchblocks in the storages themselves, a wrapper or the filesystem itself would catch such errors, then wrap them in our exceptions.Only issue I can see is one of performance...
PVince81 commentedon Jan 30, 2015
If we consider that exceptions do not happen often, then performance wouldn't be much of an issue.