Brain Docs

Reference

Rust SDKInstallationHTTP clientWire client
ErrorsRetriesPagination
Brain/Docs
✦ ASKBrain on GitHubDashboard
Rust SDKErrors

Errors

Both taxonomies — the wire BrainError enum with its nine categories and eighty-odd codes, and the HTTP tier's BrainHttpError.

PURPOSE

The two tiers fail differently and the SDK does not paper over it. The wire client returns a BrainError enum carrying the protocol's own error frames; the HTTP client returns BrainHttpError carrying a status and a string code. This page catalogs both.

Wire tier: the BrainError enum

One enum, matched exhaustively — not a class hierarchy.

ParameterTypeRequired
Io(std::io::Error)variantrequired

The socket failed. Retryable. Converts from std::io::Error.

Frame(FrameError)variantoptional

The frame codec rejected the bytes. Fatal for the connection.

Cbor(CborError)variantoptional

The payload codec rejected the bytes.

Protocol(String)variantoptional

The peer broke the protocol sequence. Not retryable.

Server { code, category, message, retry_after_ms, response }variantoptional

The server returned a structured ERROR frame. The boxed response carries the whole thing.

VersionMismatch { chosen, supported }variantoptional

The server chose a wire version the client did not offer. Never retryable.

Closedvariantoptional

The peer closed the connection. Retryable — on a new connection.

Timeout(Duration)variantoptional

An operation missed its deadline. Retryable.

Five inherent methods:

ParameterTypeRequired
is_retryable()boolrequired

true for Io, Closed, Timeout, and a Server error whose category is ResourceExhausted or Unavailable. Nothing else.

retry_after()Option<Duration>optional

The server's hint, when it sent one. Treat it as a floor, not a target — see Retries.

is_act_as_denied()booloptional

A Server error carrying ErrorCodeWire::ActAsDenied (0x0033) — the principal lacks the can_act_as grant, or named a namespace outside its allowlist. Never retryable; the fix is a differently-scoped credential.

is_llm_credential_missing()booloptional

LlmCredentialMissing (0x0066) — the write's namespace has no provider key registered. Terminal: retrying cannot create a key. Surface it as "register a provider key", not as a transient failure.

is_llm_credential_unavailable()booloptional

LlmCredentialUnavailable (0x0095) — a key exists, but the credential broker was unreachable, timed out or failed transiently. Retryable.

Why the three code predicates exist

is_retryable reads only the category, and the category does not separate a tenant that has never registered a provider key from a broker that blipped — one can never succeed, the other almost certainly will. The same two conditions, plus act-as denial, are ServerError subclasses in Python (ActAsDenied, LlmCredentialMissing, LlmCredentialUnavailable) and isActAsDenied-style functions in TypeScript. Matching the code field of the Server variant by hand still works, and is the only option for every other code.

use brain_db_sdk::{wire::types::ErrorCategoryWire, BrainError};

match client.encode(&request).await {
    Ok(res) => res,
    // Terminal, and not what `is_retryable` would tell you — test it first.
    Err(e) if e.is_llm_credential_missing() => return prompt_for_provider_key(),
    Err(e) if e.is_retryable() => return schedule_retry(e.retry_after()),
    Err(BrainError::Server { category: ErrorCategoryWire::Validation, message, .. }) => {
        eprintln!("bad request: {message}");
        return Err(anyhow::anyhow!(message));
    }
    Err(e) => return Err(e.into()),
}

Categories

CategoryValueMeaningRetry
Protocol0Malformed or out-of-sequence request.No
Authentication1The credential was rejected.No
Authorization2The identity lacks permission.No
Validation3The request failed input validation.No
NotFound4The referenced thing does not exist.No
Conflict5Idempotency or transaction conflict.No
ResourceExhausted6Rate or quota limit. May carry retry_after_ms.Yes
Internal7Server-side failure.No
Unavailable8The shard is temporarily unavailable.Yes

Codes

ErrorCodeWire is a u16-backed enum. The families, by prefix:

OptionTypeDefault / Env
0x0001–0x000BFraming

BadMagic, BadHeaderCrc, BadPayloadCrc, BadOpcode, BadVersion, BadFrame, OversizePayload, ReservedFieldNonZero, BadFlagCombination, MalformedPayload, MalformedVector.

0x0020–0x0025Authentication

VersionNotSupported, NoSuchAuthMethod, Unauthenticated, NotAuthenticated, AuthBackendUnavailable, SessionExpired.

0x0030–0x0033Authorization

PermissionDenied, AdminPermissionRequired, WrongShard, ActAsDenied.

0x0040–0x004CValidation

InvalidArgument, MissingRequiredField, TextTooLarge, TextEmpty, BadSessionId, BadMemoryKind, BadEdgeKind, BadStrategyHint, TopKOutOfRange, BudgetTooLarge, BadModelFingerprint, PredicateNotInSchema, RelationTypeNotInSchema.

0x0050–0x0054Not found

MemoryNotFound, ContextNotFound, SubscriptionNotFound, SnapshotNotFound, TxnNotFound.

0x0060–0x0066Conflict

IdempotencyConflict, TransactionConflict, TransactionTimeout, StreamIdInUse, SubscriptionLsnTooOld, CardinalityViolation, LlmCredentialMissing (0x0066).

0x0070–0x0077Resource exhausted

OutOfSlots, OutOfDisk, OutOfMemory, RateLimited, StreamLimitExceeded, ConnectionLimitExceeded, TransactionLimitExceeded, TransactionTooLarge.

0x0080–0x0085Internal

Internal, StorageError, IndexError, EmbeddingError, MetadataError, Cancelled.

0x0090–0x0095Unavailable

ShardUnavailable, Overloaded, Restarting, Maintenance, RetrieverDegraded, LlmCredentialUnavailable (0x0095).

0x0120–0x0172Graph and extraction

SchemaInvalid, SchemaMigrationRequired, EntityNotFound, EntityTypeMismatch, EntityAmbiguous, EntityMergeConflict, StatementNotFound, StatementObjectTypeMismatch, StatementContradictsExisting, QueryTimeout, QueryOverBudget, ExtractorDisabled, ExtractorBudgetExceeded, ExtractionFailed.

ErrorCodeWire::from_raw maps an unrecognised value to Unknown rather than failing to deserialize, so a client built against an older SDK still surfaces a newer server's errors. Match arms on this enum therefore need a _ case.

HTTP tier: BrainHttpError

One struct, not an enum.

FieldTypePresence
statusu16always

The HTTP status. 0 means the request never got an answer — a transport failure or a client-side timeout.

codeStringalways

The edge's stable string code. Branch on this, not on the message.

field_errorsVec<FieldError>always

Per-field validation detail. Empty unless the edge rejected specific fields.

messageStringalways

Human-readable. Never parse it.

status: 0 with code: "config" is client-side misconfiguration, returned by try_new before any request is attempted: an empty api_key, an api_key carrying an ASCII control character, or a base_url without an http/https scheme. Every other status == 0 is a transport failure or a timeout — which the retry policy does treat as transient, so test code before deciding to retry.

Validation failures are not always errors

The schema verbs return Ok with a populated validation_errors vector rather than Err. ? on those calls propagates transport and auth failures only. See validateSchema.

See also
RetriesProvider credentialsWire client

Was this page helpful?

ping

A connection-level liveness check that works while streams are in flight.

Retries

Both retry layers — the HTTP client's automatic policy with its idempotent-only verb list, and the wire tier's with_retry combinator.

On this page

Wire tier: the BrainError enumCategoriesCodesHTTP tier: BrainHttpError
Suggest an editOpen in Playground