{"record":{"id":"dd7a57bfc6e7e3f5","repo":"linera-io/linera-protocol","slug":"nonexistent-chain-chain-id-dd7a57","errorCode":null,"errorMessage":"nonexistent chain `{chain_id}`","messagePattern":"nonexistent chain `(.+?)`","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"linera-wallet-json/src/wallet.rs","lineNumber":199,"sourceCode":"    }\n\n    /// Applies a mutation to the chain with the given ID, saving afterwards. Returns `None`\n    /// if the chain is not in the wallet.\n    pub fn mutate<R>(\n        &self,\n        chain_id: ChainId,\n        mutate: impl Fn(&mut Chain) -> R,\n    ) -> Option<Result<R, persistent::file::Error>> {\n        self.0\n            .chains\n            .mutate(chain_id, mutate)\n            .map(|outcome| self.0.save().map(|()| outcome))\n    }\n\n    /// Removes and returns the owner of the given chain, erroring if the chain or owner is absent.\n    pub fn forget_keys(&self, chain_id: ChainId) -> anyhow::Result<AccountOwner> {\n        self.mutate(chain_id, |chain| chain.owner.take())\n            .ok_or_else(|| anyhow::anyhow!(\"nonexistent chain `{chain_id}`\"))??\n            .ok_or_else(|| anyhow::anyhow!(\"keypair not found for chain `{chain_id}`\"))\n    }\n\n    /// Writes the wallet to its file.\n    pub fn save(&self) -> Result<(), persistent::file::Error> {\n        self.0.save()\n    }\n\n    /// Returns the number of chains in the wallet.\n    pub fn num_chains(&self) -> usize {\n        self.0.chains.items().len()\n    }\n\n    /// Returns the IDs of all chains in the wallet.\n    pub fn chain_ids(&self) -> Vec<ChainId> {\n        self.0.chains.chain_ids()\n    }\n","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/linera-io/linera-protocol/blob/6c226ddcb332ef55118dc8d0aafbd093d5420899/linera-wallet-json/src/wallet.rs#L181-L217","documentation":"WalletState::forget_keys calls mutate(chain_id, ...), which returns None when the chain_id key is absent from the wallet's chain map. The outer ok_or_else converts that None into this anyhow error, meaning the wallet file has no entry for the given ChainId at all.","triggerScenarios":"Calling wallet.forget_keys(chain_id) with a chain ID that was never added, was already forgotten, belongs to a different wallet file, or was mistyped/truncated on the CLI.","commonSituations":"Running linera wallet forget-keys after the chain was removed by a previous operation; pointing LINERA_WALLET at the wrong wallet.json; passing a testnet chain ID to a devnet wallet; copy-paste error in the 64-hex-character chain ID.","solutions":["List the chains actually present: linera wallet show (or wallet.chain_ids()) and confirm the target ID","Verify you are using the right wallet file: check --wallet path / LINERA_WALLET and the chain's network (devnet vs testnet)","Re-add the chain before forgetting (linera wallet add-chain ...) if keys were removed earlier","Double-check the full ChainId string for typos or missing characters"],"exampleFix":"// before\nlet owner = wallet.forget_keys(chain_id)?; // chain never added -> error\n\n// after\nif !wallet.chain_ids().contains(&chain_id) {\n    anyhow::bail!(\"chain {chain_id} not in this wallet; available: {:?}\", wallet.chain_ids());\n}\nlet owner = wallet.forget_keys(chain_id)?;","handlingStrategy":"validation","validationCode":"// Check membership before mutating\nlet ids = wallet.chain_ids();\nif !ids.contains(&chain_id) {\n    anyhow::bail!(\"chain {chain_id} not in wallet; have: {ids:?}\");\n}\nlet owner = wallet.forget_keys(chain_id)?;","typeGuard":null,"tryCatchPattern":"match wallet.forget_keys(chain_id) {\n    Ok(owner) => Ok(Some(owner)),\n    Err(e) if e.to_string().contains(\"nonexistent chain\") => {\n        // nothing to do; treat as no-op for idempotent scripts\n        Ok(None)\n    }\n    Err(e) => Err(e),\n}","preventionTips":["List chain_ids() before user-triggered forget operations and validate input","Confirm the wallet file and network match the chain ID being operated on","Wrap CLI flows so an unknown chain produces a usage message, not a raw error"],"tags":["linera","wallet","chain-id","not-found","rust"],"backgroundTag":"chain-not-found","analyzedSha":"6c226ddcb332ef55118dc8d0aafbd093d5420899","analyzedAt":"2026-08-22T22:49:09.787Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}