diff --git a/examples/dummy_error/conf.toml b/examples/dummy_error/conf.toml new file mode 100644 index 0000000..72576e5 --- /dev/null +++ b/examples/dummy_error/conf.toml @@ -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" diff --git a/examples/dummy_error/run.sh b/examples/dummy_error/run.sh new file mode 100755 index 0000000..9088452 --- /dev/null +++ b/examples/dummy_error/run.sh @@ -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 - diff --git a/pkg/dummy/dummy.go b/pkg/dummy/dummy.go index 1248dd7..938a7f4 100644 --- a/pkg/dummy/dummy.go +++ b/pkg/dummy/dummy.go @@ -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 }