-
Notifications
You must be signed in to change notification settings - Fork 49
Open
Description
Trying to compare identical empty objects or other simple objects results in a panic if no options are provided. The name is a little misleading since options imply (to me at least) that they are not required.
For instance:
diff, _ := jsondiff.Compare([]byte({}), []byte({}), nil)
Adding opts := DefaultConsoleOptions() and passing it in (as in the unit tests) prevent it from panicking. I didn't get a chance to see what it is expecting just yet.
Output:
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x5b272a]
goroutine 6 [running]:
testing.tRunner.func1.1(0x5d7ce0, 0x760ed0)
/usr/local/go-faketime/src/testing/testing.go:1076 +0x30d
testing.tRunner.func1(0xc000001b00)
/usr/local/go-faketime/src/testing/testing.go:1079 +0x41a
panic(0x5d7ce0, 0x760ed0)
/usr/local/go-faketime/src/runtime/panic.go:969 +0x175
github.com/nsf/jsondiff.(*context).printDiff(0xc000045ec0, 0x5d6c60, 0xc000073260, 0x5d6c60, 0xc000073290)
/tmp/gopath249660858/pkg/mod/github.com/nsf/jsondiff@v0.0.0-20200515183724-f29ed568f4ce/jsondiff.go:329 +0x4ea
github.com/nsf/jsondiff.Compare(0xc00002c9b0, 0x8, 0x8, 0xc00002c9b8, 0x8, 0x8, 0x0, 0x4b5a86, 0x4af9f070, 0x0)
/tmp/gopath249660858/pkg/mod/github.com/nsf/jsondiff@v0.0.0-20200515183724-f29ed568f4ce/jsondiff.go:414 +0x296
main.Test_jsondiffnoopts(0xc000001b00)
/tmp/sandbox175228423/prog.go:11 +0xaa
testing.tRunner(0xc000001b00, 0x61efb8)
/usr/local/go-faketime/src/testing/testing.go:1127 +0xef
created by testing.(*T).Run
/usr/local/go-faketime/src/testing/testing.go:1178 +0x386
Simple examples here: https://play.golang.org/p/vSdHmaOY3zw
On a different note, thank you for sharing this repo. I have a project where we are not using it for debugging, but it is useful for finding superset matches in arbitrary json bodies.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels