Compare commits

...

3 Commits

Author SHA1 Message Date
3780ae004b
feat(cmd/joj3): show internal error msg in stage results
All checks were successful
submodules sync / sync (push) Successful in 40s
build / build (push) Successful in 1m34s
build / trigger-build-image (push) Successful in 7s
2024-10-29 17:29:35 -04:00
132a50833b
chore(parser/healthcheck): output in code format on error 2024-10-29 17:04:27 -04:00
cda3faeb9a
feat(parser): make stdout & stderr file in conf 2024-10-29 17:02:35 -04:00
5 changed files with 40 additions and 19 deletions

View File

@ -1,6 +1,7 @@
package stage
import (
"fmt"
"log/slog"
"github.com/joint-online-judge/JOJ3/cmd/joj3/conf"
@ -68,19 +69,24 @@ func generateStages(conf *conf.Conf, group string) ([]stage.Stage, error) {
return stages, nil
}
func Run(conf *conf.Conf, group string) (
stageResults []stage.StageResult, forceQuit bool, err error,
) {
stageResultsOnError := []stage.StageResult{
func newErrorStageResults(err error) []stage.StageResult {
return []stage.StageResult{
{
Name: "Internal Error",
Results: []stage.ParserResult{{
Score: 0,
Comment: "JOJ3 internal error, check the log in Gitea Actions.",
Score: 0,
Comment: "JOJ3 internal error, " +
"check the log in Gitea Actions.\n" +
fmt.Sprintf("Error: `%s`", err),
}},
ForceQuit: true,
},
}
}
func Run(conf *conf.Conf, group string) (
stageResults []stage.StageResult, forceQuit bool, err error,
) {
executors.InitWithConf(
conf.Stage.SandboxExecServer,
conf.Stage.SandboxToken,
@ -88,7 +94,7 @@ func Run(conf *conf.Conf, group string) (
stages, err := generateStages(conf, group)
if err != nil {
slog.Error("generate stages", "error", err)
stageResults = stageResultsOnError
stageResults = newErrorStageResults(err)
forceQuit = true
return
}
@ -96,7 +102,7 @@ func Run(conf *conf.Conf, group string) (
stageResults, forceQuit, err = stage.Run(stages)
if err != nil {
slog.Error("run stages", "error", err)
stageResults = stageResultsOnError
stageResults = newErrorStageResults(err)
forceQuit = true
return
}

View File

@ -17,13 +17,15 @@ type Conf struct {
Score int `default:"100"`
RootDir string `default:"/w"`
Matches []Match
Stdout string `default:"stdout"`
Stderr string `default:"stderr"`
}
type ClangTidy struct{}
func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
stdout := executorResult.Files["stdout"]
stderr := executorResult.Files["stderr"]
stdout := executorResult.Files[conf.Stdout]
stderr := executorResult.Files[conf.Stderr]
if executorResult.Status != stage.Status(envexec.StatusAccepted) {
if !((executorResult.Status == stage.Status(envexec.StatusNonzeroExitStatus)) &&
(executorResult.ExitStatus == 1)) {

View File

@ -19,6 +19,8 @@ type Match struct {
type Conf struct {
Score int `default:"100"`
Matches []Match
Stdout string `default:"stdout"`
Stderr string `default:"stderr"`
}
type Record struct {
@ -31,8 +33,8 @@ type Record struct {
}
func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
// stdout := executorResult.Files["stdout"]
stderr := executorResult.Files["stderr"]
// stdout := executorResult.Files[conf.Stdout]
stderr := executorResult.Files[conf.Stderr]
if executorResult.Status != stage.Status(envexec.StatusAccepted) {
return stage.ParserResult{

View File

@ -9,14 +9,19 @@ import (
type Healthcheck struct{}
func Parse(executorResult stage.ExecutorResult) (stage.ParserResult, bool) {
stdout := executorResult.Files["stdout"]
stderr := executorResult.Files["stderr"]
type Conf struct {
Stdout string `default:"stdout"`
Stderr string `default:"stderr"`
}
func Parse(executorResult stage.ExecutorResult, conf Conf) (stage.ParserResult, bool) {
stdout := executorResult.Files[conf.Stdout]
stderr := executorResult.Files[conf.Stderr]
if executorResult.Status != stage.Status(envexec.StatusAccepted) {
return stage.ParserResult{
Score: 0,
Comment: fmt.Sprintf(
"Unexpected executor status: %s.\nStdout: %s\nStderr: %s",
"Unexpected executor status: %s.\n`stdout`: ```%s\n```\n`stderr`: ```%s\n```",
executorResult.Status, stdout, stderr,
),
}, true
@ -30,10 +35,14 @@ func Parse(executorResult stage.ExecutorResult) (stage.ParserResult, bool) {
func (*Healthcheck) Run(results []stage.ExecutorResult, confAny any) (
[]stage.ParserResult, bool, error,
) {
conf, err := stage.DecodeConf[Conf](confAny)
if err != nil {
return nil, true, err
}
var res []stage.ParserResult
forceQuit := false
for _, result := range results {
parserResult, forceQuitResult := Parse(result)
parserResult, forceQuitResult := Parse(result, *conf)
res = append(res, parserResult)
forceQuit = forceQuit || forceQuitResult
}

View File

@ -12,13 +12,15 @@ import (
type Conf struct {
Score int
Comment string
Stdout string `default:"stdout"`
Stderr string `default:"stderr"`
}
type Sample struct{}
func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
stdout := executorResult.Files["stdout"]
stderr := executorResult.Files["stderr"]
stdout := executorResult.Files[conf.Stdout]
stderr := executorResult.Files[conf.Stderr]
if executorResult.Status != stage.Status(envexec.StatusAccepted) {
return stage.ParserResult{
Score: 0,