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

This commit is contained in:
张泊明518370910136 2024-10-29 17:29:35 -04:00
parent 132a50833b
commit 3780ae004b
GPG Key ID: D47306D7062CDA9D

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.",
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
}