diff --git a/pkg/comparator/struct.go b/pkg/comparator/struct.go index c54d4f8..9f5a834 100644 --- a/pkg/comparator/struct.go +++ b/pkg/comparator/struct.go @@ -46,7 +46,7 @@ func (c *StructComparator) Compare(ctx context.Context, oldVal, newVal reflect.V continue } - if diff := diff.GenerateChangedDiff(ctx, typeField.Name, oldField, newField); diff != nil { + if diff := diff.GenerateChangedDiff(ctx, typeField.Name, filteredOldValue, filteredNewValue); diff != nil { diffs = append(diffs, *diff) } } diff --git a/pkg/diff/generator.go b/pkg/diff/generator.go index 159745e..0cc5af2 100644 --- a/pkg/diff/generator.go +++ b/pkg/diff/generator.go @@ -25,6 +25,11 @@ func GenerateRemovedDiff(ctx context.Context, obj reflect.Value) Diff { func GenerateChangedDiff(ctx context.Context, fieldName string, oldVal, newVal reflect.Value) *Diff { var oldI, newI interface{} + + if !oldVal.IsValid() || !newVal.IsValid() { + return nil + } + switch oldVal.Kind() { case reflect.Array, reflect.Slice: oldI = reflectArrayToString(ctx, oldVal)