1
0
mirror of https://github.com/amir20/dozzle.git synced 2026-01-04 12:05:07 +01:00

fix: hides errors when trying to parse simple numbers as json. fixes #2510 (#2512)

This commit is contained in:
Amir Raminfar
2023-11-18 07:52:27 -08:00
committed by GitHub
parent 0ad8f32588
commit 70e0c359da
2 changed files with 16 additions and 1 deletions

View File

@@ -5,6 +5,7 @@ import (
"bytes"
"encoding/binary"
"encoding/json"
"errors"
"fmt"
"hash/fnv"
"io"
@@ -164,7 +165,12 @@ func createEvent(message string, streamType StdType) *LogEvent {
if json.Valid([]byte(message)) {
var data map[string]interface{}
if err := json.Unmarshal([]byte(message), &data); err != nil {
log.Warnf("unable to parse json logs - error was \"%v\" while trying unmarshal \"%v\"", err.Error(), message)
var jsonErr *json.UnmarshalTypeError
if errors.As(err, &jsonErr) {
if jsonErr.Value == "string" {
log.Warnf("unable to parse json logs - error was \"%v\" while trying unmarshal \"%v\"", err.Error(), message)
}
}
} else {
logEvent.Message = data
}

View File

@@ -117,6 +117,15 @@ func Test_createEvent(t *testing.T) {
Message: "{\"key\"}",
},
},
{
name: "invalid json message",
args: args{
message: "2020-05-13T18:55:37.772853839Z 123",
},
want: &LogEvent{
Message: "123",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {