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

cleanup(pubsub): use client originated error in samples #14280

Merged
merged 3 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "google/cloud/credentials.h"
#include "google/cloud/internal/getenv.h"
#include "google/cloud/internal/random.h"
#include "google/cloud/internal/status_utils.h"
#include "google/cloud/opentelemetry_options.h"
#include "google/cloud/testing_util/integration_test.h"
#include "google/cloud/testing_util/status_matchers.h"
Expand Down
5 changes: 3 additions & 2 deletions google/cloud/pubsub/internal/subscriber_connection_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ StatusOr<pubsub::PullResponse> SubscriberConnectionImpl::Pull() {
std::this_thread::sleep_for(backoff_policy->OnCompletion());
}
if (last_status.ok()) {
return google::cloud::internal::UnavailableError("no messages returned",
GCP_ERROR_INFO());
return google::cloud::internal::UnavailableError(
"no messages returned",
GCP_ERROR_INFO().WithMetadata("gl-cpp.error.origin", "client"));
}
return google::cloud::internal::RetryLoopError(last_status, __func__,
retry_policy->IsExhausted());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ using ::testing::AtLeast;
using ::testing::AtMost;
using ::testing::Contains;
using ::testing::HasSubstr;
using ::testing::Pair;
using ::testing::Property;
using ::testing::StartsWith;

Expand Down Expand Up @@ -454,6 +455,8 @@ TEST(SubscriberConnectionTest, PullReturnsNoMessage) {
auto response = subscriber->Pull();
EXPECT_THAT(response, StatusIs(StatusCode::kUnavailable,
HasSubstr("no messages returned")));
EXPECT_THAT(response.status().error_info().metadata(),
Contains(Pair("gl-cpp.error.origin", "client")));

cq.Shutdown();
t.join();
Expand Down
7 changes: 4 additions & 3 deletions google/cloud/pubsub/samples/samples.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "google/cloud/pubsub/subscription_builder.h"
#include "google/cloud/internal/getenv.h"
#include "google/cloud/internal/random.h"
#include "google/cloud/internal/status_utils.h"
#include "google/cloud/project.h"
#include "google/cloud/status.h"
#include "google/cloud/testing_util/example_driver.h"
Expand Down Expand Up @@ -1052,9 +1053,9 @@ void OptimisticSubscribe(std::vector<std::string> const& argv) {
std::move(response->handler).ack();
return gc::Status();
}
if (response.status().code() == gc::StatusCode::kUnavailable &&
response.status().message() == "no messages returned") {
std::cout << "No messages returned from Pull()\n";
if (gc::internal::IsClientOrigin(response.status())) {
alevenberg marked this conversation as resolved.
Show resolved Hide resolved
std::cout << "Client originated error: " << response.status().message()
<< "\n";
return gc::Status();
}
return response.status();
Expand Down
Loading