Skip to main content
The SDK distinguishes between two classes of failures:
  1. Initial sync failures - surfaced as Err(NexusError::...) from NexusClient::create. Refuse to start the application; an empty cache is unsafe to serve.
  2. Background sync / SSE failures - never returned to the caller. The existing cache continues to be served.

NexusError variants

NexusError is a Rust enum. Always use match or if let on the variants - never match on the Display string:
NexusError implements std::error::Error and Display, so it integrates naturally with ?, anyhow, thiserror, and other error-handling crates.

When each variant is returned

What is NOT returned as an error

  • Background syncs - silently retried on the next TTL tick. Cache served.
  • SSE transport errors - exponential backoff, 3-strike fallback to polling. The background thread exits silently.
  • 304 Not Modified - treated as success; TTL reset.
  • Missing config / flag - get_config returns None; get_flag returns default_value.
The asymmetry between secrets (return Err) and configs/flags (return None / default) is deliberate: a missing secret usually means “you’re misconfigured, fail fast”, while a missing flag usually means “use the safe default and continue”.

Match patterns

Initial client creation

Reading a secret

Quarantine handling

PublicKeyRestricted fires before the network call

PublicKeyRestricted is returned synchronously inside get_secret - no HTTP request is made. This means the check is instant and cannot fail due to network issues:

402 Payment Required - Billing

When the backend returns HTTP 402 (the tenant has overdue invoices), the SDK:
  1. Marks billing_overdue() as true.
  2. Halts the background refresh loop - reads continue to serve the last cached snapshot.
  3. Returns NexusError::Billing from sync.
The flag clears automatically when a subsequent sync succeeds.

WIF-specific errors

When wif.enabled is true:
  • WifNotConfigured - no usable provider found in the environment and no token_source was provided. Either the Kubernetes SA token file is absent, AWS_ROLE_ARN is not set, or GCP/Azure metadata endpoints are unreachable. Provide an explicit token_source to bypass auto-detection.
  • WifTokenExchangeFailed(msg) - the backend rejected the OIDC token, or the response body could not be decoded. Most often caused by an audience mismatch or clock skew. Inspect msg for the HTTP status code detail.
  • SessionExpired - fires only when the session JWT expires and the refresh attempt fails, AND no static api_key fallback is configured. Provide both wif and api_key for automatic fallback in degraded conditions.

Using with anyhow or thiserror

NexusError implements std::error::Error, so it composes with popular error-handling crates: