Skip to content

Commit 7c0c6dc

Browse files
authored
impl: add client origin metadata for a failed async unary rpc (#14088)
* impl(internal): change the error message for a failed async unary rpc * address comments * update comment * address comment
1 parent 3cca8b6 commit 7c0c6dc

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

google/cloud/completion_queue_test.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ namespace {
4343

4444
using ::google::cloud::testing_util::FakeCompletionQueueImpl;
4545
using ::google::cloud::testing_util::IsOk;
46+
using ::google::cloud::testing_util::StatusIs;
4647
using ::testing::Contains;
4748
using ::testing::HasSubstr;
4849
using ::testing::Not;
@@ -405,7 +406,11 @@ TEST(CompletionQueueTest, MakeRpcsAfterShutdown) {
405406
},
406407
r1, std::make_unique<grpc::ClientContext>())
407408
.then([](future<StatusOr<Response>> f) {
408-
EXPECT_EQ(StatusCode::kCancelled, f.get().status().code());
409+
auto status = f.get().status();
410+
EXPECT_THAT(status, StatusIs(StatusCode::kCancelled));
411+
auto const& metadata = status.error_info().metadata();
412+
EXPECT_THAT(metadata,
413+
Contains(Pair("gl-cpp.error.origin", "client")));
409414
});
410415

411416
Request r2;

google/cloud/internal/async_rpc_details.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "google/cloud/future.h"
2020
#include "google/cloud/grpc_error_delegate.h"
2121
#include "google/cloud/internal/call_context.h"
22+
#include "google/cloud/internal/make_status.h"
2223
#include "google/cloud/status_or.h"
2324
#include "google/cloud/version.h"
2425
#include "absl/functional/function_ref.h"
@@ -72,8 +73,11 @@ class AsyncUnaryRpcFuture : public AsyncGrpcOperation {
7273
ScopedCallContext scope(call_context_);
7374
if (!ok) {
7475
// `Finish()` always returns `true` for unary RPCs, so the only time we
75-
// get `!ok` is after `Shutdown()` was called; treat that as "cancelled".
76-
promise_.set_value(Status(StatusCode::kCancelled, "call cancelled"));
76+
// get `!ok` is after `Shutdown()` was called; create a "cancelled"
77+
// originating from the client.
78+
promise_.set_value(internal::CancelledError(
79+
"call cancelled",
80+
GCP_ERROR_INFO().WithMetadata("gl-cpp.error.origin", "client")));
7781
return true;
7882
}
7983
if (!status_.ok()) {

0 commit comments

Comments
 (0)