func Invoke() in invoke.go assumes opts is non-nil
RidhwaanDev opened this issue · 1 comments
RidhwaanDev commented
Invoke() in invoke.go iterates opts... but does not check if it is nil. This means the user must supply a CallOption, which doesn't make sense since naturally if you don't want any options you pass nil. This is what I do in my code since I could not find any default CallOption in the documentation.
func Invoke(ctx context.Context, call APICall, opts ...CallOption) error {
var settings CallSettings
for _, opt := range opts {
--> opt.Resolve(&settings)
}
return invoke(ctx, call, settings, Sleep)
}
My code that eventually hits Invoke() method in googleapis/gax-go/v2/invoke.go
operation, err := client.AsyncBatchAnnotateFiles(ctx, request)
pollResp, err := operation.Poll(ctx, nil) // passing nil causes nil ptr dereference, panic :(
Above code gives the following error:
net/http.(*conn).serve.func1(0xc00031c6e0)
/usr/local/go/src/net/http/server.go:1801 +0x147
panic(0x16e36e0, 0x1c9bbf0)
/usr/local/go/src/runtime/panic.go:975 +0x47a
github.com/googleapis/gax-go/v2.Invoke(0x18a4be0, 0xc000612600, 0xc000449588, 0xc0000d8700, 0x2, 0x2, 0x1, 0x2)
/Users/ridhwaan/go/pkg/mod/github.com/googleapis/gax-go/v2@v2.0.5/invoke.go:46 +0x76
cloud.google.com/go/longrunning/autogen.(*OperationsClient).GetOperation(0xc0007860c0, 0x18a4be0, 0xc000612600, 0xc0003124c0, 0xc00051edc0, 0x1, 0x2, 0x0, 0x0, 0x0)
/Users/ridhwaan/go/pkg/mod/cloud.google.com/go@v0.80.0/longrunning/autogen/operations_client.go:259 +0x37a
cloud.google.com/go/longrunning.(*Operation).Poll(0xc0000d86c0, 0x18a4b60, 0xc00003a060, 0x18a2ee0, 0xc000312480, 0xc00051edc0, 0x1, 0x1, 0x16a7fc0, 0x1ce7a01)
/Users/ridhwaan/go/pkg/mod/cloud.google.com/go@v0.80.0/longrunning/longrunning.go:96 +0x2df
RidhwaanDev commented
Okay, if you don't want to pass in options, just do this
pollResp, err := operation.Poll(ctx)