Kudu C++ client API
Loading...
Searching...
No Matches
Classes | Macros
status.h File Reference
#include <errno.h>
#include <stdint.h>
#include <cstddef>
#include <string>
#include "kudu/client/stubs.h"
#include "kudu/util/kudu_export.h"
#include "kudu/util/slice.h"

Go to the source code of this file.

Classes

class  kudu::Status
 A representation of an operation's outcome. More...
 

Macros

#define KUDU_RETURN_NOT_OK(s)
 Return the given status if it is not OK.
 
#define KUDU_RETURN_NOT_OK_PREPEND(s, msg)
 Return the given status if it is not OK, but first clone it and prepend the given message.
 
#define KUDU_RETURN_NOT_OK_RET(to_call, to_return)
 Return to_return if to_call returns a bad status. The substitution for 'to_return' may reference the variable s for the bad status.
 
#define KUDU_RETURN_NOT_OK_EVAL(s, on_error)
 Return the given status if it is not OK, evaluating on_error if so.
 
#define KUDU_WARN_NOT_OK(to_call, warning_prefix)
 Emit a warning if to_call returns a bad status.
 
#define KUDU_LOG_AND_RETURN(level, status)
 Log the given status and return immediately.
 
#define KUDU_RETURN_NOT_OK_LOG(s, level, msg)
 If the given status is not OK, log it and 'msg' at 'level' and return the status.
 
#define KUDU_CHECK_OK_PREPEND(to_call, msg)
 If to_call returns a bad status, CHECK immediately with a logged message of msg followed by the status.
 
#define KUDU_CHECK_OK(s)   KUDU_CHECK_OK_PREPEND(s, "Bad status")
 If the status is bad, CHECK immediately, appending the status to the logged message.
 
#define KUDU_DCHECK_OK_PREPEND(to_call, msg)
 If to_call returns a bad status, DCHECK immediately with a logged message of msg followed by the status.
 
#define KUDU_DCHECK_OK(s)   KUDU_DCHECK_OK_PREPEND(s, "Bad status")
 If the status is bad, DCHECK immediately, appending the status to the logged 'Bad status' message.
 
#define KUDU_RETURN_MAIN_NOT_OK(to_call, msg, ret_code)
 A macro to use at the main() function level if it's necessary to return a non-zero status from the main() based on the non-OK status 's' and extra message 'msg' prepended. The desired return code is passed as 'ret_code' parameter.
 

Detailed Description

This header is used in both the Kudu build as well as in builds of applications that use the Kudu C++ client. In the latter we need to be careful to "namespace" our macros, to avoid colliding or overriding with similarly named macros belonging to the application.

KUDU_HEADERS_USE_SHORT_STATUS_MACROS handles this behavioral change. When defined, we're building Kudu and:

Macro Definition Documentation

◆ KUDU_CHECK_OK_PREPEND

#define KUDU_CHECK_OK_PREPEND (   to_call,
  msg 
)
Value:
do { \
const ::kudu::Status& _s = (to_call); \
KUDU_CHECK(_s.ok()) << (msg) << ": " << _s.ToString(); \
} while (0)

If to_call returns a bad status, CHECK immediately with a logged message of msg followed by the status.

◆ KUDU_DCHECK_OK_PREPEND

#define KUDU_DCHECK_OK_PREPEND (   to_call,
  msg 
)
Value:
do { \
const ::kudu::Status& _s = (to_call); \
KUDU_DCHECK(_s.ok()) << (msg) << ": " << _s.ToString(); \
} while (0)

If to_call returns a bad status, DCHECK immediately with a logged message of msg followed by the status.

◆ KUDU_LOG_AND_RETURN

#define KUDU_LOG_AND_RETURN (   level,
  status 
)
Value:
do { \
const ::kudu::Status& _s = (status); \
KUDU_LOG(level) << _s.ToString(); \
return _s; \
} while (0)

Log the given status and return immediately.

◆ KUDU_RETURN_MAIN_NOT_OK

#define KUDU_RETURN_MAIN_NOT_OK (   to_call,
  msg,
  ret_code 
)
Value:
do { \
DCHECK_NE(0, (ret_code)) << "non-OK return code should not be 0"; \
const ::kudu::Status& _s = (to_call); \
if (!_s.ok()) { \
const ::kudu::Status& _ss = _s.CloneAndPrepend((msg)); \
LOG(ERROR) << _ss.ToString(); \
return (ret_code); \
} \
} while (0)

A macro to use at the main() function level if it's necessary to return a non-zero status from the main() based on the non-OK status 's' and extra message 'msg' prepended. The desired return code is passed as 'ret_code' parameter.

◆ KUDU_RETURN_NOT_OK

#define KUDU_RETURN_NOT_OK (   s)
Value:
do { \
const ::kudu::Status& _s = (s); \
if (PREDICT_FALSE(!_s.ok())) return _s; \
} while (0)

Return the given status if it is not OK.

◆ KUDU_RETURN_NOT_OK_EVAL

#define KUDU_RETURN_NOT_OK_EVAL (   s,
  on_error 
)
Value:
do { \
const ::kudu::Status& _s = (s); \
if (PREDICT_FALSE(!_s.ok())) { \
(on_error); \
return _s; \
} \
} while (0)

Return the given status if it is not OK, evaluating on_error if so.

◆ KUDU_RETURN_NOT_OK_LOG

#define KUDU_RETURN_NOT_OK_LOG (   s,
  level,
  msg 
)
Value:
do { \
const ::kudu::Status& _s = (s); \
if (PREDICT_FALSE(!_s.ok())) { \
KUDU_LOG(level) << "Status: " << _s.ToString() << " " << (msg); \
return _s; \
} \
} while (0)

If the given status is not OK, log it and 'msg' at 'level' and return the status.

◆ KUDU_RETURN_NOT_OK_PREPEND

#define KUDU_RETURN_NOT_OK_PREPEND (   s,
  msg 
)
Value:
do { \
const ::kudu::Status& _s = (s); \
if (PREDICT_FALSE(!_s.ok())) return _s.CloneAndPrepend(msg); \
} while (0)

Return the given status if it is not OK, but first clone it and prepend the given message.

◆ KUDU_RETURN_NOT_OK_RET

#define KUDU_RETURN_NOT_OK_RET (   to_call,
  to_return 
)
Value:
do { \
const ::kudu::Status& s = (to_call); \
if (PREDICT_FALSE(!s.ok())) return (to_return); \
} while (0)

Return to_return if to_call returns a bad status. The substitution for 'to_return' may reference the variable s for the bad status.

◆ KUDU_WARN_NOT_OK

#define KUDU_WARN_NOT_OK (   to_call,
  warning_prefix 
)
Value:
do { \
const ::kudu::Status& _s = (to_call); \
if (PREDICT_FALSE(!_s.ok())) { \
KUDU_LOG(WARNING) << (warning_prefix) << ": " << _s.ToString(); \
} \
} while (0)

Emit a warning if to_call returns a bad status.