Change default of raise_exception for execute_command

This commit is contained in:
Sebastian Serth
2021-10-30 01:13:32 +02:00
parent 4f1a7cde27
commit 1609bd2e0e
4 changed files with 5 additions and 5 deletions

View File

@ -31,8 +31,8 @@ class ExecutionEnvironmentsController < ApplicationController
def execute_command def execute_command
runner = Runner.for(current_user, @execution_environment) runner = Runner.for(current_user, @execution_environment)
output = runner.execute_command(params[:command]) output = runner.execute_command(params[:command], raise_exception: false)
render(json: output) render json: output
end end
def working_time_query def working_time_query

View File

@ -79,7 +79,7 @@ class ExecutionEnvironment < ApplicationRecord
def working_docker_image? def working_docker_image?
runner = Runner.for(author, self) runner = Runner.for(author, self)
output = runner.execute_command(VALIDATION_COMMAND, raise_exception: true) output = runner.execute_command(VALIDATION_COMMAND)
errors.add(:docker_image, "error: #{output[:stderr]}") if output[:stderr].present? errors.add(:docker_image, "error: #{output[:stderr]}") if output[:stderr].present?
rescue Runner::Error => e rescue Runner::Error => e
errors.add(:docker_image, "error: #{e}") errors.add(:docker_image, "error: #{e}")

View File

@ -64,7 +64,7 @@ class Runner < ApplicationRecord
Time.zone.now - starting_time # execution duration Time.zone.now - starting_time # execution duration
end end
def execute_command(command, raise_exception: false) def execute_command(command, raise_exception: true)
output = {} output = {}
stdout = +'' stdout = +''
stderr = +'' stderr = +''

View File

@ -162,7 +162,7 @@ describe ExecutionEnvironment do
it 'executes the validation command' do it 'executes the validation command' do
allow(runner).to receive(:execute_command).and_return({}) allow(runner).to receive(:execute_command).and_return({})
working_docker_image? working_docker_image?
expect(runner).to have_received(:execute_command).with(ExecutionEnvironment::VALIDATION_COMMAND, raise_exception: true) expect(runner).to have_received(:execute_command).with(ExecutionEnvironment::VALIDATION_COMMAND)
end end
context 'when the command produces an error' do context 'when the command produces an error' do