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

Fix contract for FileSourceBlobStore #2451

Merged
merged 5 commits into from
Nov 2, 2023
Merged

Conversation

dkhozyainov
Copy link
Contributor

@dkhozyainov dkhozyainov commented Oct 17, 2023

Greetings, please look at my PR for #2420

Submitter checklist

  • Recommended: Join WireMock Slack to get any help in #help-contributing or a project-specific channel like #wiremock-java
  • Recommended: If you participate in Hacktoberfest 2023, make sure you're signed up there and in the WireMock form
  • The PR request is well described and justified, including the body and the references
  • The PR title represents the desired changelog entry
  • The repository's code style is followed (see the contributing guide)
  • Test coverage that demonstrates that the change works as expected
  • For new features, there's necessary documentation in this pull request or in a subsequent PR to wiremock.org

@dkhozyainov dkhozyainov requested a review from a team as a code owner October 17, 2023 11:27
Copy link
Member

@oleg-nenashev oleg-nenashev left a comment

Choose a reason for hiding this comment

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

Looks okay though I would think about proper diagnostics logs, because now all exceptions would be silently suppressed. Would be also nice to add a human readable PR title for the changelog

@dkhozyainov dkhozyainov changed the title Proposal for: FileSourceBlobStore throws FileNotFoundExceptions when … Fix contract for FileSourceBlobStore Oct 17, 2023
@dkhozyainov
Copy link
Contributor Author

dkhozyainov commented Oct 17, 2023

Looks okay though I would think about proper diagnostics logs, because now all exceptions would be silently suppressed. Would be also nice to add a human readable PR title for the changelog

@oleg-nenashev Can you tell me how nice it is to make diagnostic logs? maybe there is an example somewhere?

@oleg-nenashev
Copy link
Member

WireMock uses com.github.tomakehurst.wiremock.common.LocalNotifier.notifier for logging purposes, e.g.

notifier().info("Started recording with record spec:\n" + Json.write(spec));

I normally use stock logging frameworks, so not sure how much of debug logging we can make with it

fix code style, add logs
@dkhozyainov
Copy link
Contributor Author

@oleg-nenashev

@oleg-nenashev thanks for the hint, I added it in the next commit+ fixed code style

return Optional.of(fileSource.getBinaryFileNamed(key).readContents());
try {
return Optional.of(fileSource.getBinaryFileNamed(key).readContents());
} catch (Exception exception) {
Copy link
Member

Choose a reason for hiding this comment

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

How about we catch FileNotFoundException and don't log anything, since this is a normal event, then log at error for any other type of exception (which in practice would probably indicate a misconfigured file system)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. I used instanceof because FileNotFoundException is cast to Throwable in the BinaryFile class via the throwUnchecked method

notifier()
.info("Error when working with FileSource:\n" + Json.write(exception.getMessage()));
}
return Optional.empty();
Copy link
Member

Choose a reason for hiding this comment

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

I think we should still throw the exception if it's not FileNotFoundException. Only return empty when it's exactly that exception.

We can probably do this with two catch blocks rather than instanceof.

The notifier call should be at error if it's not a not-found error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, catch FileNotFoundException is unavailable due to wrapping into an unchecked exception in the Binary File class via the throwUnchecked method.
Other comments fixed

@tomakehurst tomakehurst merged commit 55ae938 into wiremock:master Nov 2, 2023
@tomakehurst
Copy link
Member

Thanks!

@dkhozyainov dkhozyainov deleted the #2420 branch November 4, 2023 18:02
henrik242 pushed a commit to henrik242/wiremock that referenced this pull request Nov 10, 2023
Fix for: FileSourceBlobStore throws FileNotFoundExceptions when it should return Optional.empty() wiremock#2420

---------

Co-authored-by: d.khoziainov <d.khoziainov@uzum.com>
Marvin9 pushed a commit to Marvin9/wiremock that referenced this pull request Nov 20, 2023
Fix for: FileSourceBlobStore throws FileNotFoundExceptions when it should return Optional.empty() wiremock#2420

---------

Co-authored-by: d.khoziainov <d.khoziainov@uzum.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants