# Errors

> Fallible calls return a status_t, a status_code_t beside an optional static note, or an expected, a plain pair of a value and the status_t beside it, and both are [[nodiscard]].

`#include <ustore/types.hpp>` 1.0.0-rc.1 · 084197c4

Fallible calls return a `status_t`, a `status_code_t` beside an optional static note, or an `expected`, a plain pair of a `value` and the `status_t` beside it, and both are `[[nodiscard]]`. Recovery branches on the code, while the note names the broken invariant, step or resource for logs, falling back to the status name. `auto [value, status]` decomposes an `expected`, whose value is default-constructed on failure. Nothing throws, and a callable that may throw, such as a progress handler, does not compile.

```cpp
auto [db, status] = us::database_t::init_ram();
if (status.failed()) fmt::println(stderr, "{}", status.note);
auto [missing, missing_status] = db.find("nowhere");
if (missing_status == us::status_code_t::not_found_k) fmt::println(stderr, "{}", missing_status.note);
```

## API

### Types

#### `status_code_t`

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

[types.hpp:73 ↗](https://github.com/unum-cloud/UStore/blob/084197c470a8c329d83051d880c71e7972b9e1b2/cpp/ustore/types.hpp#L73)

```cpp
enum status_code_t
```

#### Values

| `success_k` | `ustore_status_success_k` | |
| - | - | - |
| `deferred_k` | `ustore_status_deferred_k` | |
| `out_of_memory_k` | `ustore_status_out_of_memory_k` | |
| `read_only_k` | `ustore_status_read_only_k` | |
| `io_k` | `ustore_status_io_k` | |
| `device_k` | `ustore_status_device_k` | |
| `malformed_k` | `ustore_status_malformed_k` | |
| `internal_k` | `ustore_status_internal_k` | |
| `overflow_k` | `ustore_status_overflow_k` | |
| `uninitialized_k` | `ustore_status_uninitialized_k` | |
| `config_mismatch_k` | `ustore_status_config_mismatch_k` | |
| `contended_k` | `ustore_status_contended_k` | |
| `cancelled_k` | `ustore_status_cancelled_k` | |
| `unsupported_k` | `ustore_status_unsupported_k` | |
| `invalid_argument_k` | `ustore_status_invalid_argument_k` | |
| `not_found_k` | `ustore_status_not_found_k` | |
| `already_exists_k` | `ustore_status_already_exists_k` | |
| `write_conflict_k` | `ustore_status_write_conflict_k` | |
| `read_conflict_k` | `ustore_status_read_conflict_k` | |
| `phantom_conflict_k` | `ustore_status_phantom_conflict_k` | |
| `capacity_exhausted_k` | `ustore_status_capacity_exhausted_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:101 ↗](https://github.com/unum-cloud/UStore/blob/084197c470a8c329d83051d880c71e7972b9e1b2/cpp/ustore/types.hpp#L101)

```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:119 ↗](https://github.com/unum-cloud/UStore/blob/084197c470a8c329d83051d880c71e7972b9e1b2/cpp/ustore/types.hpp#L119)

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

#### Fields

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