Skip to content

Commit

Permalink
Make compilation errors more visible (#111)
Browse files Browse the repository at this point in the history
This makes compilation errors appear front and center when they occur.
  • Loading branch information
lhchavez authored Jan 23, 2023
1 parent 1cf39af commit 49bbb9b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 17 deletions.
35 changes: 18 additions & 17 deletions cmd/omegaup-runner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down Expand Up @@ -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)
}
}()
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -801,25 +813,14 @@ 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",
map[string]any{
"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,
},
)
}
}
}
{
Expand Down
14 changes: 14 additions & 0 deletions runner/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
)
}
Expand Down

0 comments on commit 49bbb9b

Please sign in to comment.