Skip to content
This repository was archived by the owner on Jan 10, 2023. It is now read-only.

Commit b3f0718

Browse files
authored
Handle socket errors and better handling of v4 (#75)
1 parent 2224951 commit b3f0718

4 files changed

Lines changed: 18 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
### `0.2.2`
2+
- Handle SocketError and better error handling of v4 failures
3+
14
### `0.2.1`
25
- Properly handle 400 cases when using the v4 endpoint
36

codecov.gemspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Gem::Specification.new do |s|
44
s.name = 'codecov'
5-
s.version = '0.2.1'
5+
s.version = '0.2.2'
66
s.platform = Gem::Platform::RUBY
77
s.authors = ['codecov']
88
s.email = ['[email protected]']
@@ -22,4 +22,5 @@ Gem::Specification.new do |s|
2222
s.add_development_dependency 'mocha'
2323
s.add_development_dependency 'rake'
2424
s.add_development_dependency 'rubocop'
25+
s.add_development_dependency 'webmock'
2526
end

lib/codecov.rb

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
require 'zlib'
99

1010
class SimpleCov::Formatter::Codecov
11-
VERSION = '0.2.1'
11+
VERSION = '0.2.2'
1212

1313
### CIs
1414
RECOGNIZED_CIS = [
@@ -280,20 +280,21 @@ def retry_request(req, https)
280280
retries = 3
281281
begin
282282
response = https.request(req)
283-
rescue Timeout::Error => e
283+
rescue Timeout::Error, SocketError => e
284284
retries -= 1
285285

286286
if retries.zero?
287-
puts 'Timeout error uploading coverage reports to Codecov. Out of retries.'
287+
puts 'Timeout or connection error uploading coverage reports to Codecov. Out of retries.'
288288
puts e
289289
return response
290290
end
291291

292-
puts 'Timeout error uploading coverage reports to Codecov. Retrying...'
292+
puts 'Timeout or connection error uploading coverage reports to Codecov. Retrying...'
293293
puts e
294294
retry
295295
rescue StandardError => e
296296
puts 'Error uploading coverage reports to Codecov. Sorry'
297+
puts e.class.name
297298
puts e
298299
return response
299300
end
@@ -362,8 +363,8 @@ def upload_to_v4(url, report, query, query_without_token)
362363
}
363364
)
364365
response = retry_request(req, https)
365-
if response.code == '400'
366-
puts response.body.red
366+
if !response&.code || response.code == '400'
367+
puts response&.body&.red
367368
return false
368369
end
369370

@@ -429,8 +430,8 @@ def handle_report_response(report)
429430
end
430431
end
431432

432-
def format(result)
433-
net_blockers(:off)
433+
def format(result, disable_net_blockers = true)
434+
net_blockers(:off) if disable_net_blockers
434435

435436
display_header
436437
ci = detect_ci
@@ -443,7 +444,8 @@ def format(result)
443444

444445
report['result'] = JSON.parse(response)
445446
handle_report_response(report)
446-
net_blockers(:on)
447+
448+
net_blockers(:on) if disable_net_blockers
447449
report
448450
end
449451

test/helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@
1212

1313
require 'minitest/autorun'
1414
require 'mocha/setup'
15+
16+
require 'webmock/minitest'

0 commit comments

Comments
 (0)