Errors & Retries
Everything fallible in the crate returns Result<_, acdp::AcdpError>.
AcdpError is a typed mapping of every RFC-ACDP-0007 §5 wire error code
(plus the codes later RFCs added) and a handful of local/transport errors. It is
#[non_exhaustive], so new variants can be added without a breaking release. This page explains the variants,
how registry wire errors round-trip into them, and which are safe to retry.
The wire error envelope is specified in
RFC-ACDP-0007 (Capabilities & Errors).
The canonical code registry, including which wire line introduced each code, is
the spec's
registries/error-codes.md.
The table below only adds this crate's Rust variant for each code.
Wire errors round-trip into typed variants
When a registry returns an error envelope, the client maps it via
AcdpError::from_wire_error. Each canonical code becomes a specific variant;
unknown/future codes pass through as AcdpError::Registry(WireError) so a
newer registry never breaks an older client.
| Wire code | AcdpError variant |
|---|---|
invalid_signature | InvalidSignature |
hash_mismatch | RemoteHashMismatch |
data_ref_hash_mismatch | DataRefHashMismatch |
schema_violation | SchemaViolation |
not_authorized | NotAuthorized |
not_found | NotFound |
rate_limited | RateLimited { message, retry_after } (a struct variant since 0.20.0; retry_after is the parsed Retry-After header) |
payload_too_large | PayloadTooLarge |
embedded_too_large | EmbeddedTooLarge |
key_resolution_failed | KeyResolution |
key_resolution_unreachable | KeyResolutionUnreachable |
key_not_authorized | KeyNotAuthorized; KeyRevoked (0.15.0: the same wire code, raised locally when a verified revocation refuses the signing key — carries an attributed RevocationRefusal; test both with is_key_not_authorized()) |
unsupported_algorithm | UnsupportedAlgorithm |
unsupported_media_type | UnsupportedMediaType |
not_implemented | NotImplemented |
cursor_expired | CursorExpired |
invalid_cursor | InvalidCursor |
duplicate_publish | DuplicatePublish |
cross_registry_resolution_failed | CrossRegistryResolutionFailed |
invalid_receipt | InvalidReceipt |
invalid_log_proof | InvalidLogProof |
invalid_witness_cosignature | InvalidWitnessCosignature |
immutable_field | ImmutableField |
invalid_lifecycle_transition | InvalidLifecycleTransition |
internal_error | RegistryInternal |
superseded_target | SupersededTarget { reason, message } |
| (unknown) | Registry(WireError) |
This round-trip is exhaustively pinned by the
all_26_wire_codes_round_triptest incrates/acdp-primitives/src/error.rs. Adding a new code is a coordinated three-edit change — see below.
Local-only and transport variants
These variants are raised by this library itself. Most have no wire code
(a registry never sends them); RemoteHashMismatch and DataRefHashMismatch
are listed because their relationship to the local checks is easy to confuse.
| Variant | Raised when |
|---|---|
Canonicalization | JCS canonicalization failed (input not serializable). |
HashMismatch { stored, recomputed } | your locally recomputed content_hash differs from the declared one (see below). |
RemoteHashMismatch | the wire hash_mismatch: the registry rejected your publish (see below). |
DataRefHashMismatch | a DataRef's embedded or fetched bytes don't match its declared hash — raised locally by validation and fetch_and_verify_data_ref, and also the wire data_ref_hash_mismatch. |
DeadlineExceeded | a blocking facade call passed its caller-set deadline; the call is abandoned with no partial result. Transient. |
ContextIdMismatch { requested, served } | the registry served a body whose ctx_id isn't the one requested (context substitution). |
IncompleteLineage | GET /lineages/{id} came back empty, or without the member a search match named, during revocation discovery. |
SearchTruncated | a revocation-discovery search hit its page or lineage-walk safety cap with results remaining. |
RevocationDiscoveryBudgetExceeded | revocation discovery ran out of its caller-set max_requests / max_bytes budget. |
RevocationUnknown { reason, source, detail } | revocation discovery could not reach a decision under DiscoveryFailurePolicy::FailClosed (RFC-ACDP-0014 §8 unknown); reason is truncated, unanswerable, transient, or unverifiable_candidate, and source wraps the cause. Replaces 0.14's RevocationDiscoveryFailed. |
InvalidBody | a producer body could not be parsed (e.g. not a JSON object). |
MissingField | a required builder field (title, context_type, …) was not set. |
Serialization | Local JSON (de)serialization failed. A registry document that does not deserialize (not JSON, closed-shape extra field, null in a non-nullable slot) is reported as SchemaViolation ("malformed registry response: …"), per RFC-ACDP-0007 §3.3.1 and the schema-* fixtures. |
Http | a transport error (connect, timeout, redirect policy, I/O). |
Local vs. remote hash mismatches
Two distinct variants exist deliberately:
HashMismatch { stored, recomputed }— you detected it. Thecontent_hashyou recomputed locally doesn't match the one in the body. This is the tamper-detection path in the verification pipeline.RemoteHashMismatch— the registry rejected your publish withhash_mismatch. The hash you sent didn't match the body you sent.
The same split applies to signatures (local verification failure vs. a
registry's invalid_signature rejection — both map to InvalidSignature).
Supersession failures
A superseded_target wire error carries a details.reason sub-vocabulary,
decoded into SupersessionReason. Each variant is the snake_case reason
string; what each reason means is defined in the spec's
superseded_target reason codes
table.
SupersessionReason | details.reason |
|---|---|
NotFound | not_found |
LineageMismatch | lineage_mismatch |
VersionMismatch | version_mismatch |
AlreadySuperseded | already_superseded |
CrossRegistrySupersessionUnsupported | cross_registry_supersession_unsupported |
LineageWalkFailed | lineage_walk_failed |
RevocationTypeMismatch | revocation_type_mismatch — this crate's server only emits it when advertising acdp_version >= 0.5.0; below that the same rejection is SchemaViolation |
Other | any reason this library doesn't recognize (forward-compat) |
SupersessionReason is #[non_exhaustive] — match it with a wildcard arm, not
exhaustively, so a future variant addition isn't a breaking change for callers.
Most of these are prevented up front by using
supersede_body, which sets version,
supersedes, and expected_lineage_id consistently.
Retryability
AcdpError::is_transient() tells you whether retrying the same request body
(with the same Idempotency-Key, if any) is worthwhile. It returns true only
for the variants the spec marks retryable:
Transient (is_transient() == true) | Why |
|---|---|
KeyResolutionUnreachable | the DID host was temporarily unreachable (RFC-ACDP-0001 §5.11) |
RateLimited | back off and retry, never before retry_after() has elapsed (RFC-ACDP-0008 §4.3; a 0.5.0 consumer MUST honor Retry-After) |
CrossRegistryResolutionFailed | a foreign hop failed transiently (RFC-ACDP-0006 §7) |
RegistryInternal | the registry hit an internal error (HTTP 5xx) |
Http | a connect/timeout/transport error (never an SSRF-policy refusal; see the note below) |
RevocationUnknown { reason: Transient, .. } | not a wire code: only the transient reason is retryable; truncated, unanswerable, and unverifiable_candidate will not change on retry |
Everything else — InvalidSignature, SchemaViolation, HashMismatch,
KeyResolution (permanent resolution failure: a DNS-rebinding refusal while
resolving a did:web document, and also a did:key resolver fault raised by
publish-request validation, which surfaces as KeyResolution rather than
SchemaViolation), NotAuthorized, NotFound, PayloadTooLarge,
ContextIdMismatch (locally detected context substitution — RFC-ACDP-0008
§9.1; a misbehaving registry will serve the same wrong body on retry),
RevocationDiscoveryBudgetExceeded (a caller-configured discovery
request/byte budget ran out; retrying reproduces it) — is
permanent. Retrying won't help; fix the request or the key.
DNS-rebinding refusals are never
Http.SafeDnsResolverrefuses a hostname that resolves into a forbidden range at DNS time. For direct callers that refusal is permanent:KeyResolutionon theWebResolver(did:web) path, andSchemaViolationonRegistryClientandHttpsDataRefFetcher(detect it withAcdpError::is_ssrf_policy_refusal()). Sopublish_with_retryreturns it on the first attempt. The exception isCrossRegistryResolver, which reports it asCrossRegistryResolutionFailedbecause the spec mandates that code. The per-path table is in security.md.
RegistryClient::publish_with_retry(req, idempotency_key, max_attempts) uses
exactly this predicate, with bounded backoff (250 ms → 500 ms → 1 s → 2 s):
# #[cfg(feature = "client")]
# async fn run(client: &acdp::client::RegistryClient, req: &acdp::PublishRequest) -> Result<(), acdp::AcdpError> {
let resp = client.publish_with_retry(req, "publish-2026-06-10-abc", 4).await?;
# let _ = resp; Ok(()) }Handling errors
AcdpError is #[non_exhaustive]: match on the variants you care about, but
always keep a wildcard arm (here, other), or use the convenience predicates:
# fn handle(err: acdp::AcdpError) {
use acdp::AcdpError;
match &err {
AcdpError::InvalidSignature(msg) => eprintln!("untrusted context: {msg}"),
AcdpError::NotFound(_) => { /* 404 — nothing to retry */ }
e if e.is_transient() => { /* back off and retry */ }
other => eprintln!("permanent failure: {other}"),
}
# }From conversions are provided for serde_json::Error (→ Serialization),
std::io::Error (→ Http), and reqwest::Error (→ Http, prefixed
connection failed: for connect/timeout errors; → SchemaViolation for an
SSRF-policy refusal), so ? works naturally in client code. The
reqwest::Error conversion appends the error's whole source() chain to the
message. Without that, reqwest's own Display would hide the underlying
cause, such as a SafeDnsResolver SSRF refusal.
Adding a new wire error code
If you contribute a new code (per CONTRIBUTING.md), it's three coordinated edits:
- A new variant in
crates/acdp-primitives/src/error.rs::AcdpError, with the RFC citation. - A
matcharm inAcdpError::from_wire_error. - Extend the
all_26_wire_codes_round_triptest (and bump its count).
Also revisit is_transient (is the new code retryable?) and
SupersessionReason (if the code uses a details.reason sub-vocabulary).