From d50e6d30e9f7214223fb66182e3627d7fdf54690 Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Mon, 14 Nov 2022 13:51:04 +0100 Subject: [PATCH] List Files: Catch more Runner::Errors --- app/controllers/execution_environments_controller.rb | 2 +- app/models/runner.rb | 3 +++ lib/runner/connection.rb | 7 ++++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/controllers/execution_environments_controller.rb b/app/controllers/execution_environments_controller.rb index 7deebf19..9c4d3f87 100644 --- a/app/controllers/execution_environments_controller.rb +++ b/app/controllers/execution_environments_controller.rb @@ -44,7 +44,7 @@ class ExecutionEnvironmentsController < ApplicationController downloadable_files, additional_directories = convert_files_json_to_files files js_tree = FileTree.new(downloadable_files, additional_directories, force_closed: true).to_js_tree render json: js_tree[:core][:data] - rescue Runner::Error::WorkspaceError + rescue Runner::Error::RunnerNotFound, Runner::Error::WorkspaceError render json: [] end end diff --git a/app/models/runner.rb b/app/models/runner.rb index f6475dac..2199a12e 100644 --- a/app/models/runner.rb +++ b/app/models/runner.rb @@ -77,6 +77,9 @@ class Runner < ApplicationRecord ensure # We forward the exception if requested raise e if raise_exception && defined?(e) && e.present? + + # Otherwise, we return an hash with empty files + {'files' => []} end end diff --git a/lib/runner/connection.rb b/lib/runner/connection.rb index 5900eb0a..9ab3e03e 100644 --- a/lib/runner/connection.rb +++ b/lib/runner/connection.rb @@ -146,7 +146,12 @@ class Runner::Connection @strategy.destroy_at_management @error = Runner::Error::ExecutionTimeout.new('Execution exceeded its time limit') when :terminated_by_codeocean, :terminated_by_management - @exit_callback.call @exit_code, @strategy.retrieve_files + files = begin + @strategy.retrieve_files + rescue Runner::Error::RunnerNotFound, Runner::Error::WorkspaceError + {'files' => []} + end + @exit_callback.call @exit_code, files when :terminated_by_client, :error @strategy.destroy_at_management else # :established