Skip to content

Check ParseTopicName() return err#517

Open
EAHITechnology wants to merge 13 commits intoapache:masterfrom
EAHITechnology:master
Open

Check ParseTopicName() return err#517
EAHITechnology wants to merge 13 commits intoapache:masterfrom
EAHITechnology:master

Conversation

@EAHITechnology
Copy link
Copy Markdown

No description provided.

Comment thread pulsar/consumer_regex.go
matching := make([]string, 0)
for _, t := range topics {
tn, _ := internal.ParseTopicName(t)
tn, err := internal.ParseTopicName(t)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure if this good thing to error out here. The list of topic passed here usually comes from a response from the broker, right?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I'm not sure too.Although this is returned by the broker.

Comment thread pulsar/producer_impl.go Outdated
options.BatchingMaxPublishDelay = defaultBatchingMaxPublishDelay
}

ms, err := client.metrics.GetTopicMetrics(options.Topic)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This seems like a strange way of testing the topic. I don't think we should rely on calling a metrics function. Why not just call internal.ParseTopicName(topic). Same for the consumer_impl and tests.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The CreateProducer() passes an unchecked topic.And then use GetTopicMetrics() func (Use ParseTopicName func but uncheck err. When use as object transfer internal members ,you will get a runtime panic)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I resubmit here

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

If I verify the legitimacy on the outer layer. GetTopicMetrics() passes in *TopicName, is it reasonable? In the same way, the following operations do not need to verify the legitimacy

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

done!

Comment thread pulsar/test_helper.go
var metadata map[string]interface{}
err := httpGet("admin/v2/persistent/"+topicPath(topic)+"/stats", &metadata)
tp, err := topicPath(topic)
if err != nil {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure if this is needed since it's a test helper method. The test should fail without this check if a bad topic name is passed. Same for the topicPath function.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This is just a protective measure to prevent modification of test cases. It's just that I will do it. I'm not sure that others are the same

Copy link
Copy Markdown
Member

@wolfstudy wolfstudy left a comment

Choose a reason for hiding this comment

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

Thanks @EAHITechnology work for this, thc change lgtm +1, just a little comments, please check.

if err != nil {
t.Fatal(err)
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do we need to parse topic name here? In the GetTopicMetrics method, we have called the ParseTopicName method, is it enough to directly handle the error value returned by that method?

@wolfstudy wolfstudy added this to the 0.6.0 milestone Jun 2, 2021
@wolfstudy
Copy link
Copy Markdown
Member

@EAHITechnology Any update for this?

@freeznet
Copy link
Copy Markdown
Contributor

freeznet commented Jun 2, 2021

I think we already tested the topics with func validateTopicNames(topics ...string) ([]*internal.TopicName, error), so could you please fill this PR's content to help us understand the context and what issue is trying to solve? thanks.

@wolfstudy
Copy link
Copy Markdown
Member

I think we already tested the topics with func validateTopicNames(topics ...string) ([]*internal.TopicName, error), so could you please fill this PR's content to help us understand the context and what issue is trying to solve? thanks.

hello @freeznet In ParseTopicName, we threw an error, but during the call, we ignored the error. such as:

in filterTopics

tn, _ := internal.ParseTopicName(t)

in GetTopicMetrics:

tn, _ := ParseTopicName(t)

@wolfstudy wolfstudy modified the milestones: 0.6.0, 0.7.0 Jul 21, 2021
@wolfstudy wolfstudy modified the milestones: 0.7.0, v0.8.0 Nov 1, 2021
@wolfstudy wolfstudy modified the milestones: v0.8.0, 0.9.0 Feb 16, 2022
@freeznet freeznet modified the milestones: v0.9.0, v0.10.0 Jul 4, 2022
@RobertIndie RobertIndie removed this from the v0.10.0 milestone Mar 27, 2023
@RobertIndie RobertIndie added this to the v0.11.0 milestone Mar 27, 2023
@RobertIndie RobertIndie modified the milestones: v0.11.0, v0.12.0 Jul 4, 2023
@RobertIndie RobertIndie modified the milestones: v0.12.0, v0.13.0 Jan 10, 2024
@RobertIndie RobertIndie modified the milestones: v0.13.0, v0.14.0 Jul 15, 2024
@RobertIndie RobertIndie modified the milestones: v0.14.0, v0.15.0 Oct 8, 2024
@RobertIndie RobertIndie modified the milestones: v0.15.0, v0.16.0 May 15, 2025
@RobertIndie RobertIndie modified the milestones: v0.16.0, v0.17.0 Jul 29, 2025
@RobertIndie RobertIndie modified the milestones: v0.17.0, v0.18.0 Oct 23, 2025
@RobertIndie RobertIndie modified the milestones: v0.18.0, v0.19.0 Dec 1, 2025
@RobertIndie RobertIndie modified the milestones: v0.19.0, 0.20.0 Apr 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants