fix(parser/log): handle non json input
This commit is contained in:
parent
8155de0c92
commit
e800bc5c2a
|
|
@ -12,7 +12,9 @@ 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)
|
||||
contentBytes := []byte(content)
|
||||
if json.Valid(contentBytes) {
|
||||
err := json.Unmarshal(contentBytes, &data)
|
||||
if err != nil {
|
||||
slog.Error(conf.Msg, "error", err)
|
||||
return stage.ParserResult{
|
||||
|
|
@ -30,6 +32,15 @@ func (*Log) parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserRe
|
|||
conf.Msg,
|
||||
args...,
|
||||
)
|
||||
} else {
|
||||
slog.Default().Log(
|
||||
context.Background(),
|
||||
slog.Level(conf.Level),
|
||||
conf.Msg,
|
||||
"content",
|
||||
content,
|
||||
)
|
||||
}
|
||||
return stage.ParserResult{
|
||||
Score: 0,
|
||||
Comment: "",
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user