fix(parser/log): handle non json input
This commit is contained in:
parent
8155de0c92
commit
e800bc5c2a
|
|
@ -12,24 +12,35 @@ import (
|
||||||
func (*Log) parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
|
func (*Log) parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
|
||||||
content := executorResult.Files[conf.Filename]
|
content := executorResult.Files[conf.Filename]
|
||||||
var data map[string]any
|
var data map[string]any
|
||||||
err := json.Unmarshal([]byte(content), &data)
|
contentBytes := []byte(content)
|
||||||
if err != nil {
|
if json.Valid(contentBytes) {
|
||||||
slog.Error(conf.Msg, "error", err)
|
err := json.Unmarshal(contentBytes, &data)
|
||||||
return stage.ParserResult{
|
if err != nil {
|
||||||
Score: 0,
|
slog.Error(conf.Msg, "error", err)
|
||||||
Comment: fmt.Sprintf("Failed to parse content: %s", 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{
|
return stage.ParserResult{
|
||||||
Score: 0,
|
Score: 0,
|
||||||
Comment: "",
|
Comment: "",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user