diff --git a/CHANGELOG.md b/CHANGELOG.md index 95915ff..bd2a1ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html ### Compatible changes +* `chromedriver-update` command: handles offline and DNS resolution errors. + ### Breaking changes diff --git a/lib/geordi/chromedriver_updater.rb b/lib/geordi/chromedriver_updater.rb index 2b22375..1982366 100644 --- a/lib/geordi/chromedriver_updater.rb +++ b/lib/geordi/chromedriver_updater.rb @@ -92,7 +92,8 @@ def fetch_response(url, error_message) # Rescue Errno::NOERROR, Errno::ENOENT, Errno::EACCES, Errno::EFAULT, Errno::ECONNREFUSED, Errno::ECONNABORTED, Errno::ECONNRESET, Errno::EHOSTDOWN, Errno::EHOSTUNREACH, ..., # all of which are a subclass of SystemCallError - rescue SystemCallError => e + # and DNS / resolution errors (SocketError, including Socket::ResolutionError on 3.3+) + rescue SystemCallError, SocketError => e raise ProcessingError, "Request failed: #{e.message}" end @@ -110,15 +111,14 @@ def chromedriver_url(chrome_version) end def chromedriver_download_data - return @chromedriver_download_data if @chromedriver_download_data - - fetch_response(VERSIONS_PER_MILESTONES_URL, "Could not find chromedriver download data") do |response| - begin - chromedriver_download_data = JSON.parse(response.body) - rescue JSON::ParserError - raise ProcessingError, "Could not parse chromedriver download data." + @chromedriver_download_data ||= begin + fetch_response(VERSIONS_PER_MILESTONES_URL, "Could not find chromedriver download data") do |response| + begin + JSON.parse(response.body) + rescue JSON::ParserError + raise ProcessingError, "Could not parse chromedriver download data." + end end - @chromedriver_download_data = chromedriver_download_data end end diff --git a/spec/chromedriver_updater_spec.rb b/spec/chromedriver_updater_spec.rb index 121356c..fd212d2 100644 --- a/spec/chromedriver_updater_spec.rb +++ b/spec/chromedriver_updater_spec.rb @@ -16,6 +16,13 @@ subject.run(exit_on_failure: false) end + + it 'handles offline errors' do + allow(Net::HTTP).to receive(:get_response).and_raise(SocketError, 'Failed to open TCP connection to googlechromelabs.github.io:443 (getaddrinfo: Temporary failure in name resolution)') + expect(Geordi::Interaction).to receive(:warn).with('Request failed: Failed to open TCP connection to googlechromelabs.github.io:443 (getaddrinfo: Temporary failure in name resolution)') + + subject.run(exit_on_failure: false) + end end end end