status.h#

namespace ONNX_LIGHT_NAMESPACE
namespace Common#

Enums

enum class StatusCategory : std::uint8_t#

Identifies the subsystem that generated a non-OK Status.

Each enumerator corresponds to a distinct functional area of the ONNX library so that error handlers can quickly determine the origin of a failure without parsing the error message.

Values:

enumerator NONE#

No category; used by OK (success) statuses.

enumerator CHECKER#

Error originated in the model checker.

enumerator OPTIMIZER#

Error originated in the optimizer.

enum class StatusCode : std::uint8_t#

Distinguishes the type of error carried by a non-OK Status.

Values:

enumerator OK#

Operation completed successfully.

enumerator FAIL#

Generic, unclassified failure.

enumerator INVALID_ARGUMENT#

A caller-supplied argument was invalid.

enumerator INVALID_PROTOBUF#

The serialized protobuf data was malformed or otherwise unreadable.

Functions

inline std::ostream &operator<<(std::ostream &out, const Status &status)#

Streams a human-readable representation of status to out.

Equivalent to writing status.ToString() to the stream.

Parameters:
  • out – Destination output stream.

  • statusStatus value to write.

Returns:

Reference to out to allow chaining.

class Status#
#include <status.h>

Represents the outcome of an operation.

A default-constructed (or OK()-returned) Status represents success and holds no heap allocation. Any non-OK status stores a StatusCategory, a StatusCode, and an optional human-readable error message via a heap-allocated State object.

Usage example
using namespace ONNX_LIGHT_NAMESPACE::Common;

Status ok;                    // success
assert(ok.IsOK());

Status err{StatusCategory::CHECKER, StatusCode::FAIL, "bad model"};
assert(!err.IsOK());
std::cout << err.ToString();  // "CHECKER:1:bad model"

Public Functions

Status() noexcept = default#

Constructs a success (OK) status.

The resulting object has no heap allocation; IsOK() returns true.

Status(StatusCategory category, StatusCode code, const std::string &msg)#

Constructs a non-OK status with a category, code, and message.

Parameters:
  • category – Subsystem that generated the error.

  • code – Error code; must not be StatusCode::OK (asserted in debug builds).

  • msg – Human-readable description of the error.

Status(StatusCategory category, StatusCode code)#

Constructs a non-OK status with a category and code but no message.

Parameters:
  • category – Subsystem that generated the error.

  • code – Error code; must not be StatusCode::OK (asserted in debug builds).

inline Status(const Status &other)#

Copy-constructs a Status from another.

Parameters:

other – Source status to copy.

inline Status &operator=(const Status &other)#

Copy-assigns a Status from another.

Performs a deep copy of the internal State when other is non-OK. Self-assignment is handled safely.

Parameters:

other – Source status to copy.

Returns:

Reference to *this.

Status(Status&&) = default#

Move-constructs a Status, leaving the source in an OK state.

Status &operator=(Status&&) = default#

Move-assigns a Status, leaving the source in an OK state.

~Status() = default#

Destroys the Status, releasing any heap-allocated state.

bool IsOK() const noexcept#

Returns true if the status represents success.

An OK status has no heap-allocated state; this check is therefore equivalent to testing whether the internal pointer is null.

StatusCode Code() const noexcept#

Returns the status code.

Returns StatusCode::OK when IsOK() is true.

StatusCategory Category() const noexcept#

Returns the status category.

Returns StatusCategory::NONE when IsOK() is true.

const std::string &ErrorMessage() const#

Returns the human-readable error message.

Returns a reference to an empty string when IsOK() is true or when no message was supplied to the constructor.

std::string ToString() const#

Returns a human-readable string representation of the status.

For OK statuses returns "OK". For non-OK statuses the format is "[CategoryError] : <code> : <code_name> : <message>", where the category tag is [CheckerError] or [OptimizerError] as appropriate.

inline bool operator==(const Status &other) const#

Returns true if two statuses are equal.

Two statuses are considered equal when they share the same State pointer (identity) or when their ToString() representations match.

Parameters:

otherStatus to compare against.

inline bool operator!=(const Status &other) const#

Returns true if two statuses are not equal.

Parameters:

otherStatus to compare against.

Public Static Functions

static const Status &OK() noexcept#

Returns a reference to a process-lifetime singleton OK status.

Useful when an API must return a const Status& without constructing a new object on each call. The singleton is initialized on first use via a function-local static, which is thread-safe since C++11.

Private Members

std::unique_ptr<State> state_#

Heap-allocated state; null when the status is OK.

Private Static Functions

static const std::string &EmptyString()#

Returns a reference to a process-lifetime empty string.

Initialized on first use via a function-local static; thread-safe since C++11.

struct State#

Internal heap-allocated storage for non-OK status information.

Public Functions

inline State(StatusCategory cat_, StatusCode code_, std::string msg_)#

Constructs a State with the given category, code, and message.

Parameters:
  • cat_Status category.

  • code_Status code.

  • msg_ – Error message string (moved in).

Public Members

StatusCategory category = StatusCategory::NONE#

Subsystem that generated the error.

StatusCode code = {}#

Numeric error code.

std::string msg#

Human-readable error message.