I have some binaries and other random stuff in this directory. While I may understand seeing an error, we should probably be a bit more defensive and protect against this panic. The same behavior was seen in the new pruning command.
$ sensuctl create -f bin
resource 0: error parsing spec: type could not be found: ""
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x49eed66]
goroutine 1 [running]:
github.com/sensu/sensu-go/cli/resource.Parse(0x5009d60, 0xc0002860c0, 0x0, 0xc000000000, 0xc0002860c0, 0x0, 0x0)
/Users/splourde/go/pkg/mod/github.com/sensu/[email protected]/cli/resource/parse.go:74 +0x2b6
github.com/sensu/sensu-go/cli/resource.ProcessFile.func1(0xc000282a20, 0xf, 0x5031580, 0xc0003aa340, 0x0, 0x0, 0xb, 0xc00024ba60)
/Users/splourde/go/pkg/mod/github.com/sensu/[email protected]/cli/resource/process.go:60 +0x140
path/filepath.walk(0xc000282a20, 0xf, 0x5031580, 0xc0003aa340, 0xc00024bc18, 0x0, 0xc000088390)
/usr/local/go/src/path/filepath/path.go:358 +0x425
path/filepath.walk(0xc00027b530, 0x3, 0x5031580, 0xc0003401a0, 0xc00024bc18, 0x0, 0xc00027b530)
/usr/local/go/src/path/filepath/path.go:382 +0x2ff
path/filepath.Walk(0xc00027b530, 0x3, 0xc00024bc18, 0x0, 0x3)
/usr/local/go/src/path/filepath/path.go:404 +0xff
github.com/sensu/sensu-go/cli/resource.ProcessFile(0xc0001f2db0, 0xc00027b530, 0x3, 0x0, 0x5008f00, 0x5952a20, 0x4c4d160, 0x585f2a0)
/Users/splourde/go/pkg/mod/github.com/sensu/[email protected]/cli/resource/process.go:46 +0xb8
github.com/sensu/sensu-go/cli/resource.Process(0xc0001f2db0, 0xc00030dce0, 0xc00027b530, 0x3, 0x0, 0x5008f00, 0x5952a20, 0x0, 0x48b3804)
/Users/splourde/go/pkg/mod/github.com/sensu/[email protected]/cli/resource/process.go:38 +0xa2
github.com/sensu/sensu-go/cli/commands/create.execute.func1(0xc000326000, 0xc0002d4e40, 0x0, 0x4, 0x0, 0x0)
/Users/splourde/go/pkg/mod/github.com/sensu/[email protected]/cli/commands/create/create.go:48 +0x242
github.com/spf13/cobra.(*Command).execute(0xc000326000, 0xc0002d4d80, 0x4, 0x4, 0xc000326000, 0xc0002d4d80)
/Users/splourde/go/pkg/mod/github.com/spf13/[email protected]/command.go:826 +0x460
github.com/spf13/cobra.(*Command).ExecuteC(0xc0002af680, 0xc0001f2db0, 0x0, 0x0)
/Users/splourde/go/pkg/mod/github.com/spf13/[email protected]/command.go:914 +0x2fb
github.com/spf13/cobra.(*Command).Execute(...)
/Users/splourde/go/pkg/mod/github.com/spf13/[email protected]/command.go:864
main.main()
/Users/splourde/src/sensu-enterprise-go/cmd/sensuctl/main.go:36 +0xcc
exit status 2
This should be investigated alongside https://github.com/sensu/sensu-go/issues/3586.
This is unrelated to #3586, as it's just a nil pointer dereference bug. We just need to check for nil after unmarshal.