# `Arcadic.Error`
[🔗](https://github.com/baselabs/arcadic/blob/baselabs_arcadic-v4.0.1/lib/arcadic/error.ex#L5)

A server-returned ArcadeDB error, normalized to a typed `reason`.

Exception messages and inspection omit the raw response's diagnostic
fields. Read `error.detail` explicitly during controlled debugging and
keep it out of logs.

## `reason` taxonomy

Server-derived (mapped from the HTTP response or gRPC status and trailers):

- `:not_idempotent` — a write reached the read-only `/query` endpoint
  (`QueryNotIdempotentException`).
- `:parse_error` — the statement failed to parse (`Parsing`/`ParseException`).
- `:unauthorized` for missing credentials, rejected credentials, or a request
  that the server forbids. ArcadeDB can also forbid an import or restore source.
- `:database_not_found` for an absent database. Also covers the equivalent
  server classes `DatabaseOperationException`, `DatabaseNotAvailableException`,
  and `DatabaseNotFoundException`.
- `:transaction_error` — a transaction-lifecycle failure, both server-derived
  (`TransactionException`) and client-raised (no active/already-open session;
  a Bolt commit failure).
- `:concurrent_modification` — an optimistic-concurrency conflict
  (`ConcurrentModificationException`/`NeedRetryException`).
- `:duplicate_key` — a confirmed unique-index violation (`DuplicatedKeyException`).
- `:already_exists` — a taken name or an unclassified gRPC conflict.
- `:partial_commit` — the server reports that part of a gRPC write committed.
- `:grpc_rejected` — a terminal gRPC status without a classified server exception.
- `:aborted`, `:failed_precondition`, and `:resource_exhausted` — gRPC rejection
  statuses 10, 9, and 8 without a more specific known exception.
- `:cursor_buffer_exceeded` — a gRPC cursor exceeded its unread response budget.
- `:outcome_unknown` — a dispatched operation has an unconfirmed effect.
  This reason is returned in `Arcadic.TransportError`, including when ArcadeDB
  explicitly reports an unconfirmed transaction outcome.
- `:timeout` — the server reported a timeout (`TimeoutException`).
- `:not_leader` — the target node is not the cluster leader and could not forward
  the write (`ServerIsNotTheLeaderException`, HTTP 400). A managed-retry
  `transaction/3` and multi-host failover treat it as retriable (the write was
  rejected, nothing applied).
- `:http_redirect` — an HTTP 3xx response. The client declines to follow it
  and reports only the status.
- `:invalid_begin_body` — a malformed `isolationLevel` in a transaction-begin body.
- `:server_error` — the generic fallback: an unrecognized HTTP 400 body, or an
  `exception` FQN that matches none of the above.

The client also produces errors while validating calls or interpreting
responses.

- `:use_explain` — `query`/`command` (either transport) or `query_stream` (HTTP)
  was called on a statement that already carries an `EXPLAIN`/`PROFILE` prefix,
  which returns a plan rather than rows; call `explain/4`/`profile/4` instead. The
  guard is response-layer: HTTP via `Arcadic.Result.normalize/1`, Bolt via the
  `execute/4` plan-presence check.
- `:not_supported` — the active transport doesn't implement the called
  capability (e.g. `explain/4` against a transport without it, HTTP streaming
  inside a transaction, Bolt's admin-only calls, async writes without
  `execute_async/3`).
- `:unexpected_response` — a 2xx response whose body is off the documented contract
  (client-raised by the time-series read paths and `list_databases`; the body is never echoed).
- `:invalid_params` — a caller param or statement that cannot be encoded for the wire
  (an invalid-UTF-8 binary, a term with no JSON/gRPC representation). Raised by the
  boundary, never as a mid-encode exception echoing the value.
- `:import_failed` — an import whose 2xx result row itself reported `"result" => "FAIL"`
  (current ArcadeDB reports import-setting failures in the row, not the HTTP status).
- `:interrupted_migration` — `Arcadic.Migrator` found an `up_started`/`down_started`
  marker from an attempt whose outcome is unknown; reconcile via
  `Arcadic.Migrator.resolve/3` (versions via `Arcadic.Migrator.interrupted/1`).
- `:invalid_state` — a `Migrator.resolve/3` transition was attempted against a
  non-interrupted version or matched no rows.
- `:invalid_transport_options` — contradictory transport options (e.g. both
  `:cacertfile` and `:cacerts` on a gRPC conn).
- `:transaction_unsupported` — the transport cannot include the operation
  in an open transaction.

A separate, non-`Arcadic.Error` convention: several admin validators reject
bad input as a **bare atom** tuple, never this struct, and never echoing the
offending value — `{:error, :invalid_identifier}` (`Arcadic.Identifier.validate/1`,
e.g. a bad database/type name), `{:error, :invalid_setting_key}` /
`{:error, :invalid_setting_value}` (`Arcadic.Server.set_server_setting/3` and
`set_database_setting/3`), `{:error, :invalid_url}`
(`Arcadic.Backup.backup/2`'s `:to` target and `restore/3`'s source URL, via
`Arcadic.Identifier.validate_url/1`), `{:error, :invalid_user_spec}`
(`Arcadic.Security.create_user/2` — an unencodable user spec, e.g. a non-UTF-8 password),
`{:error, :unencodable_body}` (`Arcadic.Function.define/4` and `Arcadic.Trigger.create/4` —
a body containing the sole breakout byte, a backslash, or a control/line byte, none of which
ArcadeDB's `"..."` DDL literal can escape), and, from `Arcadic.Changes`,
`{:error, :mint_web_socket_not_available}` (`start_link/1`, when the optional
`mint_web_socket` dependency is absent), `{:error, :subscriber_conflict}`
(`subscribe/3`, a second subscriber pid on an already-bound process), and the
`start_link/1` conn-shape rejections `{:error, :invalid_conn}` (no/invalid
`:conn`), `{:error, :invalid_auth}` (an auth shape other than `{user, pass}` /
`{:bearer, token}`), `{:error, :invalid_url_scheme}` (a `base_url` scheme
outside `http`/`https`/`ws`/`wss` — guards against a silent plaintext
downgrade), and `{:error, :invalid_max_buffer}` (a non-positive-integer
`:max_buffer`).

# `batch_progress`

```elixir
@type batch_progress() :: %{
  partial_commit: boolean(),
  vertices_created: non_neg_integer(),
  edges_created: non_neg_integer()
}
```

Graph batch progress reported on failure. Counts are upper bounds on durable
writes, since ArcadeDB can buffer records before committing them.

# `t`

```elixir
@type t() :: %Arcadic.Error{
  __exception__: term(),
  batch_progress: batch_progress() | nil,
  detail: String.t() | nil,
  exception: String.t() | nil,
  http_status: pos_integer() | nil,
  message: String.t() | nil,
  reason: atom()
}
```

# `from_response`

```elixir
@spec from_response(pos_integer(), map()) :: t() | Arcadic.TransportError.t()
```

Build an `Arcadic.Error` from an HTTP status and a decoded ArcadeDB error body.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
