C++ · Errors

Errors

#include <ucall/types.hpp> 1.0.0-rc.1 · b7577426

Ask your coding agent about this page, or add the docs server to it

curl -s 'https://www.unum.cloud/docs/ucall/cpp/errors.md' | claude -p "How would this fit my code?"

Every fallible verb answers a status_t, or an expected<T>, a plain pair of a value and its status_t unpacked as auto [value, status], whose value is default-constructed on failure. A status_t carries a status_code_t and an optional static note beside it, so nothing allocates on the failure path, and status == status_code_t::timeout_k compares the code. Recovery branches on the code, while the note names the broken step or resource for logs, falling back to the status name. A mistake the binding catches before calling the library, like asking for an interface the server lacks, reports the status the library would have used.

auto [client, client_status] = uc::client_t::make({.max_concurrent_connections = 1});
auto [response, status] = client.get("http://127.0.0.1:1/");
if (status == uc::status_code_t::connection_failed_k) fmt::println(stderr, "nobody listens: {}", status.note);

A submitted call that fails completes with a failed completed_t::response: connection_failed_k, connection_closed_k, timeout_k, handshake_failed_k or peer_rejected_k. HTTP error statuses are ordinary responses. status_name, io_backend_name and cpu_class_name spell stable names, like “linux-uring618” and “intel-icelake”, and their _from_name twins parse them back, failing with status_code_t::invalid_argument_k on a name no value has. version_name() spells the linked library’s version, candidate suffix included, and decode_percent decodes a path or a query value, which requests hold still percent-encoded.

API

Types

status_code_tWhat went wrong, with one enumerator per status the library reports.
types.hpp:34 ↗
enum status_code_t

Values

success_kucall_status_success_k
deferred_kucall_status_deferred_k
out_of_memory_kucall_status_out_of_memory_k
io_kucall_status_io_k
malformed_kucall_status_malformed_k
internal_kucall_status_internal_k
overflow_kucall_status_overflow_k
uninitialized_kucall_status_uninitialized_k
contended_kucall_status_contended_k
unsupported_kucall_status_unsupported_k
invalid_argument_kucall_status_invalid_argument_k
not_found_kucall_status_not_found_k
already_exists_kucall_status_already_exists_k
connection_failed_kucall_status_connection_failed_k
connection_closed_kucall_status_connection_closed_k
timeout_kucall_status_timeout_k
handshake_failed_kucall_status_handshake_failed_k
peer_rejected_kucall_status_peer_rejected_k
would_block_kucall_status_would_block_k
status_tWhy a call failed: a code recovery branches on, and an optional static note naming the broken invariant, step or resource, for logs and regression analysis.
types.hpp:60 ↗
struct status_t

Fields

codestatus_code_t
notechar const *
expectedA call's value beside its status, bound natively as auto [value, status].
types.hpp:78 ↗
template <typename value_type_>
struct expected

Fields

valuevalue_type_
statusstatus_t

Functions

status_nameThe stable lowercase spelling of code, such as "connection-failed".
types.hpp:299 ↗
std::string_view status_name(status_code_t code) noexcept;
status_from_nameReads a status back from the spelling status_name gives it.
types.hpp:304 ↗
expected<ucall_status_t> status_from_name(
    std::string_view name) noexcept;