Kudu C++ client API
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. More...
 
#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. More...
 
#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. More...
 
#define KUDU_RETURN_NOT_OK_EVAL(s, on_error)
 Return the given status if it is not OK, evaluating on_error if so. More...
 
#define KUDU_WARN_NOT_OK(to_call, warning_prefix)
 Emit a warning if to_call returns a bad status. More...
 
#define KUDU_LOG_AND_RETURN(level, status)
 Log the given status and return immediately. More...
 
#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. More...
 
#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. More...
 
#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. More...
 
#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.
 

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_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.