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

[C++] Fix Result can't be serialized to string inside the library #7034

Merged
merged 1 commit into from
May 27, 2020

Conversation

BewareMyPower
Copy link
Contributor

Motivation

When a Result was passed to std::ostream::operator<< inside the library, the overloaded operator<< wouldn't be called. Instead Result was treated as a integer. For example, if you subscribed to a topic of a namespace that didn't exist, the error log would be:

ERROR ClientImpl:384 | Error Checking/Getting Partition Metadata while Subscribing on persistent://mytenant/myns/mytopic -- 5

Giving following code:

namespace pulsar {
    void foo() {
        std::stringstream ss;
        Result result = ResultOk;
        ss << result;  // "0"
    }
}

void foo() {
    std::stringstream ss;
    Result result = ResultOk;
    ss << result;  // "Ok"
}

ss << result inside namespace pulsar doesn't call ::operator(ss, result). Instead, it calls pulsar::operator(ss, result), which hasn't been overloaded. Because nearly all methods are in namespace pulsar, the LOG_XXX(... << result) won't call ::operator<<(std::ostream&, Result).

Modifications

  • Change the overloaded operator<< for Result from global namespace to namespace pulsar.

@BewareMyPower
Copy link
Contributor Author

/pulsarbot run-failure-checks

2 similar comments
@BewareMyPower
Copy link
Contributor Author

/pulsarbot run-failure-checks

@BewareMyPower
Copy link
Contributor Author

/pulsarbot run-failure-checks

@BewareMyPower
Copy link
Contributor Author

/pulsarbot run-failure-checks

1 similar comment
@BewareMyPower
Copy link
Contributor Author

/pulsarbot run-failure-checks

@merlimat merlimat merged commit a50b75a into apache:master May 27, 2020
@BewareMyPower BewareMyPower deleted the print-result-dev branch May 29, 2020 02:29
315157973 pushed a commit to 315157973/pulsar that referenced this pull request May 29, 2020
Huanli-Meng pushed a commit to Huanli-Meng/pulsar that referenced this pull request Jun 1, 2020
Huanli-Meng pushed a commit to Huanli-Meng/pulsar that referenced this pull request Jun 1, 2020
Huanli-Meng pushed a commit to Huanli-Meng/pulsar that referenced this pull request Jun 12, 2020
huangdx0726 pushed a commit to huangdx0726/pulsar that referenced this pull request Aug 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants