This is an automated email from the ASF dual-hosted git repository. mmerli pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/pulsar-client-go.git
The following commit(s) were added to refs/heads/master by this push: new cb72395 fix nil pointer error with `GetPartitionedTopicMetadata` (#536) cb72395 is described below commit cb72395fb53fe24f20c75e2123dc9cae38603eaf Author: Rui Fu <freez...@users.noreply.github.com> AuthorDate: Tue Jun 15 09:27:09 2021 +0800 fix nil pointer error with `GetPartitionedTopicMetadata` (#536) * fix nil pointer error * update * fix lint * add more context in error msg --- pulsar/internal/lookup_service.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/pulsar/internal/lookup_service.go b/pulsar/internal/lookup_service.go index eb63077..0602080 100644 --- a/pulsar/internal/lookup_service.go +++ b/pulsar/internal/lookup_service.go @@ -190,11 +190,23 @@ func (ls *lookupService) GetPartitionedTopicMetadata(topic string) (*Partitioned } ls.log.Debugf("Got topic{%s} partitioned metadata response: %+v", topic, res) - if res.Response.PartitionMetadataResponse.Error != nil { - return nil, errors.New(res.Response.PartitionMetadataResponse.GetError().String()) + var partitionedTopicMetadata PartitionedTopicMetadata + + if res.Response.Error != nil { + return nil, errors.New(res.Response.GetError().String()) + } + + if res.Response.PartitionMetadataResponse != nil { + if res.Response.PartitionMetadataResponse.Error != nil { + return nil, errors.New(res.Response.PartitionMetadataResponse.GetError().String()) + } + + partitionedTopicMetadata.Partitions = int(res.Response.PartitionMetadataResponse.GetPartitions()) + } else { + return nil, fmt.Errorf("no partitioned metadata for topic{%s} in lookup response", topic) } - return &PartitionedTopicMetadata{Partitions: int(res.Response.PartitionMetadataResponse.GetPartitions())}, nil + return &partitionedTopicMetadata, nil } func (ls *lookupService) Close() {}