{"record":{"id":"92dbd8e72d4c1917","repo":"linera-io/linera-protocol","slug":"wallet-already-exists","errorCode":null,"errorMessage":"Wallet already exists: {}","messagePattern":"Wallet already exists: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"linera-service/src/cli/common_options.rs","lineNumber":123,"sourceCode":"    pub fn keystore_path(&self) -> Result<PathBuf, Error> {\n        linera_wallet_json::paths::keystore_path(self.keystore_path.as_ref(), &self.suffix())\n    }\n\n    /// Reads and returns the wallet.\n    pub fn wallet(&self) -> Result<Wallet, Error> {\n        Ok(Wallet::read(&self.wallet_path()?)?)\n    }\n\n    /// Reads and returns the keystore.\n    pub fn keystore(&self) -> Result<linera_wallet_json::Keystore, Error> {\n        Ok(linera_wallet_json::Keystore::read(&self.keystore_path()?)?)\n    }\n\n    /// Creates and saves a new wallet from the given genesis configuration.\n    pub fn create_wallet(&self, genesis_config: GenesisConfig) -> Result<Wallet, Error> {\n        let wallet_path = self.wallet_path()?;\n        if wallet_path.exists() {\n            bail!(\"Wallet already exists: {}\", wallet_path.display());\n        }\n        let wallet = Wallet::create(&wallet_path, genesis_config)?;\n        wallet.save()?;\n        Ok(wallet)\n    }\n\n    /// Creates and saves a new keystore, optionally seeded for deterministic testing.\n    pub fn create_keystore(\n        &self,\n        testing_prng_seed: Option<u64>,\n    ) -> Result<linera_wallet_json::Keystore, Error> {\n        let keystore_path = self.keystore_path()?;\n        if keystore_path.exists() {\n            bail!(\"Keystore already exists: {}\", keystore_path.display());\n        }\n        Ok(linera_wallet_json::Keystore::create(\n            &keystore_path,\n            testing_prng_seed,","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/linera-io/linera-protocol/blob/6c226ddcb332ef55118dc8d0aafbd093d5420899/linera-service/src/cli/common_options.rs#L105-L141","documentation":"create_wallet() refuses to overwrite: the wallet file at the resolved path (from --wallet-state-path, or the default location honoring LINERA_WALLET / wallet suffix via --with-wallet) already exists on disk. This is a guard against clobbering an existing wallet's keys and chain state during genesis creation (e.g. 'linera wallet create' / project create).","triggerScenarios":"Running a create/genesis command twice; the default wallet path already holding a wallet from an earlier run or another network; LINERA_WALLET env var pointing at an existing file; a leftover wallet in a shared container/home directory.","commonSituations":"Re-running setup scripts that assume a clean machine; switching networks (devnet to testnet) without moving the old wallet; container images that persist $HOME between runs.","solutions":["If you intended a fresh wallet: back up and remove/rename the existing file at the printed path (it contains your keys — do not delete blindly).","Use a separate wallet via --with-wallet NAME, which resolves a suffixed wallet path (and LINERA_WALLET_NAME env), keeping both.","Or point creation at another location with --wallet-state-path <new-path>.","If the existing wallet is the one you want, skip creation and just use it."],"exampleFix":"# before\n$ linera wallet create --genesis genesis.json\nError: Wallet already exists: /home/user/.config/linera/wallet.json\n\n# after (keep both)\n$ linera wallet create --with-wallet testnet2 --genesis genesis.json\n# or start over (keys are lost!)\n$ mv ~/.config/linera/wallet.json ~/.config/linera/wallet.json.bak && linera wallet create --genesis genesis.json","handlingStrategy":"validation","validationCode":"// Before create_wallet:\nlet path = options.wallet_path()?;\nif path.exists() {\n    // decide: reuse it, or target a different wallet via --with-wallet / --wallet-state-path\n    anyhow::bail!(\"refusing to overwrite existing wallet at {}\", path.display());\n}","typeGuard":null,"tryCatchPattern":"match options.create_wallet(genesis) {\n    Ok(w) => w,\n    Err(e) if e.to_string().contains(\"Wallet already exists\") => {\n        options.wallet()? // intended reuse path\n    }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Setup scripts should check wallet existence first and skip creation when present.","Use --with-wallet suffixes for multi-network setups instead of swapping files."],"tags":["linera-service","cli","wallet","file-exists","configuration","rust"],"backgroundTag":"file-already-exists","analyzedSha":"6c226ddcb332ef55118dc8d0aafbd093d5420899","analyzedAt":"2026-08-22T22:49:09.787Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}