Skip to content

Commit

Permalink
fix: as smuggle hook can return nil, check for nil just after
Browse files Browse the repository at this point in the history
Signed-off-by: Maxime Soulé <btik-git@scoubidou.com>
  • Loading branch information
maxatome committed Mar 24, 2024
1 parent 5198bbf commit c874f10
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
20 changes: 10 additions & 10 deletions td/equal.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,9 @@ func deepValueEqual(ctx ctxerr.Context, got, expected reflect.Value) (err *ctxer
expected = op
}

if !got.IsValid() || !expected.IsValid() {
if got.IsValid() == expected.IsValid() {
return
}
return nilHandler(ctx, got, expected)
}

// Check if a Smuggle hook matches got type
if handled, e := ctx.Hooks.Smuggle(&got); handled {
if e != nil {
if got.IsValid() {
// Check if a Smuggle hook matches got type
if handled, e := ctx.Hooks.Smuggle(&got); handled && e != nil {
// ctx.BooleanError is always false here as hooks cannot be set globally
return ctx.CollectError(&ctxerr.Error{
Message: e.Error(),
Expand All @@ -159,6 +152,13 @@ func deepValueEqual(ctx ctxerr.Context, got, expected reflect.Value) (err *ctxer
}
}

if !got.IsValid() || !expected.IsValid() {
if got.IsValid() == expected.IsValid() {
return
}
return nilHandler(ctx, got, expected)
}

// Check if a Cmp hook matches got & expected types
if handled, e := ctx.Hooks.Cmp(got, expected); handled {
if e == nil {
Expand Down
4 changes: 2 additions & 2 deletions td/t_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
// Each function in fns has to be a function with the following
// possible signatures:
//
// func (got A, expected A) bool
// func (got A, expected A) error
// func (got, expected A) bool
// func (got, expected A) error
//
// First arg is always got, and second is always expected.
//
Expand Down

0 comments on commit c874f10

Please sign in to comment.