Internal change

PiperOrigin-RevId: 489088227
This commit is contained in:
MediaPipe Team 2022-11-16 18:11:00 -08:00 committed by Copybara-Service
parent b6b72d5e4e
commit 90eb4a19d8
4 changed files with 20 additions and 90 deletions

View File

@ -97,39 +97,24 @@ absl::Status StatusBuilder::Impl::JoinMessageToStatus() {
}()); }());
} }
StatusBuilder::Impl::Impl(const absl::Status& status, const char* file,
int line)
: status(status), line(line), file(file), stream() {}
StatusBuilder::Impl::Impl(absl::Status&& status, const char* file, int line)
: status(std::move(status)), line(line), file(file), stream() {}
StatusBuilder::Impl::Impl(const absl::Status& status, StatusBuilder::Impl::Impl(const absl::Status& status,
mediapipe::source_location location) mediapipe::source_location location)
: status(status), : status(status), location(location), stream() {}
line(location.line()),
file(location.file_name()),
stream() {}
StatusBuilder::Impl::Impl(absl::Status&& status, StatusBuilder::Impl::Impl(absl::Status&& status,
mediapipe::source_location location) mediapipe::source_location location)
: status(std::move(status)), : status(std::move(status)), location(location), stream() {}
line(location.line()),
file(location.file_name()),
stream() {}
StatusBuilder::Impl::Impl(const Impl& other) StatusBuilder::Impl::Impl(const Impl& other)
: status(other.status), : status(other.status),
line(other.line), location(other.location),
file(other.file),
no_logging(other.no_logging), no_logging(other.no_logging),
stream(other.stream.str()), stream(other.stream.str()),
join_style(other.join_style) {} join_style(other.join_style) {}
StatusBuilder::Impl& StatusBuilder::Impl::operator=(const Impl& other) { StatusBuilder::Impl& StatusBuilder::Impl::operator=(const Impl& other) {
status = other.status; status = other.status;
line = other.line; location = other.location;
file = other.file;
no_logging = other.no_logging; no_logging = other.no_logging;
stream = std::ostringstream(other.stream.str()); stream = std::ostringstream(other.stream.str());
join_style = other.join_style; join_style = other.join_style;

View File

@ -60,17 +60,6 @@ class ABSL_MUST_USE_RESULT StatusBuilder {
? nullptr ? nullptr
: std::make_unique<Impl>(absl::Status(code, ""), location)) {} : std::make_unique<Impl>(absl::Status(code, ""), location)) {}
StatusBuilder(const absl::Status& original_status, const char* file, int line)
: impl_(original_status.ok()
? nullptr
: std::make_unique<Impl>(original_status, file, line)) {}
StatusBuilder(absl::Status&& original_status, const char* file, int line)
: impl_(original_status.ok()
? nullptr
: std::make_unique<Impl>(std::move(original_status), file,
line)) {}
bool ok() const { return !impl_; } bool ok() const { return !impl_; }
StatusBuilder& SetAppend() &; StatusBuilder& SetAppend() &;
@ -109,8 +98,6 @@ class ABSL_MUST_USE_RESULT StatusBuilder {
kPrepend, kPrepend,
}; };
Impl(const absl::Status& status, const char* file, int line);
Impl(absl::Status&& status, const char* file, int line);
Impl(const absl::Status& status, mediapipe::source_location location); Impl(const absl::Status& status, mediapipe::source_location location);
Impl(absl::Status&& status, mediapipe::source_location location); Impl(absl::Status&& status, mediapipe::source_location location);
Impl(const Impl&); Impl(const Impl&);
@ -120,10 +107,8 @@ class ABSL_MUST_USE_RESULT StatusBuilder {
// The status that the result will be based on. // The status that the result will be based on.
absl::Status status; absl::Status status;
// The line to record if this file is logged. // The source location to record if this file is logged.
int line; mediapipe::source_location location;
// Not-owned: The file to record if this status is logged.
const char* file;
// Logging disabled if true. // Logging disabled if true.
bool no_logging = false; bool no_logging = false;
// The additional messages added with `<<`. This is nullptr when status_ is // The additional messages added with `<<`. This is nullptr when status_ is

View File

@ -33,21 +33,6 @@ TEST(StatusBuilder, OkStatusRvalue) {
ASSERT_EQ(status, absl::OkStatus()); ASSERT_EQ(status, absl::OkStatus());
} }
TEST(StatusBuilder, OkStatusFileAndLineRvalueStatus) {
absl::Status status = StatusBuilder(absl::OkStatus(), "hello.cc", 1234)
<< "annotated message1 "
<< "annotated message2";
ASSERT_EQ(status, absl::OkStatus());
}
TEST(StatusBuilder, OkStatusFileAndLineLvalueStatus) {
const auto original_status = absl::OkStatus();
absl::Status status = StatusBuilder(original_status, "hello.cc", 1234)
<< "annotated message1 "
<< "annotated message2";
ASSERT_EQ(status, absl::OkStatus());
}
TEST(StatusBuilder, AnnotateMode) { TEST(StatusBuilder, AnnotateMode) {
absl::Status status = StatusBuilder(absl::Status(absl::StatusCode::kNotFound, absl::Status status = StatusBuilder(absl::Status(absl::StatusCode::kNotFound,
"original message"), "original message"),
@ -60,30 +45,6 @@ TEST(StatusBuilder, AnnotateMode) {
"original message; annotated message1 annotated message2"); "original message; annotated message1 annotated message2");
} }
TEST(StatusBuilder, AnnotateModeFileAndLineRvalueStatus) {
absl::Status status = StatusBuilder(absl::Status(absl::StatusCode::kNotFound,
"original message"),
"hello.cc", 1234)
<< "annotated message1 "
<< "annotated message2";
ASSERT_FALSE(status.ok());
EXPECT_EQ(status.code(), absl::StatusCode::kNotFound);
EXPECT_EQ(status.message(),
"original message; annotated message1 annotated message2");
}
TEST(StatusBuilder, AnnotateModeFileAndLineLvalueStatus) {
const auto original_status =
absl::Status(absl::StatusCode::kNotFound, "original message");
absl::Status status = StatusBuilder(original_status, "hello.cc", 1234)
<< "annotated message1 "
<< "annotated message2";
ASSERT_FALSE(status.ok());
EXPECT_EQ(status.code(), absl::StatusCode::kNotFound);
EXPECT_EQ(status.message(),
"original message; annotated message1 annotated message2");
}
TEST(StatusBuilder, PrependModeLvalue) { TEST(StatusBuilder, PrependModeLvalue) {
StatusBuilder builder( StatusBuilder builder(
absl::Status(absl::StatusCode::kInvalidArgument, "original message"), absl::Status(absl::StatusCode::kInvalidArgument, "original message"),

View File

@ -84,7 +84,7 @@
#define MP_RETURN_IF_ERROR(expr) \ #define MP_RETURN_IF_ERROR(expr) \
STATUS_MACROS_IMPL_ELSE_BLOCKER_ \ STATUS_MACROS_IMPL_ELSE_BLOCKER_ \
if (mediapipe::status_macro_internal::StatusAdaptorForMacros \ if (mediapipe::status_macro_internal::StatusAdaptorForMacros \
status_macro_internal_adaptor = {(expr), __FILE__, __LINE__}) { \ status_macro_internal_adaptor = {(expr), MEDIAPIPE_LOC}) { \
} else /* NOLINT */ \ } else /* NOLINT */ \
return status_macro_internal_adaptor.Consume() return status_macro_internal_adaptor.Consume()
@ -156,14 +156,14 @@
return mediapipe::StatusBuilder( \ return mediapipe::StatusBuilder( \
std::move(STATUS_MACROS_IMPL_CONCAT_(_status_or_value, __LINE__)) \ std::move(STATUS_MACROS_IMPL_CONCAT_(_status_or_value, __LINE__)) \
.status(), \ .status(), \
__FILE__, __LINE__)) MEDIAPIPE_LOC))
#define STATUS_MACROS_IMPL_ASSIGN_OR_RETURN_3_(lhs, rexpr, error_expression) \ #define STATUS_MACROS_IMPL_ASSIGN_OR_RETURN_3_(lhs, rexpr, error_expression) \
STATUS_MACROS_IMPL_ASSIGN_OR_RETURN_( \ STATUS_MACROS_IMPL_ASSIGN_OR_RETURN_( \
STATUS_MACROS_IMPL_CONCAT_(_status_or_value, __LINE__), lhs, rexpr, \ STATUS_MACROS_IMPL_CONCAT_(_status_or_value, __LINE__), lhs, rexpr, \
mediapipe::StatusBuilder _( \ mediapipe::StatusBuilder _( \
std::move(STATUS_MACROS_IMPL_CONCAT_(_status_or_value, __LINE__)) \ std::move(STATUS_MACROS_IMPL_CONCAT_(_status_or_value, __LINE__)) \
.status(), \ .status(), \
__FILE__, __LINE__); \ MEDIAPIPE_LOC); \
(void)_; /* error_expression is allowed to not use this variable */ \ (void)_; /* error_expression is allowed to not use this variable */ \
return (error_expression)) return (error_expression))
#define STATUS_MACROS_IMPL_ASSIGN_OR_RETURN_(statusor, lhs, rexpr, \ #define STATUS_MACROS_IMPL_ASSIGN_OR_RETURN_(statusor, lhs, rexpr, \
@ -201,18 +201,17 @@ namespace status_macro_internal {
// that declares a variable. // that declares a variable.
class StatusAdaptorForMacros { class StatusAdaptorForMacros {
public: public:
StatusAdaptorForMacros(const absl::Status& status, const char* file, int line) StatusAdaptorForMacros(const absl::Status& status, source_location location)
: builder_(status, file, line) {} : builder_(status, location) {}
StatusAdaptorForMacros(absl::Status&& status, const char* file, int line) StatusAdaptorForMacros(absl::Status&& status, source_location location)
: builder_(std::move(status), file, line) {} : builder_(std::move(status), location) {}
StatusAdaptorForMacros(const StatusBuilder& builder, const char* /* file */, StatusAdaptorForMacros(const StatusBuilder& builder,
int /* line */) source_location /*location*/)
: builder_(builder) {} : builder_(builder) {}
StatusAdaptorForMacros(StatusBuilder&& builder, const char* /* file */, StatusAdaptorForMacros(StatusBuilder&& builder, source_location /*location*/)
int /* line */)
: builder_(std::move(builder)) {} : builder_(std::move(builder)) {}
StatusAdaptorForMacros(const StatusAdaptorForMacros&) = delete; StatusAdaptorForMacros(const StatusAdaptorForMacros&) = delete;