IError#
Fully qualified name: carb::IError
Defined in carb/detail/Error2.h
-
class IError#
The low-level API for interacting with the Carbonite error handling system. At the core, this system maintains a thread-specific error code and optional error message.
The state of the error objects are maintained through
libcarb.so/carb.dll, the API is accessed throughcarbGetErrorApiorErrorApi::instance. Different versions of the API interact with the same global state. A call toErrorApi::viewCurrentErrorwith version 1.0 will still be able to read aErrorApi::setErrorfrom a version 4.0 API (version 4.0 does not exist at this time).Subclassed by carb::ErrorApi
Public Functions
-
virtual ErrorPtr viewCurrentError() const noexcept = 0#
Access the current thread’s Error, if any.
Note: the error remains set for the current thread. In order to clear the error after viewing it, call ErrorApi::clearError or setError with
nullptr.
-
virtual void setError(ErrorPtr error) const noexcept = 0#
Set this thread’s current error to the exact given
erroror clear the current error iferroris empty.- Parameters:
error – The error to set. If this is empty, this clears the current error.
-
virtual void setErrorOom() const noexcept = 0#
Set this thread’s current error to a pre-allocated error indicating the system is out of memory. It will always succeed.
- virtual omni::expected<void, ErrorCode> setError(
- ErrorCode code,
- cpp::string_view message = {},
Set this thread’s current error to a pre-formatted string.
In the case of any error of a call to this function, the current error will always be set with code. However, the associated message of the error will be the default for that code.
- Possible returned ErrorCodes
kInvalidArgument - A default-constructed
codewas given (or ErrorCode::kOutOfMemory), but with a non-emptymessage. Thecodeis still set as the current error butmessageis ignored.kResultOutOfMemory - the message is too large to fit in the string buffer, but the call to allocate memory failed. The current error is still set to code, but the error message is saved as the default for that code.
kResultTooMuchData - the provided message is too large to fit in any error message buffer (the current maximum is 64 KiB). The current error will be set with a truncated version of the provided message.
- Parameters:
code – The code for the created error, which callers can potentially act on.
message – The associated message containing additional details about the error. If empty, the default default message for
codeis used. A non-empty message is not allowed for kOutOfMemory or a default-constructedcode.
- Returns:
voidon success; if an error occurs while setting the current error, anomni::unexpectedis returned with the ErrorCode.
- virtual omni::expected<ErrorPtr, ErrorCode> errorCreate(
- ErrorCode code,
- cpp::string_view message = {},
Create an error message with the code and pre-formatted message string without setting the current error.
The parameters operate similarly to
setError, but are more strict. WheresetErrorwould return a non-OK code but still set the current error, this function would returnomni::unexpectedwith the error.- Possible return ErrorCode values
ErrorCode::kInvalidArgument - a default-constructed
codewas provided, or ErrorCode::kOutOfMemory was given with a non-empty message.
- Parameters:
code – The code for the created error, which callers can potentially act on. This does not have to be a pre-defined ErrorCode value.
message – The associated message containing additional details about the error.
- Returns:
The created error on success. On failure,
omni::unexpectedwith an ErrorCode is returned giving the reason for the failure.
- virtual cpp::optional<std::pair<cpp::zstring_view, cpp::zstring_view>> getCodeDescription(
- ErrorCode code,
Retrieve the name and default message for the given code.
The name is a symbol-like name in snake case like
"invalid_argument". The message is the default message for the code as a sentence fragment like"invalid argument".- Possible ErrorCode return values
kResultNotFoundif code is not in the known list of error codes.
Note
The current error is not changed.
- Parameters:
code – The ErrorCode to look up.
- Returns:
A optional containing a
std::pair<name, message>on success, wherenameandmessageare of type carb::cpp::zstring_view. If the code is not a known default ErrorCode,carb::cpp::nulloptis returned instead.
- virtual ErrorCode currentError(
- cpp::zstring_view *outMessage = nullptr,
A simple helper function to retrieve the ErrorCode stored by the current thread.
- Parameters:
outMessage – If not
nullptr, will receive the error message stored by the current thread. If no error message is stored by the current thread, this will receive an empty zstring_view. This view is valid until the error stored by the current thread changes.- Returns:
The ErrorCode stored by the current thread. If no ErrorCode is stored by the current thread, This will be a default-constructed ErrorCode.
Public Static Functions
- static inline constexpr carb::InterfaceDesc getInterfaceDesc(
Returns information about this interface.
Auto-generated by CARB_PLUGIN_INTERFACE() or CARB_PLUGIN_INTERFACE_EX.
- Returns:
The carb::InterfaceDesc struct with information about this interface.
- static inline constexpr carb::InterfaceDesc getLatestInterfaceDesc(
Returns information about the latest version of this interface.
Auto-generated by CARB_PLUGIN_INTERFACE() or CARB_PLUGIN_INTERFACE_EX.
- Returns:
The carb::InterfaceDesc struct with information about the latest version of this interface.
-
virtual ErrorPtr viewCurrentError() const noexcept = 0#