linera-io/linera-protocol · warning
Keystore already exists: {}
Error message
Keystore already exists: {} What it means
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.
Source
Thrown at linera-service/src/cli/common_options.rs:137
/// Creates and saves a new wallet from the given genesis configuration.
pub fn create_wallet(&self, genesis_config: GenesisConfig) -> Result<Wallet, Error> {
let wallet_path = self.wallet_path()?;
if wallet_path.exists() {
bail!("Wallet already exists: {}", wallet_path.display());
}
let wallet = Wallet::create(&wallet_path, genesis_config)?;
wallet.save()?;
Ok(wallet)
}
/// Creates and saves a new keystore, optionally seeded for deterministic testing.
pub fn create_keystore(
&self,
testing_prng_seed: Option<u64>,
) -> Result<linera_wallet_json::Keystore, Error> {
let keystore_path = self.keystore_path()?;
if keystore_path.exists() {
bail!("Keystore already exists: {}", keystore_path.display());
}
Ok(linera_wallet_json::Keystore::create(
&keystore_path,
testing_prng_seed,
)?)
}
}
View on GitHub (pinned to 6c226ddcb3)
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.
Example fix
# before $ linera wallet create ... Error: Keystore already exists: /home/user/.config/linera/keystore.json # after (separate identity) $ linera wallet create --with-wallet testnet2 ... # or scripted guard $ test -f ~/.config/linera/keystore.json || linera wallet create ...
Defensive patterns
Strategy: validation
Validate before calling
// Before create_keystore:
if options.keystore_path()?.exists() {
// reuse via options.keystore()?, or pick a new --keystore-path / --with-wallet suffix
} Try / catch
match options.create_keystore(seed) {
Ok(k) => k,
Err(e) if e.to_string().contains("Keystore already exists") => options.keystore()?,
Err(e) => return Err(e.into()),
} Prevention
- Guard setup scripts with an existence check and reuse the existing keystore.
- Never delete keystores automatically — they hold private keys; move them aside explicitly.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Wallet already exists: {}
- Cannot apply default storage because the feature 'rocksdb' w
- cannot have both a json string and file
- Cannot process inbox for follow-only chain {chain_id}. Use `
- invalid block export configuration: {message}
AI-assisted analysis of linera-io/linera-protocol@6c226ddcb3 (2026-08-22).
Data as JSON: /api/errors/905f1708c3a5873f.
Report an issue: GitHub.