summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Mazetto <brodock@gmail.com>2017-06-27 17:41:58 +0200
committerGabriel Mazetto <brodock@gmail.com>2017-06-27 17:48:04 +0200
commitb0f2861c3dd662a82ecbf535d1c259ad81df378b (patch)
treef7b99c9361af39fc6929657e9a578e14a49b0978
parent6b86ce75cf5b716370611f2bccea2b4590d7ce34 (diff)
downloadgitlab-ce-b0f2861c3dd662a82ecbf535d1c259ad81df378b.tar.gz
Make the SimpleExecutor rescue exceptions in the executing Checks
-rw-r--r--lib/system_check/simple_executor.rb2
-rw-r--r--spec/lib/system_check/simple_executor_spec.rb19
2 files changed, 19 insertions, 2 deletions
diff --git a/lib/system_check/simple_executor.rb b/lib/system_check/simple_executor.rb
index dc2d4643a01..e5986612908 100644
--- a/lib/system_check/simple_executor.rb
+++ b/lib/system_check/simple_executor.rb
@@ -75,6 +75,8 @@ module SystemCheck
check.show_error
end
+ rescue StandardError => e
+ $stdout.puts "Exception: #{e.message}".color(:red)
end
private
diff --git a/spec/lib/system_check/simple_executor_spec.rb b/spec/lib/system_check/simple_executor_spec.rb
index a5c6170cd7d..5de768d99ed 100644
--- a/spec/lib/system_check/simple_executor_spec.rb
+++ b/spec/lib/system_check/simple_executor_spec.rb
@@ -75,6 +75,15 @@ describe SystemCheck::SimpleExecutor, lib: true do
end
end
+ class BugousCheck < SystemCheck::BaseCheck
+ CustomError = Class.new(StandardError)
+ set_name 'my bugous check'
+
+ def check?
+ raise CustomError, 'omg'
+ end
+ end
+
describe '#component' do
it 'returns stored component name' do
expect(subject.component).to eq('Test')
@@ -138,14 +147,14 @@ describe SystemCheck::SimpleExecutor, lib: true do
context 'when check pass' do
it 'prints yes' do
expect_any_instance_of(SimpleCheck).to receive(:check?).and_call_original
- expect { subject.run_check(SimpleCheck) }.to output(/ \.\.\. yes/).to_stdout
+ expect { subject.run_check(SimpleCheck) }.to output(/ \.\.\. \e\[32myes/).to_stdout
end
end
context 'when check fails' do
it 'prints no' do
expect_any_instance_of(OtherCheck).to receive(:check?).and_call_original
- expect { subject.run_check(OtherCheck) }.to output(/ \.\.\. no/).to_stdout
+ expect { subject.run_check(OtherCheck) }.to output(/ \.\.\. \e\[31mno/).to_stdout
end
it 'displays error message from #show_error' do
@@ -219,5 +228,11 @@ describe SystemCheck::SimpleExecutor, lib: true do
end
end
end
+
+ context 'when there is an exception' do
+ it 'rescues the exception' do
+ expect{ subject.run_check(BugousCheck) }.not_to raise_exception
+ end
+ end
end
end