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 codeAcdpError variant
invalid_signatureInvalidSignature
hash_mismatchRemoteHashMismatch
data_ref_hash_mismatchDataRefHashMismatch
schema_violationSchemaViolation
not_authorizedNotAuthorized
not_foundNotFound
rate_limitedRateLimited { message, retry_after } (a struct variant since 0.20.0; retry_after is the parsed Retry-After header)
payload_too_largePayloadTooLarge
embedded_too_largeEmbeddedTooLarge
key_resolution_failedKeyResolution
key_resolution_unreachableKeyResolutionUnreachable
key_not_authorizedKeyNotAuthorized; 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_algorithmUnsupportedAlgorithm
unsupported_media_typeUnsupportedMediaType
not_implementedNotImplemented
cursor_expiredCursorExpired
invalid_cursorInvalidCursor
duplicate_publishDuplicatePublish
cross_registry_resolution_failedCrossRegistryResolutionFailed
invalid_receiptInvalidReceipt
invalid_log_proofInvalidLogProof
invalid_witness_cosignatureInvalidWitnessCosignature
immutable_fieldImmutableField
invalid_lifecycle_transitionInvalidLifecycleTransition
internal_errorRegistryInternal
superseded_targetSupersededTarget { reason, message }
(unknown)Registry(WireError)

This round-trip is exhaustively pinned by the all_26_wire_codes_round_trip test in crates/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.

VariantRaised when
CanonicalizationJCS canonicalization failed (input not serializable).
HashMismatch { stored, recomputed }your locally recomputed content_hash differs from the declared one (see below).
RemoteHashMismatchthe wire hash_mismatch: the registry rejected your publish (see below).
DataRefHashMismatcha 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.
DeadlineExceededa 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).
IncompleteLineageGET /lineages/{id} came back empty, or without the member a search match named, during revocation discovery.
SearchTruncateda revocation-discovery search hit its page or lineage-walk safety cap with results remaining.
RevocationDiscoveryBudgetExceededrevocation 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.
InvalidBodya producer body could not be parsed (e.g. not a JSON object).
MissingFielda required builder field (title, context_type, …) was not set.
SerializationLocal 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.
Httpa transport error (connect, timeout, redirect policy, I/O).

Local vs. remote hash mismatches

Two distinct variants exist deliberately:

  • HashMismatch { stored, recomputed } — you detected it. The content_hash you 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 with hash_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.

SupersessionReasondetails.reason
NotFoundnot_found
LineageMismatchlineage_mismatch
VersionMismatchversion_mismatch
AlreadySupersededalready_superseded
CrossRegistrySupersessionUnsupportedcross_registry_supersession_unsupported
LineageWalkFailedlineage_walk_failed
RevocationTypeMismatchrevocation_type_mismatch — this crate's server only emits it when advertising acdp_version >= 0.5.0; below that the same rejection is SchemaViolation
Otherany 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
KeyResolutionUnreachablethe DID host was temporarily unreachable (RFC-ACDP-0001 §5.11)
RateLimitedback off and retry, never before retry_after() has elapsed (RFC-ACDP-0008 §4.3; a 0.5.0 consumer MUST honor Retry-After)
CrossRegistryResolutionFaileda foreign hop failed transiently (RFC-ACDP-0006 §7)
RegistryInternalthe registry hit an internal error (HTTP 5xx)
Httpa 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. SafeDnsResolver refuses a hostname that resolves into a forbidden range at DNS time. For direct callers that refusal is permanent: KeyResolution on the WebResolver (did:web) path, and SchemaViolation on RegistryClient and HttpsDataRefFetcher (detect it with AcdpError::is_ssrf_policy_refusal()). So publish_with_retry returns it on the first attempt. The exception is CrossRegistryResolver, which reports it as CrossRegistryResolutionFailed because 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:

  1. A new variant in crates/acdp-primitives/src/error.rs::AcdpError, with the RFC citation.
  2. A match arm in AcdpError::from_wire_error.
  3. Extend the all_26_wire_codes_round_trip test (and bump its count).

Also revisit is_transient (is the new code retryable?) and SupersessionReason (if the code uses a details.reason sub-vocabulary).