This is an automated email from the ASF dual-hosted git repository.
dataroaring pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new bfca1bf2069 [Enhancement] Implement format methods for Status (#26133)
bfca1bf2069 is described below
commit bfca1bf206978adf9261c6eee4c423a0b8fc33e7
Author: Liu Zhenlong <[email protected]>
AuthorDate: Wed Nov 1 16:55:25 2023 +0800
[Enhancement] Implement format methods for Status (#26133)
---
be/src/common/status.h | 14 ++++++++++++++
be/test/common/status_test.cpp | 10 ++++++++++
2 files changed, 24 insertions(+)
diff --git a/be/src/common/status.h b/be/src/common/status.h
index 7ca1aacca04..512afa88fec 100644
--- a/be/src/common/status.h
+++ b/be/src/common/status.h
@@ -612,3 +612,17 @@ using ResultError = unexpected<Status>;
// clang-format on
} // namespace doris
+
+// specify formatter for Status
+template <>
+struct fmt::formatter<doris::Status> {
+ template <typename ParseContext>
+ constexpr auto parse(ParseContext& ctx) {
+ return ctx.begin();
+ }
+
+ template <typename FormatContext>
+ auto format(doris::Status const& status, FormatContext& ctx) {
+ return fmt::format_to(ctx.out(), "{}", status.to_string());
+ }
+};
diff --git a/be/test/common/status_test.cpp b/be/test/common/status_test.cpp
index 8f0cdd064a5..0371346e3cd 100644
--- a/be/test/common/status_test.cpp
+++ b/be/test/common/status_test.cpp
@@ -73,4 +73,14 @@ TEST_F(StatusTest, Error) {
}
}
+TEST_F(StatusTest /*unused*/, Format /*unused*/) {
+ // status == ok
+ Status st_ok = Status::OK();
+ EXPECT_TRUE(fmt::format("{}", st_ok).compare(fmt::format("{}",
st_ok.to_string())) == 0);
+
+ // status == error
+ Status st_error = Status::InternalError("123");
+ EXPECT_TRUE(fmt::format("{}", st_error).compare(fmt::format("{}",
st_error.to_string())) == 0);
+}
+
} // namespace doris
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]