From d55d1179c21efab9ede84191c4ee9116ef160ede Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 12 Feb 2018 19:03:04 +0300 Subject: [PATCH] Add file and line to Status.ensure. GitOrigin-RevId: 3539caee7f92f6970fd5af673866dabeec177336 --- tdutils/td/utils/Status.h | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/tdutils/td/utils/Status.h b/tdutils/td/utils/Status.h index 404d505b..8bfaea97 100644 --- a/tdutils/td/utils/Status.h +++ b/tdutils/td/utils/Status.h @@ -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();