From 51571c52e0a91c9f91626c9618c06d7df1e8cec2 Mon Sep 17 00:00:00 2001 From: Jonathan Khoo Date: Sun, 19 May 2024 18:56:15 +1200 Subject: [PATCH] Improve judging errors on the submission page (#267) This adds a proper error message and hides test cases on the submission page when judging fails. --- app/models/submission.rb | 2 +- app/models/submission/judge_data.rb | 2 +- app/views/submissions/show.html.erb | 10 +++++++--- app/workers/judge_submission_worker.rb | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/models/submission.rb b/app/models/submission.rb index d1b6dcda..ed0bf29f 100644 --- a/app/models/submission.rb +++ b/app/models/submission.rb @@ -149,7 +149,7 @@ def update_test_messages judge_data = self.judge_data return if judge_data.status == :pending # incomplete judge_log - return if judge_data.errored? # judge errored - very bad + return if judge_data.data.has_key?('error') # judge errored - very bad errors = [] warnings = [] diff --git a/app/models/submission/judge_data.rb b/app/models/submission/judge_data.rb index ed8f3c87..78b843f4 100644 --- a/app/models/submission/judge_data.rb +++ b/app/models/submission/judge_data.rb @@ -274,7 +274,7 @@ def initialize(log, test_sets, test_cases, prerequisite_sets = []) end def errored? - data.has_key?('error') + data.has_key?('error') || status == :error end def completed? diff --git a/app/views/submissions/show.html.erb b/app/views/submissions/show.html.erb index 8ebfaae9..e2719429 100644 --- a/app/views/submissions/show.html.erb +++ b/app/views/submissions/show.html.erb @@ -5,7 +5,12 @@ <%= stylesheet_link_tag "submission" %> -<% if @submission.score == nil %> +<% @judge_data = @submission.judge_data %> +<% if @judge_data.errored? %> +

+ An unexpected error has occurred during judging. Please retry the submission, or contact us at <%= mail_to "nzic@nzoi.org.nz" %> if the error persists. +

+<% elsif @submission.score == nil %>

This submission has not finished judging. Refresh this page in a minute or two to see the submission's score.

@@ -46,7 +51,6 @@ <% end %>

-<% @judge_data = @submission.judge_data %> <% if @judge_data.compiled? %> @@ -76,7 +80,7 @@
<% end %> - <% if !@judge_data.compiled? || @judge_data.compilation.status == :success %> + <% if !@judge_data.errored? && (!@judge_data.compiled? || @judge_data.compilation.status == :success) %> diff --git a/app/workers/judge_submission_worker.rb b/app/workers/judge_submission_worker.rb index 238e5973..8d862905 100644 --- a/app/workers/judge_submission_worker.rb +++ b/app/workers/judge_submission_worker.rb @@ -46,7 +46,7 @@ def perform(submission_id) rescue StandardError => e unless self.submission.nil? submission.reload - submission.judge_log = {'error' => {'message' => e.message, 'backtrace' => e.backtrace}}.to_json + submission.judge_log = {'error' => {'message' => e.message, 'backtrace' => e.backtrace}, 'status' => 2}.to_json submission.save end raise
Time