Skip to content

Commit

Permalink
forcing flushing in case of error
Browse files Browse the repository at this point in the history
  • Loading branch information
jt-dd committed Jan 14, 2025
1 parent 6a1ddae commit b92ce6b
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions pkg/kubehound/graph/adapter/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package adapter

import (
"context"
"errors"

"github.com/DataDog/KubeHound/pkg/kubehound/graph/types"
"github.com/DataDog/KubeHound/pkg/kubehound/storage/storedb"
Expand All @@ -24,18 +25,21 @@ func MongoDB(ctx context.Context, store storedb.Provider) *mongo.Database {
func MongoCursorHandler[T any](ctx context.Context, cur *mongo.Cursor,
callback types.ProcessEntryCallback, complete types.CompleteQueryCallback) error {

var lastErr error
for cur.Next(ctx) {
var entry T
err := cur.Decode(&entry)
if err != nil {
return err
lastErr = cur.Decode(&entry)
if lastErr != nil {
break
}

err = callback(ctx, &entry)
if err != nil {
return err
lastErr = callback(ctx, &entry)
if lastErr != nil {
break
}
}
err := complete(ctx)
err = errors.Join(err, lastErr)

return complete(ctx)
return err
}

0 comments on commit b92ce6b

Please sign in to comment.