summaryrefslogtreecommitdiff
path: root/absl
diff options
context:
space:
mode:
authorGravatar Greg Falcon <gfalcon@google.com>2022-05-31 14:00:42 -0700
committerGravatar Copybara-Service <copybara-worker@google.com>2022-05-31 14:01:26 -0700
commita56715378721d8abd0ae379a83b9c1ee0b1a9a30 (patch)
tree9d4b2b9ab29508a45aacce8e65704d6124ec456b /absl
parentb957f0ccd00481cd4fd663d8320aa02ae0564f18 (diff)
Add an internal helper for logging (upcoming).
PiperOrigin-RevId: 452134803 Change-Id: I8660df850ab537c441399545b25eb32399b2a3ef
Diffstat (limited to 'absl')
-rw-r--r--absl/status/internal/status_internal.h9
-rw-r--r--absl/status/status.cc12
2 files changed, 21 insertions, 0 deletions
diff --git a/absl/status/internal/status_internal.h b/absl/status/internal/status_internal.h
index 34914d2e..fc1e78bc 100644
--- a/absl/status/internal/status_internal.h
+++ b/absl/status/internal/status_internal.h
@@ -69,6 +69,15 @@ struct StatusRep {
};
absl::StatusCode MapToLocalCode(int value);
+
+// If `status` is not OK, returns a pointer to a newly-allocated string with the
+// given `prefix`, suitable for output as an error message in assertion/CHECK()
+// failures. Otherwise returns nullptr.
+//
+// This is an internal implementation detail for Abseil logging.
+std::string* MakeCheckFailString(const absl::Status& status,
+ const char* prefix);
+
} // namespace status_internal
ABSL_NAMESPACE_END
diff --git a/absl/status/status.cc b/absl/status/status.cc
index fc5a1425..c66009d6 100644
--- a/absl/status/status.cc
+++ b/absl/status/status.cc
@@ -599,5 +599,17 @@ Status ErrnoToStatus(int error_number, absl::string_view message) {
MessageForErrnoToStatus(error_number, message));
}
+namespace status_internal {
+
+std::string* MakeCheckFailString(const absl::Status& status,
+ const char* prefix) {
+ if (status.ok()) { return nullptr; }
+ return new std::string(
+ absl::StrCat(prefix, " (",
+ status.ToString(StatusToStringMode::kWithEverything), ")"));
+}
+
+} // namespace status_internal
+
ABSL_NAMESPACE_END
} // namespace absl