nautechsystems/nautilus_trader · error

Duplicate {description}

Error message

Duplicate {description}

What it means

This error comes from the ensure_distinct helper in verification.rs, which verifies that a set of string values contains no duplicates before registering provider endpoints or identifiers. The format string interpolates the human-readable description of what is being checked, so the final message reads e.g. 'Duplicate provider endpoint'. It prevents ambiguous or conflicting provider data from entering verification state.

Source

Thrown at crates/adapters/blockchain/src/rpc/verification.rs:1462

            && identity
                .failure_domain_ids
                .iter()
                .all(|domain| !domain.trim().is_empty()),
        "Provider failure domains must contain nonempty opaque IDs"
    );
    ensure_distinct(
        identity.failure_domain_ids.iter().map(String::as_str),
        "failure-domain IDs within one provider",
    )
}

fn ensure_distinct<'a>(
    values: impl IntoIterator<Item = &'a str>,
    description: &str,
) -> anyhow::Result<()> {
    let values = values.into_iter().collect::<Vec<_>>();
    let unique = values.iter().copied().collect::<HashSet<_>>();
    anyhow::ensure!(values.len() == unique.len(), "Duplicate {description}");
    Ok(())
}

fn normalize_endpoint(endpoint: &str) -> anyhow::Result<String> {
    let url = validate_execution_endpoint(endpoint, "Provider")?;
    Ok(url.to_string())
}

fn decode_simulation<T>(
    result: anyhow::Result<RpcCallResult>,
    decode: impl Fn(&[u8]) -> anyhow::Result<T>,
) -> anyhow::Result<VerifiedSimulation<T>> {
    match result? {
        RpcCallResult::Success(bytes) => decode(&bytes).map(VerifiedSimulation::Succeeded),
        RpcCallResult::Reverted => Ok(VerifiedSimulation::Denied),
    }
}

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Deduplicate the value list before passing it to the validation path (e.g. HashSet or .dedup() on a sorted Vec)
  2. Check provider config for repeated endpoints/IDs and remove the duplicates
  3. Normalize endpoints first (validate_execution_endpoint) and dedupe on the normalized form
  4. Report which value is duplicated to the user for easier config debugging

Example fix

// before
ensure_distinct(["https://a.example", "https://a.example"], "provider endpoint")?;
// after
let endpoints: Vec<&str> = raw_endpoints.iter().map(|e| e.as_str()).collect::<HashSet<_>>().into_iter().collect();
ensure_distinct(endpoints, "provider endpoint")?;
Defensive patterns

Strategy: validation

Validate before calling

let set: HashSet<&str> = values.iter().copied().collect();
if set.len() != values.len() {
    return Err(format!("duplicate values in {description}: {:?}", values));
}

Try / catch

match ensure_distinct(endpoints, "provider endpoint") {
    Err(e) => { eprintln!("config check failed: {e:#}"); dedupe_and_retry(); }
    Ok(()) => proceed(),
}

Prevention

When it happens

Trigger: Calling any code path that invokes ensure_distinct with an iterator containing two equal strings — e.g. a provider registering the same normalized endpoint twice, or repeating an ID in a list.

Common situations: Copy-pasted endpoint URLs in provider config; the same endpoint listed under multiple failure domains; config merge logic that concatenates lists without deduplication; trailing-slash/case variants that are duplicates in intent but distinct only if normalization was skipped.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/b74dc561313286ba. Report an issue: GitHub.