@@ -8,6 +8,8 @@ defmodule Codebattle.CodeCheck.Checker do
88
99 require Logger
1010
11+ @ failure_results ~w( error service_failure service_timeout timeout)
12+
1113 @ spec call ( Codebattle.Task . t ( ) , String . t ( ) , String . t ( ) , CodeCheck . check_meta ( ) ) :: CodeCheck . check_result ( )
1214 def call ( task , solution_text , lang_slug , meta \\ % { } ) do
1315 lang_meta = Languages . meta ( lang_slug )
@@ -53,7 +55,8 @@ defmodule Codebattle.CodeCheck.Checker do
5355 lang: token . lang_meta . slug ,
5456 started_at: started_at ,
5557 duration_ms: token . execution_time_msec ,
56- result: token . result . status
58+ result: token . result . status ,
59+ error_description: run_error_description ( token . result )
5760 } )
5861 end
5962
@@ -71,6 +74,38 @@ defmodule Codebattle.CodeCheck.Checker do
7174
7275 defp maybe_emit_telemetry ( _token , _meta ) , do: :ok
7376
77+ defp run_error_description ( % { status: status } = result ) when status in @ failure_results do
78+ description =
79+ cond do
80+ is_binary ( result [ :output_error ] ) and String . trim ( result [ :output_error ] ) != "" ->
81+ result [ :output_error ]
82+
83+ is_binary ( result [ :output ] ) and String . trim ( result [ :output ] ) != "" ->
84+ result [ :output ]
85+
86+ status in [ "service_timeout" , "timeout" ] ->
87+ "Code check execution timed out"
88+
89+ true ->
90+ nil
91+ end
92+
93+ normalize_error_description ( description )
94+ end
95+
96+ defp run_error_description ( _result ) , do: nil
97+
98+ defp normalize_error_description ( nil ) , do: nil
99+
100+ defp normalize_error_description ( description ) when is_binary ( description ) do
101+ description
102+ |> String . trim ( )
103+ |> case do
104+ "" -> nil
105+ trimmed -> String . slice ( trimmed , 0 , 4_000 )
106+ end
107+ end
108+
74109 defp get_executor do
75110 if FunWithFlags . enabled? ( :use_remote_zig_executor ) do
76111 Codebattle.CodeCheck.Executor.RemoteZig
0 commit comments