feat: add dummy error example
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
张泊明518370910136 2024-03-12 16:38:55 -04:00
parent 27a1e4420e
commit 38d1c18471
GPG Key ID: D47306D7062CDA9D
3 changed files with 41 additions and 2 deletions

View File

@ -0,0 +1,27 @@
[[stages]]
name = "dummy"
[stages.executor]
name = "sandbox"
[stages.executor.with.default]
args = ["./dummy", "--score", "-1"]
env = ["PATH=/usr/bin:/bin"]
cpuLimit = 10_000_000_000
memoryLimit = 104_857_600
procLimit = 50
copyInCwd = true
[stages.executor.with.default.copyIn.dummy]
src = "./../../build/dummy"
copyOut = ["stdout", "stderr"]
[stages.executor.with.default.stdin]
content = ""
[stages.executor.with.default.stdout]
name = "stdout"
max = 4_096
[stages.executor.with.default.stderr]
name = "stderr"
max = 4_096
[stages.parser]
name = "dummy"
[stages.parser.with]
score = 10
comment = " + comment from toml conf"

10
examples/dummy_error/run.sh Executable file
View File

@ -0,0 +1,10 @@
#!/usr/bin/env bash
set -xe
DIRNAME=`dirname -- "$0"`
# cd to make CopyInCwd work
cd $DIRNAME
./../../build/joj3
cat ./joj3_result.json
rm -f ./joj3_result.json
cd -

View File

@ -2,7 +2,6 @@ package dummy
import ( import (
"fmt" "fmt"
"log/slog"
) )
type Conf struct { type Conf struct {
@ -16,7 +15,10 @@ type Result struct {
func Run(conf Conf) (res Result, err error) { func Run(conf Conf) (res Result, err error) {
if conf.Score < 0 { if conf.Score < 0 {
slog.Error("dummy negative score", "score", conf.Score) // Just return the error here instead of logging, as it is run inside
// the sandbox, the logs will not show in drone output directly.
// If there are more kinds of errors need to be handled separately, add
// more fields in the Result struct, don't mess everything up in Stderr.
err = fmt.Errorf("dummy negative score: %d", conf.Score) err = fmt.Errorf("dummy negative score: %d", conf.Score)
return return
} }