Introduced a CHECK_NOTERROR macro.

Review: https://reviews.apache.org/r/65514


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/05cf02c7
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/05cf02c7
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/05cf02c7

Branch: refs/heads/master
Commit: 05cf02c7472184f7e102b704c0609f0047685bd8
Parents: 874dc2c
Author: Benjamin Mahler <bmah...@apache.org>
Authored: Mon Feb 5 13:32:37 2018 -0800
Committer: Benjamin Mahler <bmah...@apache.org>
Committed: Fri Feb 23 15:01:57 2018 -0800

----------------------------------------------------------------------
 3rdparty/stout/include/stout/check.hpp | 79 ++++++++++++++++++++++++++---
 1 file changed, 73 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/05cf02c7/3rdparty/stout/include/stout/check.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/check.hpp 
b/3rdparty/stout/include/stout/check.hpp
index 6a33579..7651150 100644
--- a/3rdparty/stout/include/stout/check.hpp
+++ b/3rdparty/stout/include/stout/check.hpp
@@ -23,9 +23,15 @@
 #include <stout/error.hpp>
 #include <stout/none.hpp>
 #include <stout/option.hpp>
-#include <stout/result.hpp>
 #include <stout/some.hpp>
-#include <stout/try.hpp>
+
+
+template <typename T>
+class Result;
+
+template <typename T, typename E>
+class Try;
+
 
 // A generic macro to facilitate definitions of CHECK_*, akin to CHECK.
 // This appends the error if possible to the end of the log message,
@@ -102,6 +108,67 @@ const T& _check_not_none(
       (expression))
 
 
+// A private helper for CHECK_NOTERROR which is similar to the
+// CHECK_NOTNULL provided by glog.
+template <typename T, typename E>
+T&& _check_not_error(
+    const char* file,
+    int line,
+    const char* message,
+    Try<T, E>&& t) {
+  if (t.isError()) {
+    google::LogMessageFatal(
+        file,
+        line,
+        new std::string(
+            std::string(message) + ": " + Error(t.error()).message));
+  }
+  return std::move(t).get();
+}
+
+
+template <typename T, typename E>
+T& _check_not_error(
+    const char* file,
+    int line,
+    const char* message,
+    Try<T, E>& t) {
+  if (t.isError()) {
+    google::LogMessageFatal(
+        file,
+        line,
+        new std::string(
+            std::string(message) + ": " + Error(t.error()).message));
+  }
+  return t.get();
+}
+
+
+template <typename T, typename E>
+const T& _check_not_error(
+    const char* file,
+    int line,
+    const char* message,
+    const Try<T, E>& t) {
+  if (t.isError()) {
+    google::LogMessageFatal(
+        file,
+        line,
+        new std::string(
+            std::string(message) + ": " + Error(t.error()).message));
+  }
+  return t.get();
+}
+
+
+#define CHECK_NOTERROR(expression) \
+  _check_not_error( \
+      __FILE__, \
+      __LINE__, \
+      "'" #expression "' Must be SOME", \
+      (expression))
+
+
 // Private structs/functions used for CHECK_*.
 
 template <typename T>
@@ -116,8 +183,8 @@ Option<Error> _check_some(const Option<T>& o)
 }
 
 
-template <typename T>
-Option<Error> _check_some(const Try<T>& t)
+template <typename T, typename E>
+Option<Error> _check_some(const Try<T, E>& t)
 {
   if (t.isError()) {
     return Error(t.error());
@@ -168,8 +235,8 @@ Option<Error> _check_none(const Result<T>& r)
 }
 
 
-template <typename T>
-Option<Error> _check_error(const Try<T>& t)
+template <typename T, typename E>
+Option<Error> _check_error(const Try<T, E>& t)
 {
   if (t.isSome()) {
     return Error("is SOME");

Reply via email to