Add file and line to Status.ensure.

GitOrigin-RevId: 3539caee7f92f6970fd5af673866dabeec177336
This commit is contained in:
levlam 2018-02-12 19:03:04 +03:00
parent ba83c2c5fc
commit d55d1179c2

View File

@ -42,6 +42,11 @@
} \
}
#ifndef TD_STATUS_NO_ENSURE
#define ensure() ensure_impl(__FILE__, __LINE__)
#define ensure_error() ensure_error_impl(__FILE__, __LINE__)
#endif
#if TD_PORT_POSIX
#define OS_ERROR(message) \
[&]() { \
@ -181,14 +186,14 @@ class Status {
return ptr_ != nullptr;
}
void ensure() const {
void ensure_impl(CSlice file_name, int line) const {
if (!is_ok()) {
LOG(FATAL) << "FAILED: " << to_string();
LOG(FATAL) << "Unexpexted Status " << to_string() << " in file " << file_name << " at line " << line;
}
}
void ensure_error() const {
void ensure_error_impl(CSlice file_name, int line) const {
if (is_ok()) {
LOG(FATAL) << "Expected Status::Error";
LOG(FATAL) << "Unexpected Status::OK in file " << file_name << " at line " << line;
}
}
@ -362,11 +367,11 @@ class Result {
}
}
void ensure() const {
status_.ensure();
void ensure_impl(CSlice file_name, int line) const {
status_.ensure_impl(file_name, line);
}
void ensure_error() const {
status_.ensure_error();
void ensure_error_impl(CSlice file_name, int line) const {
status_.ensure_error_impl(file_name, line);
}
void ignore() const {
status_.ignore();