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

(maint) Handle an invalid mirror gracefully #813

Merged
merged 1 commit into from
Aug 29, 2023

Conversation

nmburgan
Copy link
Contributor

Because the HTTP source's valid_url? check was always returning truthy before, a mirror URL to a file would always seem to be valid, even if it wasn't. Now that 9995d5e fixed it, a Vanagon::Error would get thrown saying it was an unknown file type. This means that fetch_url would never get called since this exception in fetch_mirrors would be unhandled.

This handles that particular error, and continues to throw other Vanagon::Error types, as they usually indicate a problem with the definition of the component or some other type of fatal error. Additionally, this changes the catching of RuntimeError to StandardError, so that we can handle issues talking to the particular URL, such as OpenSSL errors.

Please add all notable changes to the "Unreleased" section of the CHANGELOG.

Copy link
Contributor

@e-gris e-gris left a comment

Choose a reason for hiding this comment

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

LGTM, but please add a CHANGELOG entry.

@@ -260,14 +260,28 @@ def fetch_mirrors(options)
VanagonLogger.info %(Attempting to fetch from mirror URL "#{mirror}")
@source = Vanagon::Component::Source.source(mirror, **options)
return true if source.fetch
rescue Vanagon::Error => e
if e.message =~ /Unknown file type/
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I'd prefer raising an subclass of Vanagon::Error specifically for the unknown source case and rescue the most specific exceptions first like:

rescue Vanagon::UnknownSourceError
  VanagonLogger.error %(Unable to access mirror URL "#{mirror}")
rescue Vanagon::Error 
  raise
rescue SocketError
  ...
rescue StandardError
  ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that's fair. I was being lazy :)

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

@nmburgan nmburgan changed the title Handle an invalid mirror gracefully (maint) Handle an invalid mirror gracefully Aug 28, 2023
Because the HTTP source's valid_url? check was always returning truthy before, a mirror URL to a file would always seem to be valid, even if it wasn't. Now that puppetlabs@9995d5e fixed it, a Vanagon::Error would get thrown saying it was an unknown file type. This means that fetch_url would never get called since this exception in fetch_mirrors would be unhandled.

This handles that particular error, and continues to throw other Vanagon::Error types, as they usually indicate a problem with the definition of the component or some other type of fatal error. Additionally, this changes the catching of RuntimeError to StandardError, so that we can handle issues talking to the particular URL, such as OpenSSL errors.
@nmburgan nmburgan merged commit 378ab44 into puppetlabs:main Aug 29, 2023
4 checks passed
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.

3 participants