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 6 commits into
base: master
Choose a base branch
from

Conversation

darrkz
Copy link

@darrkz darrkz commented Apr 1, 2024

topic error was catch in ErrInvalidArg
but it can show more clearly

topic error was catch in  ErrInvalidArg
but it can show more clearly
Copy link

cla-assistant bot commented Apr 1, 2024

CLA assistant check
All committers have signed the CLA.

@darrkz darrkz mentioned this pull request Apr 1, 2024
7 tasks
@darrkz
Copy link
Author

darrkz commented Apr 2, 2024

@milindl please review , thanks...

issue link
#1160

Copy link
Contributor

@milindl milindl left a 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.

Comment on lines 176 to 177
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")

Comment on lines 178 to 179
}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)

add nil message detect
add topic error detect
Copy link
Contributor

@milindl milindl left a 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

@darrkz darrkz requested a review from milindl April 19, 2024 01:11
@darrkz
Copy link
Author

darrkz commented Apr 24, 2024

@milindl please review again and it can be merged

@milindl
Copy link
Contributor

milindl commented Apr 25, 2024

Hi @darrkz , please run the go fmt command on the codebase to fix the format issues automatically. I can run the CI and merge it after that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants