|
@@ -119,6 +119,21 @@ struct DetailedPermissionDenied : Client::PermissionDenied, DetailCarrier {
|
|
|
: Client::PermissionDenied(m), DetailCarrier(std::move(d)) {}
|
|
: Client::PermissionDenied(m), DetailCarrier(std::move(d)) {}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+// v2.12.4 - THE RULE FOR READS: a read whose "nothing there" value (nullopt,
|
|
|
|
|
+// false, 0, an empty list, a default config) is also a valid answer must THROW
|
|
|
|
|
+// on a failed status, never return that value. Returning it made a transport
|
|
|
|
|
+// blip (UNAVAILABLE, DEADLINE_EXCEEDED) indistinguishable from absence, so a
|
|
|
|
|
+// consumer reported a definite 404 for a collection that existed and lost a
|
|
|
|
|
+// six-minute ingest to it. v2.4.2 (find on a missing collection) and v2.8.0
|
|
|
|
|
+// (permission denials) applied this rule one status code at a time; it now
|
|
|
|
|
+// applies to every code. Absence is always reported IN-BAND by the server
|
|
|
|
|
+// (found=false, exists=false, an empty list); only Find uses a NOT_FOUND
|
|
|
|
|
+// status, and that already threw. Exempt, deliberately: healthCheck /
|
|
|
|
|
+// getHealthInfo / getStats (their job is to answer "unreachable"),
|
|
|
|
|
+// getRelationsEnforced (fails toward enforced) and tryGetRelationsEnforced
|
|
|
|
|
+// (declines to answer). Writes keep returning false/0 - false already means
|
|
|
|
|
+// "did not happen", and they have Failure& overloads carrying the code.
|
|
|
|
|
+//
|
|
|
// Throw the Client::Error subtype matching a failed status. `message` becomes
|
|
// Throw the Client::Error subtype matching a failed status. `message` becomes
|
|
|
// what(): every site passes what it threw before 2.11.4, so the text an
|
|
// what(): every site passes what it threw before 2.11.4, so the text an
|
|
|
// existing consumer logs or matches on is unchanged. v2.12.0: the thrown
|
|
// existing consumer logs or matches on is unchanged. v2.12.0: the thrown
|
|
@@ -444,7 +459,7 @@ public:
|
|
|
throw Client::PermissionDenied("access denied: get");
|
|
throw Client::PermissionDenied("access denied: get");
|
|
|
}
|
|
}
|
|
|
spdlog::error("Client::get failed: {}", status.error_message());
|
|
spdlog::error("Client::get failed: {}", status.error_message());
|
|
|
- return std::nullopt;
|
|
|
|
|
|
|
+ throwStatus(status, status.error_message()); // v2.12.4: never empty on failure
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (!response.found()) {
|
|
if (!response.found()) {
|
|
@@ -478,8 +493,21 @@ public:
|
|
|
// 2. Call updateIfVersion
|
|
// 2. Call updateIfVersion
|
|
|
// 3. On version conflict (another writer), re-read and retry
|
|
// 3. On version conflict (another writer), re-read and retry
|
|
|
for (uint32_t attempt = 0; attempt <= config_.maxRetries; ++attempt) {
|
|
for (uint32_t attempt = 0; attempt <= config_.maxRetries; ++attempt) {
|
|
|
- // Get current version
|
|
|
|
|
- auto current = get(collection, id);
|
|
|
|
|
|
|
+ // Get current version. v2.12.4: get() now throws on a failed read
|
|
|
|
|
+ // instead of returning nullopt. Before, an unreachable database
|
|
|
|
|
+ // was reported here as "document not found" - the same conflation
|
|
|
|
|
+ // get() had. update() still reports failure by returning false,
|
|
|
|
|
+ // so the real code is recorded instead. A permission denial threw
|
|
|
|
|
+ // out of here before 2.12.4 too, and still does.
|
|
|
|
|
+ std::optional<nlohmann::json> current;
|
|
|
|
|
+ try {
|
|
|
|
|
+ current = get(collection, id);
|
|
|
|
|
+ } catch (const Client::PermissionDenied&) {
|
|
|
|
|
+ throw;
|
|
|
|
|
+ } catch (const Client::Error& e) {
|
|
|
|
|
+ failureOut.record(e.code(), e.what());
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
if (!current) {
|
|
if (!current) {
|
|
|
// The one failure here the client can name itself, without
|
|
// The one failure here the client can name itself, without
|
|
|
// reading a server message: get() just said there is no
|
|
// reading a server message: get() just said there is no
|
|
@@ -801,7 +829,7 @@ public:
|
|
|
throw Client::PermissionDenied("access denied: exists");
|
|
throw Client::PermissionDenied("access denied: exists");
|
|
|
}
|
|
}
|
|
|
spdlog::error("Client::exists failed: {}", status.error_message());
|
|
spdlog::error("Client::exists failed: {}", status.error_message());
|
|
|
- return false;
|
|
|
|
|
|
|
+ throwStatus(status, status.error_message()); // v2.12.4: never empty on failure
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return response.exists();
|
|
return response.exists();
|
|
@@ -849,8 +877,8 @@ public:
|
|
|
if (status.error_code() == grpc::StatusCode::NOT_FOUND) {
|
|
if (status.error_code() == grpc::StatusCode::NOT_FOUND) {
|
|
|
// Surfaced rather than logged: an unknown collection or view is a
|
|
// Surfaced rather than logged: an unknown collection or view is a
|
|
|
// caller bug, and returning {} here is indistinguishable from a
|
|
// caller bug, and returning {} here is indistinguishable from a
|
|
|
- // legitimately empty result. Other failures keep the old
|
|
|
|
|
- // log-and-return-empty behaviour.
|
|
|
|
|
|
|
+ // legitimately empty result. Since v2.12.4 every other failure
|
|
|
|
|
+ // throws too (below).
|
|
|
throwStatus(status, status.error_message());
|
|
throwStatus(status, status.error_message());
|
|
|
}
|
|
}
|
|
|
if (!status.ok()) {
|
|
if (!status.ok()) {
|
|
@@ -864,7 +892,7 @@ public:
|
|
|
throw Client::PermissionDenied("access denied: find");
|
|
throw Client::PermissionDenied("access denied: find");
|
|
|
}
|
|
}
|
|
|
spdlog::error("Client::find failed: {}", status.error_message());
|
|
spdlog::error("Client::find failed: {}", status.error_message());
|
|
|
- return {};
|
|
|
|
|
|
|
+ throwStatus(status, status.error_message()); // v2.12.4: never empty on failure
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
std::vector<nlohmann::json> results;
|
|
std::vector<nlohmann::json> results;
|
|
@@ -934,7 +962,7 @@ public:
|
|
|
throw Client::PermissionDenied("access denied: findWithMetrics");
|
|
throw Client::PermissionDenied("access denied: findWithMetrics");
|
|
|
}
|
|
}
|
|
|
spdlog::error("Client::findWithMetrics failed: {}", status.error_message());
|
|
spdlog::error("Client::findWithMetrics failed: {}", status.error_message());
|
|
|
- return {};
|
|
|
|
|
|
|
+ throwStatus(status, status.error_message()); // v2.12.4: never empty on failure
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
Client::FindResult result;
|
|
Client::FindResult result;
|
|
@@ -989,7 +1017,7 @@ public:
|
|
|
throw Client::PermissionDenied("access denied: count");
|
|
throw Client::PermissionDenied("access denied: count");
|
|
|
}
|
|
}
|
|
|
spdlog::error("Client::count failed: {}", status.error_message());
|
|
spdlog::error("Client::count failed: {}", status.error_message());
|
|
|
- return 0;
|
|
|
|
|
|
|
+ throwStatus(status, status.error_message()); // v2.12.4: never empty on failure
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return response.count();
|
|
return response.count();
|
|
@@ -1047,7 +1075,7 @@ public:
|
|
|
auto status = stub_->SetMembers(&context, request, &response);
|
|
auto status = stub_->SetMembers(&context, request, &response);
|
|
|
if (!status.ok()) {
|
|
if (!status.ok()) {
|
|
|
spdlog::error("Client::setMembers failed: {}", status.error_message());
|
|
spdlog::error("Client::setMembers failed: {}", status.error_message());
|
|
|
- return {};
|
|
|
|
|
|
|
+ throwStatus(status, status.error_message()); // v2.12.4: never empty on failure
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return {response.members().begin(), response.members().end()};
|
|
return {response.members().begin(), response.members().end()};
|
|
@@ -1066,7 +1094,7 @@ public:
|
|
|
auto status = stub_->SetIsMember(&context, request, &response);
|
|
auto status = stub_->SetIsMember(&context, request, &response);
|
|
|
if (!status.ok()) {
|
|
if (!status.ok()) {
|
|
|
spdlog::error("Client::setIsMember failed: {}", status.error_message());
|
|
spdlog::error("Client::setIsMember failed: {}", status.error_message());
|
|
|
- return false;
|
|
|
|
|
|
|
+ throwStatus(status, status.error_message()); // v2.12.4: never empty on failure
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return response.is_member();
|
|
return response.is_member();
|
|
@@ -1180,7 +1208,7 @@ public:
|
|
|
auto status = stub_->ListCollections(&context, request, &response);
|
|
auto status = stub_->ListCollections(&context, request, &response);
|
|
|
if (!status.ok()) {
|
|
if (!status.ok()) {
|
|
|
spdlog::error("Client::listCollections failed: {}", status.error_message());
|
|
spdlog::error("Client::listCollections failed: {}", status.error_message());
|
|
|
- return {};
|
|
|
|
|
|
|
+ throwStatus(status, status.error_message()); // v2.12.4: never empty on failure
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// v2.4.5 — round-trip the naming: callers pass bare names in, so they
|
|
// v2.4.5 — round-trip the naming: callers pass bare names in, so they
|
|
@@ -1210,7 +1238,7 @@ public:
|
|
|
auto status = stub_->GetCollectionInfo(&context, request, &response);
|
|
auto status = stub_->GetCollectionInfo(&context, request, &response);
|
|
|
if (!status.ok()) {
|
|
if (!status.ok()) {
|
|
|
spdlog::error("Client::getCollectionInfo failed: {}", status.error_message());
|
|
spdlog::error("Client::getCollectionInfo failed: {}", status.error_message());
|
|
|
- return std::nullopt;
|
|
|
|
|
|
|
+ throwStatus(status, status.error_message()); // v2.12.4: never empty on failure
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (!response.found()) {
|
|
if (!response.found()) {
|
|
@@ -1241,7 +1269,7 @@ public:
|
|
|
auto status = stub_->ListProjects(&context, request, &response);
|
|
auto status = stub_->ListProjects(&context, request, &response);
|
|
|
if (!status.ok()) {
|
|
if (!status.ok()) {
|
|
|
spdlog::error("Client::listProjects failed: {}", status.error_message());
|
|
spdlog::error("Client::listProjects failed: {}", status.error_message());
|
|
|
- return {};
|
|
|
|
|
|
|
+ throwStatus(status, status.error_message()); // v2.12.4: never empty on failure
|
|
|
}
|
|
}
|
|
|
return {response.projects().begin(), response.projects().end()};
|
|
return {response.projects().begin(), response.projects().end()};
|
|
|
}
|
|
}
|
|
@@ -1329,7 +1357,7 @@ public:
|
|
|
auto status = stub_->GetCollectionConfig(&context, request, &response);
|
|
auto status = stub_->GetCollectionConfig(&context, request, &response);
|
|
|
if (!status.ok()) {
|
|
if (!status.ok()) {
|
|
|
spdlog::error("Client::getCollectionConfig failed: {}", status.error_message());
|
|
spdlog::error("Client::getCollectionConfig failed: {}", status.error_message());
|
|
|
- return out;
|
|
|
|
|
|
|
+ throwStatus(status, status.error_message()); // v2.12.4: never empty on failure
|
|
|
}
|
|
}
|
|
|
out.timestampPrecision = response.config().timestamp_precision();
|
|
out.timestampPrecision = response.config().timestamp_precision();
|
|
|
if (out.timestampPrecision.empty()) out.timestampPrecision = "ms";
|
|
if (out.timestampPrecision.empty()) out.timestampPrecision = "ms";
|
|
@@ -1352,7 +1380,10 @@ public:
|
|
|
setDeadline(context);
|
|
setDeadline(context);
|
|
|
|
|
|
|
|
auto status = stub_->GetCollectionConfig(&context, request, &response);
|
|
auto status = stub_->GetCollectionConfig(&context, request, &response);
|
|
|
- if (!status.ok()) return false;
|
|
|
|
|
|
|
+ if (!status.ok()) {
|
|
|
|
|
+ spdlog::error("Client::hasCollectionConfig failed: {}", status.error_message());
|
|
|
|
|
+ throwStatus(status, status.error_message()); // v2.12.4: never empty on failure
|
|
|
|
|
+ }
|
|
|
return response.found();
|
|
return response.found();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1605,7 +1636,7 @@ public:
|
|
|
auto status = stub_->ListIndexes(&context, request, &response);
|
|
auto status = stub_->ListIndexes(&context, request, &response);
|
|
|
if (!status.ok()) {
|
|
if (!status.ok()) {
|
|
|
spdlog::error("Client::listIndexes failed: {}", status.error_message());
|
|
spdlog::error("Client::listIndexes failed: {}", status.error_message());
|
|
|
- return out;
|
|
|
|
|
|
|
+ throwStatus(status, status.error_message()); // v2.12.4: never empty on failure
|
|
|
}
|
|
}
|
|
|
out.reserve(response.indexes_size());
|
|
out.reserve(response.indexes_size());
|
|
|
if (uniqueFlags != nullptr) {
|
|
if (uniqueFlags != nullptr) {
|
|
@@ -1687,7 +1718,7 @@ public:
|
|
|
auto status = stub_->ListIndexes(&context, request, &response);
|
|
auto status = stub_->ListIndexes(&context, request, &response);
|
|
|
if (!status.ok()) {
|
|
if (!status.ok()) {
|
|
|
spdlog::error("Client::listCompositeUniqueIndexes failed: {}", status.error_message());
|
|
spdlog::error("Client::listCompositeUniqueIndexes failed: {}", status.error_message());
|
|
|
- return out;
|
|
|
|
|
|
|
+ throwStatus(status, status.error_message()); // v2.12.4: never empty on failure
|
|
|
}
|
|
}
|
|
|
for (const auto& i : response.indexes()) {
|
|
for (const auto& i : response.indexes()) {
|
|
|
if (i.fields_size() > 0) out.emplace_back(i.fields().begin(), i.fields().end());
|
|
if (i.fields_size() > 0) out.emplace_back(i.fields().begin(), i.fields().end());
|
|
@@ -1711,7 +1742,7 @@ public:
|
|
|
auto status = stub_->GetIndexValues(&context, request, &response);
|
|
auto status = stub_->GetIndexValues(&context, request, &response);
|
|
|
if (!status.ok()) {
|
|
if (!status.ok()) {
|
|
|
spdlog::error("Client::indexValues failed: {}", status.error_message());
|
|
spdlog::error("Client::indexValues failed: {}", status.error_message());
|
|
|
- return out;
|
|
|
|
|
|
|
+ throwStatus(status, status.error_message()); // v2.12.4: never empty on failure
|
|
|
}
|
|
}
|
|
|
out.reserve(response.values_size());
|
|
out.reserve(response.values_size());
|
|
|
for (const auto& v : response.values()) {
|
|
for (const auto& v : response.values()) {
|
|
@@ -1754,7 +1785,7 @@ public:
|
|
|
auto status = stub_->ListViews(&context, request, &response);
|
|
auto status = stub_->ListViews(&context, request, &response);
|
|
|
if (!status.ok()) {
|
|
if (!status.ok()) {
|
|
|
spdlog::error("Client::listViews failed: {}", status.error_message());
|
|
spdlog::error("Client::listViews failed: {}", status.error_message());
|
|
|
- return out;
|
|
|
|
|
|
|
+ throwStatus(status, status.error_message()); // v2.12.4: never empty on failure
|
|
|
}
|
|
}
|
|
|
for (const auto& pb : response.views()) {
|
|
for (const auto& pb : response.views()) {
|
|
|
Client::ViewDefinition v;
|
|
Client::ViewDefinition v;
|
|
@@ -1792,7 +1823,11 @@ public:
|
|
|
setDeadline(context);
|
|
setDeadline(context);
|
|
|
|
|
|
|
|
auto status = stub_->GetViewInfo(&context, request, &response);
|
|
auto status = stub_->GetViewInfo(&context, request, &response);
|
|
|
- if (!status.ok() || !response.found()) {
|
|
|
|
|
|
|
+ if (!status.ok()) {
|
|
|
|
|
+ spdlog::error("Client::getViewInfo failed: {}", status.error_message());
|
|
|
|
|
+ throwStatus(status, status.error_message()); // v2.12.4: never empty on failure
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!response.found()) {
|
|
|
return std::nullopt;
|
|
return std::nullopt;
|
|
|
}
|
|
}
|
|
|
Client::ViewDefinition v;
|
|
Client::ViewDefinition v;
|
|
@@ -1909,7 +1944,7 @@ public:
|
|
|
auto status = stub_->ListRelations(&context, request, &response);
|
|
auto status = stub_->ListRelations(&context, request, &response);
|
|
|
if (!status.ok()) {
|
|
if (!status.ok()) {
|
|
|
spdlog::error("Client::listRelations failed: {}", status.error_message());
|
|
spdlog::error("Client::listRelations failed: {}", status.error_message());
|
|
|
- return out;
|
|
|
|
|
|
|
+ throwStatus(status, status.error_message()); // v2.12.4: never empty on failure
|
|
|
}
|
|
}
|
|
|
out.reserve(response.relations_size());
|
|
out.reserve(response.relations_size());
|
|
|
for (const auto& pb : response.relations()) {
|
|
for (const auto& pb : response.relations()) {
|
|
@@ -1926,7 +1961,11 @@ public:
|
|
|
setDeadline(context);
|
|
setDeadline(context);
|
|
|
|
|
|
|
|
auto status = stub_->GetRelationInfo(&context, request, &response);
|
|
auto status = stub_->GetRelationInfo(&context, request, &response);
|
|
|
- if (!status.ok() || !response.found()) {
|
|
|
|
|
|
|
+ if (!status.ok()) {
|
|
|
|
|
+ spdlog::error("Client::getRelationInfo failed: {}", status.error_message());
|
|
|
|
|
+ throwStatus(status, status.error_message()); // v2.12.4: never empty on failure
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!response.found()) {
|
|
|
return std::nullopt;
|
|
return std::nullopt;
|
|
|
}
|
|
}
|
|
|
return relationFromProto(response.relation());
|
|
return relationFromProto(response.relation());
|
|
@@ -2135,7 +2174,7 @@ public:
|
|
|
auto status = stub_->GetVersionHistory(&context, request, &response);
|
|
auto status = stub_->GetVersionHistory(&context, request, &response);
|
|
|
if (!status.ok()) {
|
|
if (!status.ok()) {
|
|
|
spdlog::error("Client::getVersionHistory failed: {}", status.error_message());
|
|
spdlog::error("Client::getVersionHistory failed: {}", status.error_message());
|
|
|
- return {};
|
|
|
|
|
|
|
+ throwStatus(status, status.error_message()); // v2.12.4: never empty on failure
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
Client::VersionHistoryResult result;
|
|
Client::VersionHistoryResult result;
|
|
@@ -2172,7 +2211,7 @@ public:
|
|
|
auto status = stub_->GetDocumentVersion(&context, request, &response);
|
|
auto status = stub_->GetDocumentVersion(&context, request, &response);
|
|
|
if (!status.ok()) {
|
|
if (!status.ok()) {
|
|
|
spdlog::error("Client::getDocumentVersion failed: {}", status.error_message());
|
|
spdlog::error("Client::getDocumentVersion failed: {}", status.error_message());
|
|
|
- return std::nullopt;
|
|
|
|
|
|
|
+ throwStatus(status, status.error_message()); // v2.12.4: never empty on failure
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (!response.found()) {
|
|
if (!response.found()) {
|