Introduce more error types

This commit is contained in:
Felix Auringer
2021-06-24 12:42:43 +02:00
committed by Sebastian Serth
parent db2d1e3164
commit cc412b73bc
5 changed files with 35 additions and 29 deletions

View File

@ -12,9 +12,9 @@ class Runner::Strategy::DockerContainerPool < Runner::Strategy
container_id = JSON.parse(Faraday.get("#{config[:pool][:location]}/docker_container_pool/get_container/#{environment.id}").body)['id']
container_id.presence || raise(Runner::Error::NotAvailable.new("DockerContainerPool didn't return a container id"))
rescue Faraday::Error => e
raise Runner::Error::Unknown.new("Faraday request to DockerContainerPool failed: #{e.inspect}")
raise Runner::Error::FaradayError.new("Request to DockerContainerPool failed: #{e.inspect}")
rescue JSON::ParserError => e
raise Runner::Error::Unknown.new("DockerContainerPool returned invalid JSON: #{e.inspect}")
raise Runner::Error::UnexpectedResponse.new("DockerContainerPool returned invalid JSON: #{e.inspect}")
end
def initialize(runner_id, _environment)
@ -40,7 +40,7 @@ class Runner::Strategy::DockerContainerPool < Runner::Strategy
rescue IOError => e
# TODO: try catch i/o exception and log failed attempts
# Does this fix the issue @Sebastian? What exceptions did you have in mind?
raise Runner::Error::Unknown.new("Could not create workspace file #{file.filepath}: #{e.inspect}")
raise Runner::Error::WorkspaceError.new("Could not create file #{file.filepath}: #{e.inspect}")
end
end
end
@ -50,7 +50,7 @@ class Runner::Strategy::DockerContainerPool < Runner::Strategy
def destroy_at_management
Faraday.get("#{self.class.config[:pool][:location]}/docker_container_pool/destroy_container/#{container.id}")
rescue Faraday::Error => e
raise Runner::Error::Unknown.new("Faraday request to DockerContainerPool failed: #{e.inspect}")
raise Runner::Error::FaradayError.new("Request to DockerContainerPool failed: #{e.inspect}")
end
def attach_to_execution(command)
@ -88,7 +88,7 @@ class Runner::Strategy::DockerContainerPool < Runner::Strategy
unclean_path = local_workspace_path.join(path)
clean_path = File.expand_path(unclean_path)
unless clean_path.to_s.start_with? local_workspace_path.to_s
raise Runner::Error::Unknown.new("Local filepath #{clean_path.inspect} not allowed")
raise Runner::Error::WorkspaceError.new("Local filepath #{clean_path.inspect} not allowed")
end
Pathname.new(clean_path)
@ -97,10 +97,10 @@ class Runner::Strategy::DockerContainerPool < Runner::Strategy
def clean_workspace
FileUtils.rm_r(local_workspace_path.children, secure: true)
rescue Errno::ENOENT => e
raise Runner::Error::Unknown.new("The workspace directory does not exist and cannot be deleted: #{e.inspect}")
raise Runner::Error::WorkspaceError.new("The workspace directory does not exist and cannot be deleted: #{e.inspect}")
rescue Errno::EACCES => e
# TODO: Why was this rescued before @Sebastian?
raise Runner::Error::Unknown.new("Not allowed to clean workspace #{local_workspace_path}: #{e.inspect}")
raise Runner::Error::WorkspaceError.new("Not allowed to clean workspace #{local_workspace_path}: #{e.inspect}")
end
def local_workspace_path

View File

@ -23,14 +23,14 @@ class Runner::Strategy::Poseidon < Runner::Strategy
when 200
response_body = parse response
runner_id = response_body[:runnerId]
runner_id.presence || raise(Runner::Error::Unknown.new('Poseidon did not send a runner id'))
runner_id.presence || raise(Runner::Error::UnexpectedResponse.new('Poseidon did not send a runner id'))
when 404
raise Runner::Error::EnvironmentNotFound.new
else
handle_error response
end
rescue Faraday::Error => e
raise Runner::Error::Unknown.new("Faraday request to runner management failed: #{e.inspect}")
raise Runner::Error::FaradayError.new("Request to Poseidon failed: #{e.inspect}")
end
def self.handle_error(response)
@ -51,7 +51,7 @@ class Runner::Strategy::Poseidon < Runner::Strategy
raise Runner::Error::InternalServerError.new("Poseidon sent #{response_body[:errorCode]}: #{response_body[:message]}")
end
else
raise Runner::Error::Unknown.new("Poseidon sent unexpected response status code #{response.status}")
raise Runner::Error::UnexpectedResponse.new("Poseidon sent unexpected response status code #{response.status}")
end
end
@ -59,7 +59,7 @@ class Runner::Strategy::Poseidon < Runner::Strategy
JSON.parse(response.body).deep_symbolize_keys
rescue JSON::ParserError => e
# Poseidon should not send invalid json
raise Runner::Error::Unknown.new("Error parsing response from Poseidon: #{e.message}")
raise Runner::Error::UnexpectedResponse.new("Error parsing response from Poseidon: #{e.message}")
end
def initialize(runner_id, _environment)
@ -82,7 +82,7 @@ class Runner::Strategy::Poseidon < Runner::Strategy
Runner.destroy(@allocation_id) if response.status == 400
self.class.handle_error response
rescue Faraday::Error => e
raise Runner::Error::Unknown.new("Faraday request to runner management failed: #{e.inspect}")
raise Runner::Error::FaradayError.new("Request to Poseidon failed: #{e.inspect}")
end
def attach_to_execution(command)
@ -99,7 +99,7 @@ class Runner::Strategy::Poseidon < Runner::Strategy
response = Faraday.delete runner_url
self.class.handle_error response unless response.status == 204
rescue Faraday::Error => e
raise Runner::Error::Unknown.new("Faraday request to runner management failed: #{e.inspect}")
raise Runner::Error::FaradayError.new("Request to Poseidon failed: #{e.inspect}")
end
private
@ -115,7 +115,7 @@ class Runner::Strategy::Poseidon < Runner::Strategy
if websocket_url.present?
return websocket_url
else
raise Runner::Error::Unknown.new('Poseidon did not send websocket url')
raise Runner::Error::UnexpectedResponse.new('Poseidon did not send websocket url')
end
when 400
Runner.destroy(@allocation_id)
@ -123,7 +123,7 @@ class Runner::Strategy::Poseidon < Runner::Strategy
self.class.handle_error response
rescue Faraday::Error => e
raise Runner::Error::Unknown.new("Faraday request to runner management failed: #{e.inspect}")
raise Runner::Error::FaradayError.new("Request to Poseidon failed: #{e.inspect}")
end
def runner_url
@ -134,7 +134,7 @@ class Runner::Strategy::Poseidon < Runner::Strategy
def decode(raw_event)
JSON.parse(raw_event.data)
rescue JSON::ParserError => e
raise Runner::Error::Unknown.new("The websocket message from Poseidon could not be decoded to JSON: #{e.inspect}")
raise Runner::Error::UnexpectedResponse.new("The websocket message from Poseidon could not be decoded to JSON: #{e.inspect}")
end
def encode(data)