Skip to content

Commit

Permalink
fix missing filename in 'Unable to read keypair file' errors
Browse files Browse the repository at this point in the history
Use named placeholders in formatting

Co-authored-by: acheron <98934430+acheroncrypto@users.noreply.github.com>
  • Loading branch information
mikemaccana and acheroncrypto committed Apr 29, 2024
1 parent 81c8c55 commit b5a7577
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ The minor version will be incremented upon a breaking change and the patch versi

### Breaking

## Next release

- cli: add filename to 'Unable to read keypair file' errors. ([#2932](https://github.com/coral-xyz/anchor/pull/2932))

## [0.30.0] - 2024-04-15

### Features
Expand Down
6 changes: 3 additions & 3 deletions cli/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::is_hidden;
use crate::{get_keypair, is_hidden};
use anchor_client::Cluster;
use anchor_lang_idl::types::Idl;
use anyhow::{anyhow, bail, Context, Error, Result};
Expand Down Expand Up @@ -531,7 +531,7 @@ impl Config {
}

pub fn wallet_kp(&self) -> Result<Keypair> {
solana_sdk::signature::read_keypair_file(&self.provider.wallet.to_string())
get_keypair(&self.provider.wallet.to_string())
.map_err(|_| anyhow!("Unable to read keypair file"))
}
}
Expand Down Expand Up @@ -1265,7 +1265,7 @@ impl Program {

pub fn keypair(&self) -> Result<Keypair> {
let file = self.keypair_file()?;
solana_sdk::signature::read_keypair_file(file.path())
get_keypair(&file.path().to_str().unwrap())
.map_err(|_| anyhow!("failed to read keypair for program: {}", self.lib_name))
}

Expand Down
30 changes: 12 additions & 18 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,11 @@ pub enum ClusterCommand {
List,
}

fn get_keypair(path: &str) -> Result<Keypair> {
solana_sdk::signature::read_keypair_file(&path)
.map_err(|_| anyhow!("Unable to read keypair file ({path})"))
}

pub fn entry(opts: Opts) -> Result<()> {
let restore_cbs = override_toolchain(&opts.cfg_override)?;
let result = process_command(opts);
Expand Down Expand Up @@ -2267,8 +2272,7 @@ fn idl_set_buffer(
priority_fee: Option<u64>,
) -> Result<Pubkey> {
with_workspace(cfg_override, |cfg| {
let keypair = solana_sdk::signature::read_keypair_file(&cfg.provider.wallet.to_string())
.map_err(|_| anyhow!("Unable to read keypair file"))?;
let keypair = get_keypair(&cfg.provider.wallet.to_string())?;
let url = cluster_url(cfg, &cfg.test_validator);
let client = create_client(url);

Expand Down Expand Up @@ -2386,8 +2390,7 @@ fn idl_set_authority(
None => IdlAccount::address(&program_id),
Some(addr) => addr,
};
let keypair = solana_sdk::signature::read_keypair_file(&cfg.provider.wallet.to_string())
.map_err(|_| anyhow!("Unable to read keypair file"))?;
let keypair = get_keypair(&cfg.provider.wallet.to_string())?;
let url = cluster_url(cfg, &cfg.test_validator);
let client = create_client(url);

Expand Down Expand Up @@ -2470,8 +2473,7 @@ fn idl_close_account(
print_only: bool,
priority_fee: Option<u64>,
) -> Result<()> {
let keypair = solana_sdk::signature::read_keypair_file(&cfg.provider.wallet.to_string())
.map_err(|_| anyhow!("Unable to read keypair file"))?;
let keypair = get_keypair(&cfg.provider.wallet.to_string())?;
let url = cluster_url(cfg, &cfg.test_validator);
let client = create_client(url);

Expand Down Expand Up @@ -2523,8 +2525,7 @@ fn idl_write(
priority_fee: Option<u64>,
) -> Result<()> {
// Misc.
let keypair = solana_sdk::signature::read_keypair_file(&cfg.provider.wallet.to_string())
.map_err(|_| anyhow!("Unable to read keypair file"))?;
let keypair = get_keypair(&cfg.provider.wallet.to_string())?;
let url = cluster_url(cfg, &cfg.test_validator);
let client = create_client(url);

Expand Down Expand Up @@ -3613,12 +3614,7 @@ fn deploy(
println!("Program path: {}...", binary_path);

let (program_keypair_filepath, program_id) = match &program_keypair {
Some(path) => (
path.clone(),
solana_sdk::signature::read_keypair_file(path)
.map_err(|_| anyhow!("Unable to read keypair file"))?
.pubkey(),
),
Some(path) => (path.clone(), get_keypair(path)?.pubkey()),
None => (
program.keypair_file()?.path().display().to_string(),
program.pubkey()?,
Expand Down Expand Up @@ -3707,8 +3703,7 @@ fn create_idl_account(
) -> Result<Pubkey> {
// Misc.
let idl_address = IdlAccount::address(program_id);
let keypair = solana_sdk::signature::read_keypair_file(keypair_path)
.map_err(|_| anyhow!("Unable to read keypair file"))?;
let keypair = get_keypair(&cfg.provider.wallet.to_string())?;
let url = cluster_url(cfg, &cfg.test_validator);
let client = create_client(url);
let idl_data = serialize_idl(idl)?;
Expand Down Expand Up @@ -3789,8 +3784,7 @@ fn create_idl_buffer(
idl: &Idl,
priority_fee: Option<u64>,
) -> Result<Pubkey> {
let keypair = solana_sdk::signature::read_keypair_file(keypair_path)
.map_err(|_| anyhow!("Unable to read keypair file"))?;
let keypair = get_keypair(&cfg.provider.wallet.to_string())?;
let url = cluster_url(cfg, &cfg.test_validator);
let client = create_client(url);

Expand Down

0 comments on commit b5a7577

Please sign in to comment.