fix(bigtable): safely handle error states in metadata retrieval#16225
fix(bigtable): safely handle error states in metadata retrieval#16225colinmoy wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request contains unresolved git conflict markers in google/cloud/bigtable/internal/data_connection_impl.cc within the Metadata() method. The reviewer correctly identified this issue, which would cause compilation to fail, and provided a clear suggestion to resolve the conflict by keeping the absl::optional signature while incorporating the new safety check.
| <<<<<<< Updated upstream | ||
| absl::optional<google::bigtable::v2::ResultSetMetadata> Metadata() override { | ||
| if (!source_.has_value()) return absl::nullopt; | ||
| ======= | ||
| std::optional<google::bigtable::v2::ResultSetMetadata> Metadata() override { | ||
| if (!source_.has_value() || !source_->ok()) return std::nullopt; | ||
| >>>>>>> Stashed changes |
There was a problem hiding this comment.
Unresolved git conflict markers are present in the code. This will cause compilation to fail. Please resolve the conflict by keeping the absl::optional signature (as required by the base class override) while incorporating the safety check for !source_->ok().
absl::optional<google::bigtable::v2::ResultSetMetadata> Metadata() override {
if (!source_.has_value() || !source_->ok()) return absl::nullopt;References
- Prefer defensive code, such as explicit
ok()checks, even if they seem redundant based on the current implementation of a framework, as the framework's contract may change in the future.
eb58205 to
b6f1f5e
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #16225 +/- ##
==========================================
- Coverage 92.24% 92.24% -0.01%
==========================================
Files 2265 2265
Lines 210126 210126
==========================================
- Hits 193839 193829 -10
- Misses 16287 16297 +10 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Fixes a potential undefined behavior/crash where source_ (a nested std::optional<StatusOr<...>>) was being dereferenced without checking if the underlying StatusOr holds an error
fixes #16222