{"record":{"id":"5507e82e10b20c58","repo":"linera-io/linera-protocol","slug":"cannot-forget-the-default-chain-chain-id-swit","errorCode":null,"errorMessage":"cannot forget the default chain `{chain_id}`; switch to another chain with `wallet set-default` first","messagePattern":"cannot forget the default chain `(.+?)`; switch to another chain with `wallet set-default` first","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"linera-service/src/cli/main.rs","lineNumber":2648,"sourceCode":"                    .keystore()?\n                    .contains_key(&owner)\n                    .await\n                    .expect(\"Signer error\")\n                {\n                    warn!(\"no keypair found in keystore for chain {chain_id}\");\n                }\n                info!(\n                    \"Chain keys forgotten in {} ms\",\n                    start_time.elapsed().as_millis()\n                );\n                Ok(0)\n            }\n\n            WalletCommand::ForgetChain { chain_id } => {\n                let start_time = Instant::now();\n                let wallet = options.wallet()?;\n                if wallet.default_chain() == Some(*chain_id) {\n                    anyhow::bail!(\n                        \"cannot forget the default chain `{chain_id}`; \\\n                         switch to another chain with `wallet set-default` first\"\n                    );\n                }\n                wallet\n                    .remove(*chain_id)?\n                    .ok_or_else(|| anyhow::anyhow!(\"nonexistent chain `{chain_id}`\"))?;\n                info!(\"Chain forgotten in {} ms\", start_time.elapsed().as_millis());\n                Ok(0)\n            }\n\n            WalletCommand::Init {\n                genesis_config_path,\n                faucet,\n                testing_prng_seed,\n            } => {\n                let start_time = Instant::now();\n                let genesis_config: GenesisConfig = match (genesis_config_path, faucet) {","sourceCodeStart":2630,"sourceCodeEnd":2666,"githubUrl":"https://github.com/linera-io/linera-protocol/blob/6c226ddcb332ef55118dc8d0aafbd093d5420899/linera-service/src/cli/main.rs#L2630-L2666","documentation":"`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.","triggerScenarios":"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`).","commonSituations":"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.","solutions":["Switch the default away first: `linera wallet set-default <other-chain>`, then re-run `linera wallet forget-chain <chain>`","Check which chain is default with `linera wallet show` before forgetting","In scripts, read the default from the wallet and re-point it (or skip the forget) before cleanup"],"exampleFix":"# before\nlinera wallet forget-chain e476187f6ddfeb040...   # this is the default chain -> error\n\n# after\nlinera wallet set-default ca80e5a184e6487f...\nlinera wallet forget-chain e476187f6ddfeb040...","handlingStrategy":"validation","validationCode":"// Guard before forgetting a chain.\nlet wallet = options.wallet()?;\nif wallet.default_chain() == Some(chain_id) {\n    if let Some(other) = wallet.chain_ids().iter().find(|c| **c != chain_id) {\n        wallet.set_default_chain(*other)?;\n    } else {\n        anyhow::bail!(\"cannot forget the only/default chain; nothing to switch to\");\n    }\n}\nwallet.remove(chain_id)?;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always run `linera wallet show` before destructive wallet operations to see the current default","In test teardown, re-point the default to a surviving chain (or the admin chain) before forgetting chains","Treat this bail as a safety rail: it fires only for the default chain, so fix the default first"],"tags":["wallet","chain-management","linera-cli"],"backgroundTag":"invalid-operation-state","analyzedSha":"6c226ddcb332ef55118dc8d0aafbd093d5420899","analyzedAt":"2026-08-22T22:49:09.787Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}