Skip to content

Throw exceptions on IFileStorage instead of returning false or null. #281

Open
@frabe1579

Description

@frabe1579

Almost all the methods in IFileStorage, in the different implementations, catches exception without analyzing errors and returns null or false.
This can lead to mis-interpretation of the result.
For example, takes the methods ExistsAsync and GetFileInfoAsync: they return false/null if the file does not exist, but also for any error (look at S3FileStorage). So if something goes wrong in the network, the main program can potentially have destructive bugs.
I think the best solution is to throw an exception if the result is not one of the expected results, and not returning false/null for any exception.
Also, SaveFileAsync, RenameFileAsync, CopyFileAsync, DeleteFileAsync and DeleteFilesAsync shoudn't have a boolean return value, but instead throw an exception if something goes wrong, to ensure that the main program is informed of the correct result of the operation.
Finally, GetFileStreamAsync should throw an exception instaead of returning null if an error occur, and maybe if the file does not exist.
What do you think about this?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions