diff --git a/cmd/omegaup-runner/main.go b/cmd/omegaup-runner/main.go index 72200f0..313ae51 100644 --- a/cmd/omegaup-runner/main.go +++ b/cmd/omegaup-runner/main.go @@ -474,7 +474,9 @@ func runOneshotCI(ctx *common.Context, sandbox runner.Sandbox) *ci.Report { "grade", strconv.FormatUint(run.AttemptID, 10), ) - defer os.RemoveAll(runRoot) + if !ctx.Config.Runner.PreserveFiles { + defer os.RemoveAll(runRoot) + } result, err := runner.Grade(ctx, nil, &run, inputRef.Input, sandbox) if err != nil { @@ -491,10 +493,18 @@ func runOneshotCI(ctx *common.Context, sandbox runner.Sandbox) *ci.Report { ctx.Log.Error( "Error generating outputs", map[string]any{ - "config": runConfig.OutGeneratorConfig, - "err": err, + "config": runConfig.OutGeneratorConfig, + "compileError": result.CompileError, + "err": err, }, ) + if result.CompileError != nil { + return errors.Errorf( + "expecting a verdict of {AC, PA, WA}; got %s:\n%q", + result.Verdict, + *result.CompileError, + ) + } return errors.Errorf( "expecting a verdict of {AC, PA, WA}; got %s", result.Verdict, @@ -675,7 +685,9 @@ func runOneshotCI(ctx *common.Context, sandbox runner.Sandbox) *ci.Report { }, ) } - os.RemoveAll(runRoot) + if !ctx.Config.Runner.PreserveFiles { + os.RemoveAll(runRoot) + } }() } @@ -747,7 +759,7 @@ func main() { ) os.Exit(1) } - if os.Getenv("PRESERVE") != "" { + if os.Getenv("PRESERVE") != "" || *oneshot == "ci" { ctx.Config.Runner.PreserveFiles = true } if !ctx.Config.Runner.PreserveFiles { @@ -801,7 +813,7 @@ func main() { } if *resultsOutputDirectory != "" { { - f, err := os.Create(path.Join(*resultsOutputDirectory, "ci.log")) + err := os.WriteFile(path.Join(*resultsOutputDirectory, "ci.log"), ctx.LogBuffer(), 0o644) if err != nil { ctx.Log.Error( "Failed to create log file", @@ -809,17 +821,6 @@ func main() { "err": err, }, ) - } else { - _, err = f.Write(ctx.LogBuffer()) - f.Close() - if err != nil { - ctx.Log.Error( - "Failed to write log file", - map[string]any{ - "err": err, - }, - ) - } } } { diff --git a/runner/sandbox.go b/runner/sandbox.go index a5de671..af9332e 100644 --- a/runner/sandbox.go +++ b/runner/sandbox.go @@ -399,10 +399,24 @@ func (o *OmegajailSandbox) invokeOmegajail(ctx *common.Context, omegajailParams cmd.Stderr = omegajailErrorFd } if err := cmd.Run(); err != nil { + var output string + if omegajailErrorFd != nil { + b, err := os.ReadFile(omegajailErrorFile) + if err == nil { + output = string(b) + } + } + if output == "" { + b, err := os.ReadFile(errorFile) + if err == nil { + output = string(b) + } + } ctx.Log.Error( "Omegajail execution failed", map[string]any{ "err": err, + "out": output, }, ) }