fix(parser/log): handle non json input
All checks were successful
submodules sync / sync (push) Successful in 50s
build / build (push) Successful in 2m54s
build / trigger-build-image (push) Successful in 18s

This commit is contained in:
张泊明518370910136 2025-11-27 22:09:49 -08:00
parent 8155de0c92
commit e800bc5c2a
GPG Key ID: D47306D7062CDA9D

View File

@ -12,24 +12,35 @@ import (
func (*Log) parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
content := executorResult.Files[conf.Filename]
var data map[string]any
err := json.Unmarshal([]byte(content), &data)
if err != nil {
slog.Error(conf.Msg, "error", err)
return stage.ParserResult{
Score: 0,
Comment: fmt.Sprintf("Failed to parse content: %s", err),
contentBytes := []byte(content)
if json.Valid(contentBytes) {
err := json.Unmarshal(contentBytes, &data)
if err != nil {
slog.Error(conf.Msg, "error", err)
return stage.ParserResult{
Score: 0,
Comment: fmt.Sprintf("Failed to parse content: %s", err),
}
}
args := make([]any, 0, len(data)*2)
for key, value := range data {
args = append(args, key, value)
}
slog.Default().Log(
context.Background(),
slog.Level(conf.Level),
conf.Msg,
args...,
)
} else {
slog.Default().Log(
context.Background(),
slog.Level(conf.Level),
conf.Msg,
"content",
content,
)
}
args := make([]any, 0, len(data)*2)
for key, value := range data {
args = append(args, key, value)
}
slog.Default().Log(
context.Background(),
slog.Level(conf.Level),
conf.Msg,
args...,
)
return stage.ParserResult{
Score: 0,
Comment: "",