diff --git a/app/errors/runner/error.rb b/app/errors/runner/error.rb index 3470f553..ba6aeee1 100644 --- a/app/errors/runner/error.rb +++ b/app/errors/runner/error.rb @@ -1,3 +1,21 @@ # frozen_string_literal: true -class Runner::Error < ApplicationError; end +class Runner + class Error < ApplicationError + class BadRequest < Error; end + + class EnvironmentNotFound < Error; end + + class ExecutionTimeout < Error; end + + class InternalServerError < Error; end + + class NotAvailable < Error; end + + class Unauthorized < Error; end + + class RunnerNotFound < Error; end + + class Unknown < Error; end + end +end diff --git a/app/errors/runner/error/bad_request.rb b/app/errors/runner/error/bad_request.rb deleted file mode 100644 index 98b8f5ca..00000000 --- a/app/errors/runner/error/bad_request.rb +++ /dev/null @@ -1,3 +0,0 @@ -# frozen_string_literal: true - -class Runner::Error::BadRequest < Runner::Error; end diff --git a/app/errors/runner/error/execution_timeout.rb b/app/errors/runner/error/execution_timeout.rb deleted file mode 100644 index c10806a5..00000000 --- a/app/errors/runner/error/execution_timeout.rb +++ /dev/null @@ -1,3 +0,0 @@ -# frozen_string_literal: true - -class Runner::Error::ExecutionTimeout < Runner::Error; end diff --git a/app/errors/runner/error/internal_server_error.rb b/app/errors/runner/error/internal_server_error.rb deleted file mode 100644 index 68f3f0b8..00000000 --- a/app/errors/runner/error/internal_server_error.rb +++ /dev/null @@ -1,3 +0,0 @@ -# frozen_string_literal: true - -class Runner::Error::InternalServerError < Runner::Error; end diff --git a/app/errors/runner/error/not_available.rb b/app/errors/runner/error/not_available.rb deleted file mode 100644 index 4785ea59..00000000 --- a/app/errors/runner/error/not_available.rb +++ /dev/null @@ -1,3 +0,0 @@ -# frozen_string_literal: true - -class Runner::Error::NotAvailable < Runner::Error; end diff --git a/app/errors/runner/error/not_found.rb b/app/errors/runner/error/not_found.rb deleted file mode 100644 index 329bcc71..00000000 --- a/app/errors/runner/error/not_found.rb +++ /dev/null @@ -1,3 +0,0 @@ -# frozen_string_literal: true - -class Runner::Error::NotFound < Runner::Error; end diff --git a/app/errors/runner/error/unauthorized.rb b/app/errors/runner/error/unauthorized.rb deleted file mode 100644 index 8bccf7fa..00000000 --- a/app/errors/runner/error/unauthorized.rb +++ /dev/null @@ -1,3 +0,0 @@ -# frozen_string_literal: true - -class Runner::Error::Unauthorized < Runner::Error; end diff --git a/app/errors/runner/error/unknown.rb b/app/errors/runner/error/unknown.rb deleted file mode 100644 index 6e1a1fce..00000000 --- a/app/errors/runner/error/unknown.rb +++ /dev/null @@ -1,3 +0,0 @@ -# frozen_string_literal: true - -class Runner::Error::Unknown < Runner::Error; end diff --git a/app/models/runner.rb b/app/models/runner.rb index c1aee053..0293f181 100644 --- a/app/models/runner.rb +++ b/app/models/runner.rb @@ -38,7 +38,7 @@ class Runner < ApplicationRecord DELEGATED_STRATEGY_METHODS.each do |method| define_method(method) do |*args, &block| @strategy.send(method, *args, &block) - rescue Runner::Error::NotFound + rescue Runner::Error::RunnerNotFound request_new_id save @strategy.send(method, *args, &block) @@ -55,13 +55,13 @@ class Runner < ApplicationRecord strategy_class = self.class.strategy_class self.runner_id = strategy_class.request_from_management(execution_environment) @strategy = strategy_class.new(runner_id, execution_environment) - rescue Runner::Error::NotFound + rescue Runner::Error::EnvironmentNotFound if strategy_class.sync_environment(execution_environment) - raise Runner::Error::NotFound.new( + raise Runner::Error::EnvironmentNotFound.new( "The execution environment with id #{execution_environment.id} was not found and was successfully synced with the runner management" ) else - raise Runner::Error::NotFound.new( + raise Runner::Error::EnvironmentNotFound.new( "The execution environment with id #{execution_environment.id} was not found and could not be synced with the runner management" ) end diff --git a/spec/lib/runner/strategy/poseidon_spec.rb b/spec/lib/runner/strategy/poseidon_spec.rb index 7f5ac368..15795701 100644 --- a/spec/lib/runner/strategy/poseidon_spec.rb +++ b/spec/lib/runner/strategy/poseidon_spec.rb @@ -53,7 +53,7 @@ describe Runner::Strategy::Poseidon do let(:response_status) { 404 } it 'raises an error' do - expect { action.call }.to raise_error(Runner::Error::NotFound, /Runner/) + expect { action.call }.to raise_error(Runner::Error::RunnerNotFound) end end end @@ -152,7 +152,7 @@ describe Runner::Strategy::Poseidon do let(:response_status) { 404 } it 'raises an error' do - expect { action.call }.to raise_error(Runner::Error::NotFound, /Execution environment/) + expect { action.call }.to raise_error(Runner::Error::EnvironmentNotFound) end end diff --git a/spec/models/runner_spec.rb b/spec/models/runner_spec.rb index b2f0e6cb..e8f57966 100644 --- a/spec/models/runner_spec.rb +++ b/spec/models/runner_spec.rb @@ -118,23 +118,23 @@ describe Runner do context 'when the environment could not be found in the runner management' do let(:environment_id) { runner.execution_environment.id } - before { allow(strategy_class).to receive(:request_from_management).and_raise(Runner::Error::NotFound) } + before { allow(strategy_class).to receive(:request_from_management).and_raise(Runner::Error::EnvironmentNotFound) } it 'syncs the execution environment' do expect(strategy_class).to receive(:sync_environment).with(runner.execution_environment) runner.send(:request_new_id) - rescue Runner::Error::NotFound + rescue Runner::Error::EnvironmentNotFound # Ignored because this error is expected (see tests below). end it 'raises an error when the environment could be synced' do allow(strategy_class).to receive(:sync_environment).with(runner.execution_environment).and_return(true) - expect { runner.send(:request_new_id) }.to raise_error(Runner::Error::NotFound, /#{environment_id}.*successfully synced/) + expect { runner.send(:request_new_id) }.to raise_error(Runner::Error::EnvironmentNotFound, /#{environment_id}.*successfully synced/) end it 'raises an error when the environment could not be synced' do allow(strategy_class).to receive(:sync_environment).with(runner.execution_environment).and_return(false) - expect { runner.send(:request_new_id) }.to raise_error(Runner::Error::NotFound, /#{environment_id}.*could not be synced/) + expect { runner.send(:request_new_id) }.to raise_error(Runner::Error::EnvironmentNotFound, /#{environment_id}.*could not be synced/) end end end