Errors
Both taxonomies — the wire BrainError enum with its nine categories and eighty-odd codes, and the HTTP tier's BrainHttpError.
Wire tier: the BrainError enum
One enum, matched exhaustively — not a class hierarchy.
Io(std::io::Error)variantrequiredThe socket failed. Retryable. Converts from std::io::Error.
Frame(FrameError)variantoptionalThe frame codec rejected the bytes. Fatal for the connection.
Cbor(CborError)variantoptionalThe payload codec rejected the bytes.
Protocol(String)variantoptionalThe peer broke the protocol sequence. Not retryable.
Server { code, category, message, retry_after_ms, response }variantoptionalThe server returned a structured ERROR frame. The boxed response carries
the whole thing.
VersionMismatch { chosen, supported }variantoptionalThe server chose a wire version the client did not offer. Never retryable.
ClosedvariantoptionalThe peer closed the connection. Retryable — on a new connection.
Timeout(Duration)variantoptionalAn operation missed its deadline. Retryable.
Five inherent methods:
is_retryable()boolrequiredtrue for Io, Closed, Timeout, and a Server error whose category
is ResourceExhausted or Unavailable. Nothing else.
retry_after()Option<Duration>optionalThe server's hint, when it sent one. Treat it as a floor, not a target — see Retries.
is_act_as_denied()booloptionalA 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()booloptionalLlmCredentialMissing (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()booloptionalLlmCredentialUnavailable (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
| Category | Value | Meaning | Retry |
|---|---|---|---|
Protocol | 0 | Malformed or out-of-sequence request. | No |
Authentication | 1 | The credential was rejected. | No |
Authorization | 2 | The identity lacks permission. | No |
Validation | 3 | The request failed input validation. | No |
NotFound | 4 | The referenced thing does not exist. | No |
Conflict | 5 | Idempotency or transaction conflict. | No |
ResourceExhausted | 6 | Rate or quota limit. May carry retry_after_ms. | Yes |
Internal | 7 | Server-side failure. | No |
Unavailable | 8 | The shard is temporarily unavailable. | Yes |
Codes
ErrorCodeWire is a u16-backed enum. The families, by prefix:
0x0001–0x000BFramingBadMagic, BadHeaderCrc, BadPayloadCrc, BadOpcode, BadVersion,
BadFrame, OversizePayload, ReservedFieldNonZero,
BadFlagCombination, MalformedPayload, MalformedVector.
0x0020–0x0025AuthenticationVersionNotSupported, NoSuchAuthMethod, Unauthenticated,
NotAuthenticated, AuthBackendUnavailable, SessionExpired.
0x0030–0x0033AuthorizationPermissionDenied, AdminPermissionRequired, WrongShard,
ActAsDenied.
0x0040–0x004CValidationInvalidArgument, MissingRequiredField, TextTooLarge, TextEmpty,
BadSessionId, BadMemoryKind, BadEdgeKind, BadStrategyHint,
TopKOutOfRange, BudgetTooLarge, BadModelFingerprint,
PredicateNotInSchema, RelationTypeNotInSchema.
0x0050–0x0054Not foundMemoryNotFound, ContextNotFound, SubscriptionNotFound,
SnapshotNotFound, TxnNotFound.
0x0060–0x0066ConflictIdempotencyConflict, TransactionConflict, TransactionTimeout,
StreamIdInUse, SubscriptionLsnTooOld, CardinalityViolation,
LlmCredentialMissing (0x0066).
0x0070–0x0077Resource exhaustedOutOfSlots, OutOfDisk, OutOfMemory, RateLimited,
StreamLimitExceeded, ConnectionLimitExceeded,
TransactionLimitExceeded, TransactionTooLarge.
0x0080–0x0085InternalInternal, StorageError, IndexError, EmbeddingError,
MetadataError, Cancelled.
0x0090–0x0095UnavailableShardUnavailable, Overloaded, Restarting, Maintenance,
RetrieverDegraded, LlmCredentialUnavailable (0x0095).
0x0120–0x0172Graph and extractionSchemaInvalid, 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.
statusu16alwaysThe HTTP status. 0 means the request never got an answer — a
transport failure or a client-side timeout.
codeStringalwaysThe edge's stable string code. Branch on this, not on the message.
field_errorsVec<FieldError>alwaysPer-field validation detail. Empty unless the edge rejected specific fields.
messageStringalwaysHuman-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.
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.
Was this page helpful?