nautechsystems/nautilus_trader · error · anyhow::Error

Invalid chain name: {chain}

Error message

Invalid chain name: {chain}

What it means

Thrown by run_sync_dex when the --chain argument cannot be resolved to a Chain via Chain::from_chain_name. Syncing cannot proceed without a known chain; this check runs before DEX resolution and any RPC/database connection.

Source

Thrown at crates/cli/src/blockchain/sync.rs:39

    exchanges::{find_dex_type_case_insensitive, get_dex_extended, get_supported_dexes_for_chain},
    rpc::providers::check_infura_rpc_provider,
};
use nautilus_core::string::secret::mask_api_key;
use nautilus_infrastructure::sql::pg::get_postgres_connect_options;
use nautilus_model::defi::chain::Chain;

use crate::opt::DatabaseConfig;

pub(crate) async fn run_sync_dex(
    chain: String,
    dex: String,
    rpc_url: Option<String>,
    database: DatabaseConfig,
    reset: bool,
    multicall_calls_per_rpc_request: Option<u32>,
) -> anyhow::Result<()> {
    let chain = Chain::from_chain_name(&chain)
        .ok_or_else(|| anyhow::anyhow!("Invalid chain name: {chain}"))?;

    let dex_type = find_dex_type_case_insensitive(&dex, chain).ok_or_else(|| {
        let supported_dexes = get_supported_dexes_for_chain(chain.name);
        if supported_dexes.is_empty() {
            anyhow::anyhow!("Invalid DEX name '{}' (case-insensitive). Chain '{}' is not supported for pool syncing.",dex, chain.name)
        } else {
            anyhow::anyhow!("Invalid DEX name '{}' (case-insensitive). Supported DEXes for chain '{}': {}",dex,chain.name,supported_dexes.join(", "))
        }
    })?;

    // Fail before connecting to the RPC/database when the DEX cannot discover pools from
    // PoolCreated logs; without a parser sync-dex would otherwise find zero pools silently.
    let dex_extended = get_dex_extended(chain.name, &dex_type).ok_or_else(|| {
        anyhow::anyhow!(
            "DEX '{dex_type}' is not registered on chain '{}'",
            chain.name
        )
    })?;

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Use a canonical chain name recognized by Chain::from_chain_name (e.g. 'ethereum', 'base', 'arbitrum').
  2. Check CLI help or the Chain registry for the exact accepted names.
  3. Fix the spelling/casing of the --chain argument.
  4. If the chain must be supported, add it to the Chain lookup table.

Example fix

// before
nautilusctl blockchain sync-dex --chain eth --dex uniswap-v2
// after
nautilusctl blockchain sync-dex --chain ethereum --dex uniswap-v2
Defensive patterns

Strategy: validation

Validate before calling

if let None = Chain::from_chain_name(&chain_arg) {
    eprintln!("unknown chain '{}'; use a canonical name like ethereum, base, arbitrum", chain_arg);
    std::process::exit(2);
}

Prevention

When it happens

Trigger: Calling run_blockchain_command -> run_sync_dex with a chain string that is not in the Chain::from_chain_name lookup (misspelled, wrong casing if matching is case-sensitive, or an unsupported/custom chain id).

Common situations: Typing 'eth' or 'ethereum-mainnet' instead of the canonical name; using an internal alias not in the registry; typos like 'etherum'; running against a chain this build does not know.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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