-
Notifications
You must be signed in to change notification settings - Fork 663
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
base: master
Are you sure you want to change the base?
Conversation
topic error was catch in ErrInvalidArg but it can show more clearly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for following up with a PR!
I have suggested some changes. Once you are done, could you also run go fmt
on the changed files? Let me know if you have any questions.
kafka/producer.go
Outdated
if msg == nil || len(*msg.TopicPartition.Topic) == 0 { | ||
return newErrorFromString(ErrInvalidArg, "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if msg == nil || len(*msg.TopicPartition.Topic) == 0 { | |
return newErrorFromString(ErrInvalidArg, "") | |
if msg == nil { | |
return newErrorFromString(ErrInvalidArg, "msg cannot be nil") |
kafka/producer.go
Outdated
}else if msg.TopicPartition.Topic == nil{ | ||
return newErrorFromString(ErrUnknownTopic, "topic is null, please check") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
}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") |
There was a problem hiding this comment.
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,
- msg.TopicPartition.Topic == nil must be made before len(*msg.TopicPartition.Topic) == 0 , else it causes a nil pointer dereference and will panic.
- 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)
add nil message detect add topic error detect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good, thanks! Just one more thing, we should run go fmt
on the changed files
@milindl please review again and it can be merged |
Hi @darrkz , please run the |
topic error was catch in ErrInvalidArg
but it can show more clearly