purify
C++ Purify implementation with native circuit and BPP support
Loading...
Searching...
No Matches
error.hpp File Reference

Library-level error taxonomy used to classify Purify failures. More...

#include <compare>
#include <cstdint>
#include <string_view>
#include <utility>
#include "purify/expected.hpp"

Go to the source code of this file.

Data Structures

struct  purify::Error
 Compact error object returned by checked APIs. More...
 

Namespaces

namespace  purify
 

Macros

#define PURIFY_DETAIL_CONCAT_IMPL(x, y)   x##y
 
#define PURIFY_DETAIL_CONCAT(x, y)   PURIFY_DETAIL_CONCAT_IMPL(x, y)
 
#define PURIFY_RETURN_IF_ERROR(expr, context)    PURIFY_DETAIL_RETURN_IF_ERROR_IMPL(PURIFY_DETAIL_CONCAT(_purify_status_, __COUNTER__), expr, context)
 Evaluates an expected-like expression and returns the wrapped error on failure.
 
#define PURIFY_ASSIGN_OR_RETURN(lhs, expr, context)    PURIFY_DETAIL_ASSIGN_OR_RETURN_IMPL(PURIFY_DETAIL_CONCAT(_purify_result_, __COUNTER__), lhs, expr, context)
 Evaluates an expected-like expression, binds the value to lhs, and propagates errors.
 
#define PURIFY_DETAIL_RETURN_IF_ERROR_IMPL(status_name, expr, context)
 
#define PURIFY_DETAIL_ASSIGN_OR_RETURN_IMPL(result_name, lhs, expr, context)
 

Typedefs

template<typename T >
using purify::Result = Expected< T, Error >
 Expected-returning convenience alias for Purify value-producing APIs.
 
using purify::Status = Expected< void, Error >
 Expected-returning convenience alias for Purify status-only APIs.
 

Enumerations

enum class  purify::ErrorCategory : std::uint8_t { purify::Natural , purify::Usage , purify::Internal }
 High-level classification for all recoverable Purify errors. More...
 
enum class  purify::ErrorCode : std::uint16_t {
  purify::InvalidHex , purify::InvalidHexLength , purify::InvalidFixedSize , purify::Overflow ,
  purify::Underflow , purify::NarrowingOverflow , purify::DivisionByZero , purify::BitIndexOutOfRange ,
  purify::RangeViolation , purify::EmptyInput , purify::SizeMismatch , purify::MissingValue ,
  purify::InvalidSymbol , purify::UnsupportedSymbol , purify::UninitializedState , purify::IndexOutOfRange ,
  purify::InvalidDimensions , purify::NonBooleanValue , purify::EquationMismatch , purify::BindingMismatch ,
  purify::IoOpenFailed , purify::IoWriteFailed , purify::EntropyUnavailable , purify::BackendRejectedInput ,
  purify::HashToCurveExhausted , purify::UnexpectedSize , purify::GeneratorOrderCheckFailed , purify::InternalMismatch ,
  purify::TranscriptCheckFailed
}
 Machine-readable error codes shared across the library. More...
 

Functions

constexpr ErrorCategory purify::error_category (ErrorCode code) noexcept
 Returns the high-level category for a concrete error code.
 
constexpr std::string_view purify::to_string (ErrorCategory category) noexcept
 Returns a stable programmatic name for an error category.
 
constexpr std::string_view purify::to_string (ErrorCode code) noexcept
 Returns a stable programmatic name for an error code.
 
constexpr std::string_view purify::error_message (ErrorCode code) noexcept
 Returns the human-facing description for an error code.
 
constexpr Unexpected< Errorpurify::unexpected_error (ErrorCode code, const char *context=nullptr)
 Constructs an unexpected Error value from a machine-readable code.
 
constexpr Unexpected< Errorpurify::unexpected_error (Error error, const char *context=nullptr)
 Re-wraps an existing Error value for propagation through another Result.
 

Macro Definition Documentation

◆ PURIFY_ASSIGN_OR_RETURN

#define PURIFY_ASSIGN_OR_RETURN (   lhs,
  expr,
  context 
)     PURIFY_DETAIL_ASSIGN_OR_RETURN_IMPL(PURIFY_DETAIL_CONCAT(_purify_result_, __COUNTER__), lhs, expr, context)

Example: PURIFY_ASSIGN_OR_RETURN(auto secret, SecretKey::from_hex(hex), "caller:from_hex"); context is forwarded to unexpected_error().

Definition at line 338 of file error.hpp.

◆ PURIFY_DETAIL_ASSIGN_OR_RETURN_IMPL

#define PURIFY_DETAIL_ASSIGN_OR_RETURN_IMPL (   result_name,
  lhs,
  expr,
  context 
)
Value:
auto result_name = (expr); \
if (!result_name.has_value()) \
return ::purify::unexpected_error(result_name.error(), context); \
lhs = std::move(*result_name)

Definition at line 346 of file error.hpp.

◆ PURIFY_DETAIL_CONCAT

#define PURIFY_DETAIL_CONCAT (   x,
 
)    PURIFY_DETAIL_CONCAT_IMPL(x, y)

Definition at line 321 of file error.hpp.

◆ PURIFY_DETAIL_CONCAT_IMPL

#define PURIFY_DETAIL_CONCAT_IMPL (   x,
 
)    x##y

Definition at line 320 of file error.hpp.

◆ PURIFY_DETAIL_RETURN_IF_ERROR_IMPL

#define PURIFY_DETAIL_RETURN_IF_ERROR_IMPL (   status_name,
  expr,
  context 
)
Value:
auto status_name = (expr); \
if (!status_name.has_value()) \
return ::purify::unexpected_error(status_name.error(), context)

Definition at line 341 of file error.hpp.

◆ PURIFY_RETURN_IF_ERROR

#define PURIFY_RETURN_IF_ERROR (   expr,
  context 
)     PURIFY_DETAIL_RETURN_IF_ERROR_IMPL(PURIFY_DETAIL_CONCAT(_purify_status_, __COUNTER__), expr, context)

This is intended for Status-style propagation and may also be used with Result<T> when the value is intentionally discarded. context is forwarded to unexpected_error().

Definition at line 329 of file error.hpp.