- Initial sync failures - surfaced as
Err(NexusError::...)fromNexusClient::create. Refuse to start the application; an empty cache is unsafe to serve. - 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_configreturnsNone;get_flagreturnsdefault_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:
- Marks
billing_overdue()astrue. - Halts the background refresh loop - reads continue to serve the last cached snapshot.
- Returns
NexusError::Billingfromsync.
WIF-specific errors
Whenwif.enabled is true:
WifNotConfigured- no usable provider found in the environment and notoken_sourcewas provided. Either the Kubernetes SA token file is absent,AWS_ROLE_ARNis not set, or GCP/Azure metadata endpoints are unreachable. Provide an explicittoken_sourceto 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. Inspectmsgfor the HTTP status code detail.SessionExpired- fires only when the session JWT expires and the refresh attempt fails, AND no staticapi_keyfallback is configured. Provide bothwifandapi_keyfor automatic fallback in degraded conditions.
Using with anyhow or thiserror
NexusError implements std::error::Error, so it composes with popular error-handling crates:
