Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 7 additions & 17 deletions banks-client/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,21 @@ impl BanksClientError {
impl From<BanksClientError> for io::Error {
fn from(err: BanksClientError) -> Self {
match err {
BanksClientError::ClientError(err) => Self::new(io::ErrorKind::Other, err.to_string()),
BanksClientError::ClientError(err) => Self::other(err.to_string()),
BanksClientError::Io(err) => err,
BanksClientError::RpcError(err) => Self::new(io::ErrorKind::Other, err.to_string()),
BanksClientError::TransactionError(err) => {
Self::new(io::ErrorKind::Other, err.to_string())
}
BanksClientError::SimulationError { err, .. } => {
Self::new(io::ErrorKind::Other, err.to_string())
}
BanksClientError::RpcError(err) => Self::other(err.to_string()),
BanksClientError::TransactionError(err) => Self::other(err.to_string()),
BanksClientError::SimulationError { err, .. } => Self::other(err.to_string()),
}
}
}

impl From<BanksClientError> for TransportError {
fn from(err: BanksClientError) -> Self {
match err {
BanksClientError::ClientError(err) => {
Self::IoError(io::Error::new(io::ErrorKind::Other, err.to_string()))
}
BanksClientError::Io(err) => {
Self::IoError(io::Error::new(io::ErrorKind::Other, err.to_string()))
}
BanksClientError::RpcError(err) => {
Self::IoError(io::Error::new(io::ErrorKind::Other, err.to_string()))
}
BanksClientError::ClientError(err) => Self::IoError(io::Error::other(err.to_string())),
BanksClientError::Io(err) => Self::IoError(io::Error::other(err.to_string())),
BanksClientError::RpcError(err) => Self::IoError(io::Error::other(err.to_string())),
BanksClientError::TransactionError(err) => Self::TransactionError(err),
BanksClientError::SimulationError { err, .. } => Self::TransactionError(err),
}
Expand Down
42 changes: 15 additions & 27 deletions clap-utils/src/keypair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,10 @@ impl DefaultSigner {
}
})
.map_err(|_| {
std::io::Error::new(
std::io::ErrorKind::Other,
format!(
std::io::Error::other(format!(
"No default signer found, run \"solana-keygen new -o {}\" to create a new one",
self.path
),
)
))
})?;
*self.is_path_checked.borrow_mut() = true;
}
Expand Down Expand Up @@ -775,10 +772,9 @@ pub fn signer_from_path_with_config(
)?))
}
SignerSourceKind::Filepath(path) => match read_keypair_file(&path) {
Err(e) => Err(std::io::Error::new(
std::io::ErrorKind::Other,
format!("could not read keypair file \"{path}\". Run \"solana-keygen new\" to create a keypair file: {e}"),
)
Err(e) => Err(std::io::Error::other(format!(
"could not read keypair file \"{path}\". Run \"solana-keygen new\" to create a keypair file: {e}"
))
.into()),
Ok(file) => Ok(Box::new(file)),
},
Expand Down Expand Up @@ -811,8 +807,7 @@ pub fn signer_from_path_with_config(
} else if config.allow_null_signer || matches.is_present(SIGN_ONLY_ARG.name) {
Ok(Box::new(NullSigner::new(&pubkey)))
} else {
Err(std::io::Error::new(
std::io::ErrorKind::Other,
Err(std::io::Error::other(
format!("missing signature for supplied pubkey: {pubkey}"),
)
.into())
Expand Down Expand Up @@ -897,13 +892,10 @@ pub fn resolve_signer_from_path(
.map(|_| None)
}
SignerSourceKind::Filepath(path) => match read_keypair_file(&path) {
Err(e) => Err(std::io::Error::new(
std::io::ErrorKind::Other,
format!(
"could not read keypair file \"{path}\". \
Err(e) => Err(std::io::Error::other(format!(
"could not read keypair file \"{path}\". \
Run \"solana-keygen new\" to create a keypair file: {e}"
),
)
))
.into()),
Ok(_) => Ok(Some(path.to_string())),
},
Expand Down Expand Up @@ -1019,24 +1011,20 @@ pub fn keypair_from_path(
)?)
}
SignerSourceKind::Filepath(path) => match read_keypair_file(&path) {
Err(e) => Err(std::io::Error::new(
std::io::ErrorKind::Other,
format!(
"could not read keypair file \"{path}\". \
Err(e) => Err(std::io::Error::other(format!(
"could not read keypair file \"{path}\". \
Run \"solana-keygen new\" to create a keypair file: {e}"
),
)
))
.into()),
Ok(file) => Ok(file),
},
SignerSourceKind::Stdin => {
let mut stdin = std::io::stdin();
Ok(read_keypair(&mut stdin)?)
}
_ => Err(std::io::Error::new(
std::io::ErrorKind::Other,
format!("signer of type `{kind:?}` does not support Keypair output"),
)
_ => Err(std::io::Error::other(format!(
"signer of type `{kind:?}` does not support Keypair output"
))
.into()),
}
}
Expand Down
34 changes: 12 additions & 22 deletions clap-v3-utils/src/keypair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ impl DefaultSigner {
}
})
.map_err(|_| {
std::io::Error::new(
std::io::ErrorKind::Other,
std::io::Error::other(
format!(
"No default signer found, run \"solana-keygen new -o {}\" to create a new one",
self.path
Expand Down Expand Up @@ -652,8 +651,7 @@ pub fn signer_from_source_with_config(
)?))
}
SignerSourceKind::Filepath(path) => match read_keypair_file(path) {
Err(e) => Err(std::io::Error::new(
std::io::ErrorKind::Other,
Err(e) => Err(std::io::Error::other(
format!("could not read keypair file \"{path}\". Run \"solana-keygen new\" to create a keypair file: {e}"),
)
.into()),
Expand Down Expand Up @@ -689,8 +687,7 @@ pub fn signer_from_source_with_config(
} else if config.allow_null_signer || matches.try_contains_id(SIGN_ONLY_ARG.name).unwrap_or(false) {
Ok(Box::new(NullSigner::new(pubkey)))
} else {
Err(std::io::Error::new(
std::io::ErrorKind::Other,
Err(std::io::Error::other(
format!("missing signature for supplied pubkey: {pubkey}"),
)
.into())
Expand Down Expand Up @@ -794,13 +791,10 @@ pub fn resolve_signer_from_source(
.map(|_| None)
}
SignerSourceKind::Filepath(path) => match read_keypair_file(path) {
Err(e) => Err(std::io::Error::new(
std::io::ErrorKind::Other,
format!(
"could not read keypair file \"{path}\". \
Err(e) => Err(std::io::Error::other(format!(
"could not read keypair file \"{path}\". \
Run \"solana-keygen new\" to create a keypair file: {e}"
),
)
))
.into()),
Ok(_) => Ok(Some(path.to_string())),
},
Expand Down Expand Up @@ -1071,24 +1065,20 @@ fn encodable_key_from_source<K: EncodableKey + SeedDerivable>(
*legacy,
)?),
SignerSourceKind::Filepath(path) => match K::read_from_file(path) {
Err(e) => Err(std::io::Error::new(
std::io::ErrorKind::Other,
format!(
"could not read keypair file \"{path}\". \
Err(e) => Err(std::io::Error::other(format!(
"could not read keypair file \"{path}\". \
Run \"solana-keygen new\" to create a keypair file: {e}"
),
)
))
.into()),
Ok(file) => Ok(file),
},
SignerSourceKind::Stdin => {
let mut stdin = std::io::stdin();
Ok(K::read(&mut stdin)?)
}
_ => Err(std::io::Error::new(
std::io::ErrorKind::Other,
format!("signer of type `{kind:?}` does not support Keypair output"),
)
_ => Err(std::io::Error::other(format!(
"signer of type `{kind:?}` does not support Keypair output"
))
.into()),
}
}
Expand Down
8 changes: 4 additions & 4 deletions cli-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ where
P: AsRef<Path>,
{
let file = File::open(config_file)?;
let config = serde_yaml::from_reader(file)
.map_err(|err| io::Error::new(io::ErrorKind::Other, format!("{err:?}")))?;
let config =
serde_yaml::from_reader(file).map_err(|err| io::Error::other(format!("{err:?}")))?;
Ok(config)
}

Expand All @@ -105,8 +105,8 @@ where
T: serde::ser::Serialize,
P: AsRef<Path>,
{
let serialized = serde_yaml::to_string(config)
.map_err(|err| io::Error::new(io::ErrorKind::Other, format!("{err:?}")))?;
let serialized =
serde_yaml::to_string(config).map_err(|err| io::Error::other(format!("{err:?}")))?;

if let Some(outdir) = config_file.as_ref().parent() {
create_dir_all(outdir)?;
Expand Down
5 changes: 1 addition & 4 deletions cli-output/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,10 +605,7 @@ fn write_return_data<W: io::Write>(
let (data, encoding) = &return_data.data;
let raw_return_data = match encoding {
UiReturnDataEncoding::Base64 => BASE64_STANDARD.decode(data).map_err(|err| {
io::Error::new(
io::ErrorKind::Other,
format!("could not parse data as {encoding:?}: {err:?}"),
)
io::Error::other(format!("could not parse data as {encoding:?}: {err:?}"))
})?,
};
if !raw_return_data.is_empty() {
Expand Down
23 changes: 10 additions & 13 deletions core/src/consensus/tower_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ pub struct NullTowerStorage {}

impl TowerStorage for NullTowerStorage {
fn load(&self, _node_pubkey: &Pubkey) -> Result<Tower> {
Err(TowerError::IoError(io::Error::new(
io::ErrorKind::Other,
Err(TowerError::IoError(io::Error::other(
"NullTowerStorage::load() not available",
)))
}
Expand Down Expand Up @@ -278,7 +277,7 @@ impl EtcdTowerStorage {
}

fn etdc_to_tower_error(error: etcd_client::Error) -> TowerError {
TowerError::IoError(io::Error::new(io::ErrorKind::Other, error.to_string()))
TowerError::IoError(io::Error::other(error.to_string()))
}
}

Expand Down Expand Up @@ -315,10 +314,9 @@ impl TowerStorage for EtcdTowerStorage {
})?;

if !response.succeeded() {
return Err(TowerError::IoError(io::Error::new(
io::ErrorKind::Other,
format!("Lost etcd instance lock for {node_pubkey}"),
)));
return Err(TowerError::IoError(io::Error::other(format!(
"Lost etcd instance lock for {node_pubkey}"
))));
}

for op_response in response.op_responses() {
Expand All @@ -332,8 +330,7 @@ impl TowerStorage for EtcdTowerStorage {
}

// Should never happen...
Err(TowerError::IoError(io::Error::new(
io::ErrorKind::Other,
Err(TowerError::IoError(io::Error::other(
"Saved tower response missing".to_string(),
)))
}
Expand Down Expand Up @@ -363,10 +360,10 @@ impl TowerStorage for EtcdTowerStorage {
.map_err(Self::etdc_to_tower_error)?;

if !response.succeeded() {
return Err(TowerError::IoError(io::Error::new(
io::ErrorKind::Other,
format!("Lost etcd instance lock for {}", saved_tower.pubkey()),
)));
return Err(TowerError::IoError(io::Error::other(format!(
"Lost etcd instance lock for {}",
saved_tower.pubkey()
))));
}
Ok(())
}
Expand Down
7 changes: 2 additions & 5 deletions faucet/src/faucet_mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ use {
solana_pubkey::Pubkey,
solana_system_transaction::transfer,
solana_transaction::Transaction,
std::{
io::{Error, ErrorKind},
net::SocketAddr,
},
std::{io::Error, net::SocketAddr},
};

pub fn request_airdrop_transaction(
Expand All @@ -17,7 +14,7 @@ pub fn request_airdrop_transaction(
_blockhash: Hash,
) -> Result<Transaction, Error> {
if lamports == 0 {
Err(Error::new(ErrorKind::Other, "Airdrop failed"))
Err(Error::other("Airdrop failed"))
} else {
let key = Keypair::new();
let to = solana_pubkey::new_rand();
Expand Down
Loading
Loading