Repository: kudu
Updated Branches:
refs/heads/master 29f1543cc -> af9fc13cf
Add a macro to LOG and return on a non-OK status
We often see the following pattern:
Status s = someOperation();
if (!s.ok()) {
LOG(ERROR) << "A critical error occurred at blah. Status: " << s.ToString();
return s;
}
This is cumbersome. This macro allows to do the same the following way:
RETURN_NOT_OK_LOG(someOperation(), ERROR, "A critical error occurred at blah.");
The macro also prints the status (though at the beginning of the
message and not at the end so that we can have arbirarily long
debugging information but the status is easy to find).
Change-Id: Ibb906e7240d7a289a7822444bc9cbf748a555efb
Reviewed-on: http://gerrit.cloudera.org:8080/4927
Reviewed-by: Alexey Serbin <[email protected]>
Tested-by: Kudu Jenkins
Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/dbac80fd
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/dbac80fd
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/dbac80fd
Branch: refs/heads/master
Commit: dbac80fd373c782d60f7dbb031832dc81f5024a2
Parents: 29f1543
Author: David Alves <[email protected]>
Authored: Thu Oct 27 17:52:35 2016 -0700
Committer: David Ribeiro Alves <[email protected]>
Committed: Wed Nov 9 22:28:24 2016 +0000
----------------------------------------------------------------------
src/kudu/util/status.h | 10 ++++++++++
1 file changed, 10 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kudu/blob/dbac80fd/src/kudu/util/status.h
----------------------------------------------------------------------
diff --git a/src/kudu/util/status.h b/src/kudu/util/status.h
index af02c73..289d4e1 100644
--- a/src/kudu/util/status.h
+++ b/src/kudu/util/status.h
@@ -62,6 +62,15 @@
return _s; \
} while (0);
+/// @brief If the given status is not OK, log it and 'msg' at 'level' and
return the status.
+#define KUDU_RETURN_NOT_OK_LOG(s, level, msg) do { \
+ const ::kudu::Status& _s = (s); \
+ if (PREDICT_FALSE(!_s.ok())) { \
+ KUDU_LOG(level) << "Status: " << _s.ToString() << " " << (msg); \
+ return _s; \
+ } \
+ } while (0);
+
/// @brief If @c to_call returns a bad status, CHECK immediately with
/// a logged message of @c msg followed by the status.
#define KUDU_CHECK_OK_PREPEND(to_call, msg) do { \
@@ -92,6 +101,7 @@
#define RETURN_NOT_OK_RET KUDU_RETURN_NOT_OK_RET
#define WARN_NOT_OK KUDU_WARN_NOT_OK
#define LOG_AND_RETURN KUDU_LOG_AND_RETURN
+#define RETURN_NOT_OK_LOG KUDU_RETURN_NOT_OK_LOG
#define CHECK_OK_PREPEND KUDU_CHECK_OK_PREPEND
#define CHECK_OK KUDU_CHECK_OK