linera-io/linera-protocol · warning

cannot forget the default chain `{chain_id}`; switch to anot

Error message

cannot forget the default chain `{chain_id}`; switch to another chain with `wallet set-default` first

What it means

`linera wallet forget-chain <chain>` refuses to remove the chain that is currently the wallet's default (`wallet.default_chain() == chain_id`). Forgetting the default would leave later commands without an implicit target chain, so the destructive operation is blocked until another default is chosen.

Source

Thrown at linera-service/src/cli/main.rs:2648

                    .keystore()?
                    .contains_key(&owner)
                    .await
                    .expect("Signer error")
                {
                    warn!("no keypair found in keystore for chain {chain_id}");
                }
                info!(
                    "Chain keys forgotten in {} ms",
                    start_time.elapsed().as_millis()
                );
                Ok(0)
            }

            WalletCommand::ForgetChain { chain_id } => {
                let start_time = Instant::now();
                let wallet = options.wallet()?;
                if wallet.default_chain() == Some(*chain_id) {
                    anyhow::bail!(
                        "cannot forget the default chain `{chain_id}`; \
                         switch to another chain with `wallet set-default` first"
                    );
                }
                wallet
                    .remove(*chain_id)?
                    .ok_or_else(|| anyhow::anyhow!("nonexistent chain `{chain_id}`"))?;
                info!("Chain forgotten in {} ms", start_time.elapsed().as_millis());
                Ok(0)
            }

            WalletCommand::Init {
                genesis_config_path,
                faucet,
                testing_prng_seed,
            } => {
                let start_time = Instant::now();
                let genesis_config: GenesisConfig = match (genesis_config_path, faucet) {

View on GitHub (pinned to 6c226ddcb3)

Solutions

  1. Switch the default away first: `linera wallet set-default <other-chain>`, then re-run `linera wallet forget-chain <chain>`
  2. Check which chain is default with `linera wallet show` before forgetting
  3. In scripts, read the default from the wallet and re-point it (or skip the forget) before cleanup

Example fix

# before
linera wallet forget-chain e476187f6ddfeb040...   # this is the default chain -> error

# after
linera wallet set-default ca80e5a184e6487f...
linera wallet forget-chain e476187f6ddfeb040...
Defensive patterns

Strategy: validation

Validate before calling

// Guard before forgetting a chain.
let wallet = options.wallet()?;
if wallet.default_chain() == Some(chain_id) {
    if let Some(other) = wallet.chain_ids().iter().find(|c| **c != chain_id) {
        wallet.set_default_chain(*other)?;
    } else {
        anyhow::bail!("cannot forget the only/default chain; nothing to switch to");
    }
}
wallet.remove(chain_id)?;

Prevention

When it happens

Trigger: Calling `linera wallet forget-chain X` while X is the wallet's default chain (typically the genesis/admin chain or the last chain created with `set_default`).

Common situations: Test teardown scripts that create a chain, set it as default, then try to forget it; cleanup routines iterating all wallet chains in arbitrary order; attempting to forget the admin chain of a local net.

Related errors


AI-assisted analysis of linera-io/linera-protocol@6c226ddcb3 (2026-08-22). Data as JSON: /api/errors/5507e82e10b20c58. Report an issue: GitHub.