Skip to content

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

Merged
niemyjski merged 8 commits intoFoundatioFx:mainfrom
frabe1579:s3-resolve
May 29, 2025
Merged

Throw S3FileStorageException when something goes wrong and response is not as expected.#305
niemyjski merged 8 commits intoFoundatioFx:mainfrom
frabe1579:s3-resolve

Conversation

@frabe1579
Copy link
Contributor

@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
Contributor 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.

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
Contributor 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.

Copy link
Contributor

Choose a reason for hiding this comment

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

@frabe1579 I think this was the main concern with merging this PR. We don't want to have different exceptions being thrown per implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry I'm not comfortable with branches and pull-requests. I've removed S3FileStorageException and corrected code. Can you see it?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, thank you, we can delete this file.

Copy link
Member

@niemyjski niemyjski May 15, 2025

Choose a reason for hiding this comment

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

I'm going to work towards merging this pr then create a StorageException in the core library and update the core implementations and then update this line (post merge) to use this new exception type.

Thanks again for the pr!

Copy link
Member

Choose a reason for hiding this comment

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

@niemyjski
Copy link
Member

@frabe1579 could you please address Erics comments, would love to get this merged.

@frabe1579 frabe1579 requested a review from ejsmith May 7, 2025 07:52
Use more generic exception for error in GetFileInfo
`res` variable is now named `resource`.
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.

I'm going to merge this and then update it shortly to use the new StorageException we created in Foundatio.

@niemyjski niemyjski merged commit 01c7215 into FoundatioFx:main May 29, 2025
2 checks passed
@niemyjski
Copy link
Member

Thank you so much for your PR!

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