feat: add dummy error example
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
27a1e4420e
commit
38d1c18471
27
examples/dummy_error/conf.toml
Normal file
27
examples/dummy_error/conf.toml
Normal 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
10
examples/dummy_error/run.sh
Executable 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 -
|
|
@ -2,7 +2,6 @@ package dummy
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
)
|
||||
|
||||
type Conf struct {
|
||||
|
@ -16,7 +15,10 @@ type Result struct {
|
|||
|
||||
func Run(conf Conf) (res Result, err error) {
|
||||
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)
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user