Asylo
Macros
status_macros.h File Reference
#include "absl/base/optimization.h"
#include "asylo/util/status.h"
#include "asylo/util/statusor.h"
Include dependency graph for status_macros.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ASYLO_RETURN_IF_ERROR(expr)
 Evaluates an expression that produces an asylo::Status. More...
 
#define ASYLO_ASSIGN_OR_RETURN(lhs, rexpr)
 Evaluates an expression rexpr that returns an asylo::StatusOr<T>. More...
 

Macro Definition Documentation

◆ ASYLO_ASSIGN_OR_RETURN

#define ASYLO_ASSIGN_OR_RETURN (   lhs,
  rexpr 
)
Value:
do { \
auto _asylo_status_or_value = (rexpr); \
if (ABSL_PREDICT_FALSE(!_asylo_status_or_value.ok())) { \
return _asylo_status_or_value.status(); \
} \
lhs = std::move(_asylo_status_or_value).ValueOrDie(); \
} while (false)

Evaluates an expression rexpr that returns an asylo::StatusOr<T>.

If the result is OK, moves its value into the variable defined by lhs, otherwise returns the asylo::Status from the current function. The error asylo::Status is returned unchanged. If there is an error, lhs is not evaluated; thus any side effects that lhs may have only occur in the success case.

Interface:

Example: Assigning to an existing variable:

ValueType value;
ASYLO_ASSIGN_OR_RETURN(value, MaybeGetValue(arg));

Example: Assigning to an expression with side effects:

MyProto data;
ASYLO_ASSIGN_OR_RETURN(*data.mutable_str(), MaybeGetValue(arg));
// No field "str" is added on error.

Example: Assigning to a std::unique_ptr.

std::unique_ptr<T> ptr;
ASYLO_ASSIGN_OR_RETURN(ptr, MaybeGetPtr(arg));

◆ ASYLO_RETURN_IF_ERROR

#define ASYLO_RETURN_IF_ERROR (   expr)
Value:
do { \
const auto _asylo_status_to_verify = (expr); \
if (ABSL_PREDICT_FALSE(!_asylo_status_to_verify.ok())) { \
return _asylo_status_to_verify; \
} \
} while (false)

Evaluates an expression that produces an asylo::Status.

If the status is non-OK, returns it from the current function.

Example:

::asylo::Status MultiStepFunction() {
ASYLO_RETURN_IF_ERROR(Function(args...));
ASYLO_RETURN_IF_ERROR(foo.Method(args...));
return ::asylo::Status::OkStatus();
}