# Errors

> 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.

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

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.

```cpp
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_t`

What went wrong, with one enumerator per status the library reports.

[types.hpp:34 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/types.hpp#L34)

```cpp
enum status_code_t
```

#### Values

| `success_k` | `ucall_status_success_k` | |
| - | - | - |
| `deferred_k` | `ucall_status_deferred_k` | |
| `out_of_memory_k` | `ucall_status_out_of_memory_k` | |
| `io_k` | `ucall_status_io_k` | |
| `malformed_k` | `ucall_status_malformed_k` | |
| `internal_k` | `ucall_status_internal_k` | |
| `overflow_k` | `ucall_status_overflow_k` | |
| `uninitialized_k` | `ucall_status_uninitialized_k` | |
| `contended_k` | `ucall_status_contended_k` | |
| `unsupported_k` | `ucall_status_unsupported_k` | |
| `invalid_argument_k` | `ucall_status_invalid_argument_k` | |
| `not_found_k` | `ucall_status_not_found_k` | |
| `already_exists_k` | `ucall_status_already_exists_k` | |
| `connection_failed_k` | `ucall_status_connection_failed_k` | |
| `connection_closed_k` | `ucall_status_connection_closed_k` | |
| `timeout_k` | `ucall_status_timeout_k` | |
| `handshake_failed_k` | `ucall_status_handshake_failed_k` | |
| `peer_rejected_k` | `ucall_status_peer_rejected_k` | |
| `would_block_k` | `ucall_status_would_block_k` | |

#### `status_t`

Why 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 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/types.hpp#L60)

```cpp
struct status_t
```

#### Fields

| `code` | `status_code_t` | |
| - | - | - |
| `note` | `char const *` | |

#### `expected`

A call's value beside its status, bound natively as `auto [value, status]`.

[types.hpp:78 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/types.hpp#L78)

```cpp
template <typename value_type_>
struct expected
```

#### Fields

| `value` | `value_type_` | |
| - | - | - |
| `status` | `status_t` | |

### Functions

#### `status_name`

The stable lowercase spelling of `code`, such as "connection-failed".

[types.hpp:299 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/types.hpp#L299)

```cpp
std::string_view status_name(status_code_t code) noexcept;
```

#### `status_from_name`

Reads a status back from the spelling [`status_name`](#status_name) gives it.

[types.hpp:304 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/types.hpp#L304)

```cpp
expected<ucall_status_t> status_from_name(
    std::string_view name) noexcept;
```
