Skip to content

Storage API must work with exceptions, not booleans #13792

Closed

Description

@PVince81

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.

@Xenopathic @icewind1991 @schiesbn @DeepDiver1975

Activity

  1. RobinMcCorkell commented on Jan 30, 2015

    @RobinMcCorkell
    Contributor

    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);
    }
    

    Only issue I can see is one of performance...

  2. PVince81 commented on Jan 30, 2015

    @PVince81
    ContributorAuthor

    If we consider that exceptions do not happen often, then performance wouldn't be much of an issue.

  3. added this to the backlog milestone on Mar 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions