Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return more clearly topic error message #1162

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion kafka/producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,10 @@ func (p *Producer) gethandle() *handle {
}

func (p *Producer) produce(msg *Message, msgFlags int, deliveryChan chan Event) error {
if msg == nil || msg.TopicPartition.Topic == nil || len(*msg.TopicPartition.Topic) == 0 {
if msg == nil || len(*msg.TopicPartition.Topic) == 0 {
return newErrorFromString(ErrInvalidArg, "")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if msg == nil || len(*msg.TopicPartition.Topic) == 0 {
return newErrorFromString(ErrInvalidArg, "")
if msg == nil {
return newErrorFromString(ErrInvalidArg, "msg cannot be nil")

}else if msg.TopicPartition.Topic == nil{
return newErrorFromString(ErrUnknownTopic, "topic is null, please check")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}else if msg.TopicPartition.Topic == nil{
return newErrorFromString(ErrUnknownTopic, "topic is null, please check")
} else if msg.TopicPartition.Topic == nil || len(*msg.TopicPartition.Topic) == 0 {
return newErrorFromString(ErrInvalidArg, "topic cannot be nil or empty")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We must keep in mind, 2 things,

  1. msg.TopicPartition.Topic == nil must be made before len(*msg.TopicPartition.Topic) == 0 , else it causes a nil pointer dereference and will panic.
  2. We can't change the type of the error, only the message of it (since the type is a part of the public API so people might be relying on that)

}

crkt := p.handle.getRkt(*msg.TopicPartition.Topic)
Expand Down