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

Throw S3FileStorageException when something goes wrong and response is not as expected. #305

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

frabe1579
Copy link

@frabe1579 frabe1579 commented Nov 7, 2022

This PR changes GetFileStreamAsync, GetFileInfoAsync, and ExistsAsync.
The changes test for precise response status code, in order to avoid silent catching of particular S3 errors.
All tests passes, but not new tests were added because of the difficult to simulate errors. A classic error simulation is network error, but this already throws other exceptions.
Related to FoundatioFx/Foundatio#281

…s not as expected for GetFileStreamAsync, GetFileInfoAsync, and ExistsAsync.
@CLAassistant
Copy link

CLAassistant commented Nov 7, 2022

CLA assistant check
All committers have signed the CLA.

@frabe1579
Copy link
Author

There is a failure on Queue tests, but this PR touches only FileStorage, maybe future merges can solve this.

Copy link
Member

@niemyjski niemyjski left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

@ejsmith I wonder if we should also be adding debug / trace logging around responses / before we throw.

src/Foundatio.AWS/Storage/S3FileStorage.cs Outdated Show resolved Hide resolved
Comment on lines 109 to 113
} catch (AmazonS3Exception ex) {
if (ex.StatusCode == System.Net.HttpStatusCode.NotFound)
return null;
throw new S3FileStorageException("Error accessing S3 storage: " + ex.Message, ex);
}
Copy link
Member

Choose a reason for hiding this comment

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

Would be nice to use exception filters here

@frabe1579
Copy link
Author

In this specific case, trace/debug logging I think isn't needed, because in case of not-managed error, an exception is thrown to the caller.
Anyway, logging may be useful, as for S3FileStorage the logger is never used.

Copy link
Contributor

@ejsmith ejsmith left a comment

Choose a reason for hiding this comment

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

Wow. Just realized that I reviewed this a long while back and didn't submit the review. Sorry.

using System.Collections.Generic;
using System.Text;

namespace Foundatio.AWS.Storage {
Copy link
Contributor

Choose a reason for hiding this comment

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

We definitely don't want to have exceptions that are unique to each implementation where a user would need to check for different kinds of exceptions depending on which implementation they are using.

return null;

if (res.HttpStatusCode != System.Net.HttpStatusCode.OK)
Copy link
Contributor

Choose a reason for hiding this comment

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

We are probably going to want to think about some sort of retry mechanism for things that can be retried. I guess it doesn't need to be part of this change though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants