{"record":{"id":"905f1708c3a5873f","repo":"linera-io/linera-protocol","slug":"keystore-already-exists","errorCode":null,"errorMessage":"Keystore already exists: {}","messagePattern":"Keystore already exists: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"linera-service/src/cli/common_options.rs","lineNumber":137,"sourceCode":"    /// 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,\n        )?)\n    }\n}\n","sourceCodeStart":119,"sourceCodeEnd":145,"githubUrl":"https://github.com/linera-io/linera-protocol/blob/6c226ddcb332ef55118dc8d0aafbd093d5420899/linera-service/src/cli/common_options.rs#L119-L145","documentation":"create_keystore() refuses to overwrite an existing keystore file at the resolved path (from --keystore-path or the default honoring env vars and the --with-wallet suffix). The keystore holds the wallet's private keys, so creation is deliberately blocked when the file exists to prevent destroying keys.","triggerScenarios":"Running a command that initializes the keystore (wallet/project creation flows) after one already exists at the same path; leftover keystore from a previous network or test run; LINERA_KEYSTORE pointing at an existing file.","commonSituations":"Re-running setup tooling on a non-clean environment; parallel processes using the same HOME; switching between wallets without the --with-wallet suffix so both resolve the same keystore path.","solutions":["If the existing keystore is valid for your setup, reuse it instead of creating a new one.","Create the new keystore under a distinct identity: --with-wallet NAME (suffixed paths) or --keystore-path <new-path>.","If truly starting over: back up and remove the file at the printed path first (it holds private keys).","In scripts, check for the keystore's existence and skip creation when present."],"exampleFix":"# before\n$ linera wallet create ...\nError: Keystore already exists: /home/user/.config/linera/keystore.json\n\n# after (separate identity)\n$ linera wallet create --with-wallet testnet2 ...\n# or scripted guard\n$ test -f ~/.config/linera/keystore.json || linera wallet create ...","handlingStrategy":"validation","validationCode":"// Before create_keystore:\nif options.keystore_path()?.exists() {\n    // reuse via options.keystore()?, or pick a new --keystore-path / --with-wallet suffix\n}","typeGuard":null,"tryCatchPattern":"match options.create_keystore(seed) {\n    Ok(k) => k,\n    Err(e) if e.to_string().contains(\"Keystore already exists\") => options.keystore()?,\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Guard setup scripts with an existence check and reuse the existing keystore.","Never delete keystores automatically — they hold private keys; move them aside explicitly."],"tags":["linera-service","cli","keystore","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"}