# Errors

> Every fallible verb answers an error, a *Error carrying the Status the C ABI reported and the static message beside it, so errors.Is matches it against a bare Status and errors.As reaches the message.

`import "github.com/unum-cloud/ustore"` 1.0.0-rc.1 · 084197c4

Every fallible verb answers an `error`, a `*Error` carrying the `Status` the C ABI reported and the static message beside it, so `errors.Is` matches it against a bare `Status` and `errors.As` reaches the message. A closed handle is refused with `StatusUninitialized` before anything crosses, and a batch whose runs disagree in length with `StatusInvalidArgument`. `Status`, `Durability`, `Watch`, `Modality` and the other enums print through `String` and parse through their `FromName` functions the spellings the C tables own, such as `"not-found"` or `"strict-serializable"`.

```go
_, err := database.CollectionCreate("people", ustore.ModalityBlobs)
if errors.Is(err, ustore.StatusAlreadyExists) {
	fmt.Println(err)
}
fmt.Println(ustore.VersionName()) // the library the program runs against, such as "1.0.0-rc.1"
```

## API

### Struct `Error`

Error is one failed call: a status every caller can branch on, and the detail the status cannot carry.2

[types.go:153 ↗](https://github.com/unum-cloud/UStore/blob/084197c470a8c329d83051d880c71e7972b9e1b2/types.go#L153)

```go
type Error struct {
    Status  Status
    Message string
}
```

Reach the status with errors.Is or errors.As.

#### `Error`

Error implements the error interface.

[types.go:159 ↗](https://github.com/unum-cloud/UStore/blob/084197c470a8c329d83051d880c71e7972b9e1b2/types.go#L159)

```go
func (failure *Error) Error() string
```

#### `Unwrap`

Unwrap exposes the status, which is what errors.Is compares.

[types.go:164 ↗](https://github.com/unum-cloud/UStore/blob/084197c470a8c329d83051d880c71e7972b9e1b2/types.go#L164)

```go
func (failure *Error) Unwrap() error
```

### Enum `Status`

Status names what went wrong, in a vocabulary shared by every engine and by this binding.3

[types.go:83 ↗](https://github.com/unum-cloud/UStore/blob/084197c470a8c329d83051d880c71e7972b9e1b2/types.go#L83)

```go
type Status int32
```

Validation performed here before a call crosses reports the status the engine would have reported for the same fault.

A Status is an error, so errors.Is matches any failure carrying it against a bare Status.

#### Values

| `StatusSuccess` | | StatusSuccess means the call succeeded and carries no message. |
| - | - | - |
| `StatusDeferred` | | StatusDeferred means the call was submitted deferred and is not final yet. |
| `StatusOutOfMemory` | | StatusOutOfMemory means an allocation could not be satisfied. |
| `StatusReadOnly` | | StatusReadOnly means the call would change a database opened read-only. |
| `StatusIO` | | StatusIO means a file or directory could not be opened, read, written, or closed. |
| `StatusDevice` | | StatusDevice means a device could not be selected or its memory claimed, or the call's executor, database and arena belong to different residencies or devices. |
| `StatusMalformed` | | StatusMalformed means stored or supplied data could not be decoded. |
| `StatusInternal` | | StatusInternal means the engine failed in a way no other status names. |
| `StatusOverflow` | | StatusOverflow means a count passed what its word holds, like the open exports of one arena. |
| `StatusUninitialized` | | StatusUninitialized means the call needs a handle that was never opened or is closed. |
| `StatusConfigMismatch` | | StatusConfigMismatch means the handles or arguments are each well-formed but cannot be joined. |
| `StatusContended` | | StatusContended means the call was refused rather than waited for: another call holds its executor, arena, cursor or transaction. |
| `StatusCancelled` | | StatusCancelled means a progress handler stopped the call, which unwound and published nothing. |
| `StatusUnsupported` | | StatusUnsupported means the engine or build does not implement what the call asks for. |
| `StatusInvalidArgument` | | StatusInvalidArgument means an argument is missing, contradicts another one, or carries a choice the call does not accept. |
| `StatusNotFound` | | StatusNotFound means a collection, a directory, or a document a modification needs does not exist. |
| `StatusAlreadyExists` | | StatusAlreadyExists means a collection name or a document the call creates is already taken. |
| `StatusWriteConflict` | | StatusWriteConflict means a concurrent writer changed a key this transaction wrote. |
| `StatusReadConflict` | | StatusReadConflict means a concurrent writer changed a key this transaction read. |
| `StatusPhantomConflict` | | StatusPhantomConflict means a concurrent writer inserted into a range this transaction scanned. |
| `StatusCapacityExhausted` | | StatusCapacityExhausted means a hard design ceiling was reached. |

##### `StatusFromName`

StatusFromName reads a status back from the spelling [Status.String](https://www.unum.cloud/docs/ustore/go/platform-notes.md#String) renders.

[types.go:142 ↗](https://github.com/unum-cloud/UStore/blob/084197c470a8c329d83051d880c71e7972b9e1b2/types.go#L142)

```go
func StatusFromName(name string) (Status, error)
```

##### `Error`

Error implements the error interface, so a bare Status is an errors.Is target.

[types.go:149 ↗](https://github.com/unum-cloud/UStore/blob/084197c470a8c329d83051d880c71e7972b9e1b2/types.go#L149)

```go
func (status Status) Error() string
```

##### `String`

String renders the status as the library spells it, such as "not-found".

[types.go:137 ↗](https://github.com/unum-cloud/UStore/blob/084197c470a8c329d83051d880c71e7972b9e1b2/types.go#L137)

```go
func (status Status) String() string
```
