Skip to content

Commit

Permalink
fix nil pointer error with GetPartitionedTopicMetadata (#536)
Browse files Browse the repository at this point in the history
* fix nil pointer error

* update

* fix lint

* add more context in error msg
  • Loading branch information
freeznet committed Jun 15, 2021
1 parent 8a78d2c commit cb72395
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions pulsar/internal/lookup_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Expand Down

0 comments on commit cb72395

Please sign in to comment.