Skip to content

Commit 4628f22

Browse files
authored
Failure to parse a single artifact should not cause all artifacts to fail (#66)
1 parent 25e9687 commit 4628f22

2 files changed

Lines changed: 37 additions & 8 deletions

File tree

lib/test_summary_buildkite_plugin/input.rb

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,8 @@ def files
4040
Agent.run('artifact', 'download', artifact_path, WORKDIR)
4141
Dir.glob("#{WORKDIR}/#{artifact_path}")
4242
rescue Agent::CommandFailed => err
43-
if fail_on_error
44-
raise
45-
else
46-
Utils.log_error(err)
47-
[]
48-
end
43+
handle_error(err)
44+
[]
4945
end
5046
end
5147

@@ -63,6 +59,9 @@ def fail_on_error
6359

6460
def filename_to_failures(filename)
6561
file_contents_to_failures(read(filename)).each { |failure| failure.job_id = job_id(filename) }
62+
rescue StandardError => err
63+
handle_error(err)
64+
[]
6665
end
6766

6867
def job_id(filename)
@@ -78,6 +77,14 @@ def job_id_regex
7877
DEFAULT_JOB_ID_REGEX
7978
end
8079
end
80+
81+
def handle_error(err)
82+
if fail_on_error
83+
raise err
84+
else
85+
Utils.log_error(err)
86+
end
87+
end
8188
end
8289

8390
class OneLine < Base

spec/test_summary_buildkite_plugin/input_spec.rb

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@
265265
describe 'setting ascii encoding' do
266266
let(:type) { 'oneline' }
267267
let(:artifact_path) { 'eslint-00112233-0011-0011-0011-001122334455.txt' }
268-
let(:additional_options) { { encoding: 'ascii' } }
268+
let(:additional_options) { { encoding: 'ascii', fail_on_error: true } }
269269

270270
it 'tries to parse as ascii' do
271271
expect { input.failures }.to raise_error('invalid byte sequence in US-ASCII')
@@ -301,7 +301,7 @@
301301
end
302302

303303
context 'with bad custom job_id_regex' do
304-
let(:additional_options) { { job_id_regex: '(eslint)' } }
304+
let(:additional_options) { { job_id_regex: '(eslint)', fail_on_error: true } }
305305
let(:artifact_path) { 'eslint-00112233-0011-0011-0011-001122334455.txt' }
306306

307307
it 'gives helpful error' do
@@ -338,4 +338,26 @@
338338
end
339339
end
340340
end
341+
342+
describe 'parsing exceptions' do
343+
let(:type) { 'oneline' }
344+
let(:artifact_path) { 'rubocop.txt' }
345+
346+
before do
347+
allow(input).to receive(:file_contents_to_failures).and_raise('no good')
348+
end
349+
350+
it 'handles the error' do
351+
expect { input.failures }.to output(/no good/).to_stdout
352+
expect(input.failures).to be_empty
353+
end
354+
355+
describe 'with fail_on_error' do
356+
let(:additional_options) { { fail_on_error: true } }
357+
358+
it 're-raises the error' do
359+
expect { input.failures }.to raise_error('no good')
360+
end
361+
end
362+
end
341363
end

0 commit comments

Comments
 (0)