@@ -19,6 +19,7 @@ import (
1919 "encoding/csv"
2020 "fmt"
2121 "os/signal"
22+ "reflect"
2223 "slices"
2324 "syscall"
2425 "time"
@@ -246,6 +247,19 @@ func AnnotateWrite(path string, out <-chan string, wg *sync.WaitGroup) {
246247 log .Debug ("write thread finished" )
247248}
248249
250+ func isPtrNil (i any ) bool {
251+ if i == nil {
252+ return true
253+ }
254+ val := reflect .ValueOf (i )
255+ switch val .Kind () {
256+ case reflect .Pointer , reflect .Interface , reflect .Slice , reflect .Map :
257+ return val .IsNil ()
258+ default :
259+ return false
260+ }
261+ }
262+
249263func AnnotateWorker (conf * GlobalConf , a Annotator , inChan <- chan inProcessIP ,
250264 outChan chan <- inProcessIP , fieldName string , wg * sync.WaitGroup , i int ) {
251265 name := a .GetFieldName ()
@@ -257,9 +271,18 @@ func AnnotateWorker(conf *GlobalConf, a Annotator, inChan <-chan inProcessIP,
257271 for inProcess := range inChan {
258272 if fieldName != "" && slices .Contains ([]string {"json" , "csv" }, conf .InputFileType ) {
259273 p := inProcess .Out [fieldName ].(map [string ]interface {})
260- p [name ] = a .Annotate (inProcess .Ip )
274+ res := a .Annotate (inProcess .Ip )
275+ if isPtrNil (res ) {
276+ res = struct {}{} // Don't return null, breaks downstream JSON parsing
277+ }
278+ p [name ] = res
279+
261280 } else {
262- inProcess .Out [name ] = a .Annotate (inProcess .Ip )
281+ res := a .Annotate (inProcess .Ip )
282+ if isPtrNil (res ) {
283+ res = struct {}{} // Don't return null, breaks downstream JSON parsing
284+ }
285+ inProcess .Out [name ] = res
263286 }
264287 outChan <- inProcess
265288 }
0 commit comments