diff --git a/banks-client/src/error.rs b/banks-client/src/error.rs index b4e8ce4a09a693..e3568120cf70f4 100644 --- a/banks-client/src/error.rs +++ b/banks-client/src/error.rs @@ -43,15 +43,11 @@ impl BanksClientError { impl From 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()), } } } @@ -59,15 +55,9 @@ impl From for io::Error { impl From 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), } diff --git a/clap-utils/src/keypair.rs b/clap-utils/src/keypair.rs index 19141ad34dee9d..e44015d180a9ec 100644 --- a/clap-utils/src/keypair.rs +++ b/clap-utils/src/keypair.rs @@ -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; } @@ -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)), }, @@ -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()) @@ -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())), }, @@ -1019,13 +1011,10 @@ 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), }, @@ -1033,10 +1022,9 @@ pub fn keypair_from_path( 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()), } } diff --git a/clap-v3-utils/src/keypair.rs b/clap-v3-utils/src/keypair.rs index 5c508c89e1b09d..d49c923d2d32d1 100644 --- a/clap-v3-utils/src/keypair.rs +++ b/clap-v3-utils/src/keypair.rs @@ -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 @@ -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()), @@ -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()) @@ -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())), }, @@ -1071,13 +1065,10 @@ fn encodable_key_from_source( *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), }, @@ -1085,10 +1076,9 @@ fn encodable_key_from_source( 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()), } } diff --git a/cli-config/src/lib.rs b/cli-config/src/lib.rs index 7bf3ce1943b35b..1b1db5cc0b2429 100644 --- a/cli-config/src/lib.rs +++ b/cli-config/src/lib.rs @@ -82,8 +82,8 @@ where P: AsRef, { 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) } @@ -105,8 +105,8 @@ where T: serde::ser::Serialize, P: AsRef, { - 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)?; diff --git a/cli-output/src/display.rs b/cli-output/src/display.rs index 7e33ee36002992..f0d64c3087dcab 100644 --- a/cli-output/src/display.rs +++ b/cli-output/src/display.rs @@ -605,10 +605,7 @@ fn write_return_data( 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() { diff --git a/core/src/consensus/tower_storage.rs b/core/src/consensus/tower_storage.rs index 75f7f6739ee158..4195bb00923771 100644 --- a/core/src/consensus/tower_storage.rs +++ b/core/src/consensus/tower_storage.rs @@ -123,8 +123,7 @@ pub struct NullTowerStorage {} impl TowerStorage for NullTowerStorage { fn load(&self, _node_pubkey: &Pubkey) -> Result { - Err(TowerError::IoError(io::Error::new( - io::ErrorKind::Other, + Err(TowerError::IoError(io::Error::other( "NullTowerStorage::load() not available", ))) } @@ -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())) } } @@ -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() { @@ -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(), ))) } @@ -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(()) } diff --git a/faucet/src/faucet_mock.rs b/faucet/src/faucet_mock.rs index 076aa3e16057fa..601631a4708f2c 100644 --- a/faucet/src/faucet_mock.rs +++ b/faucet/src/faucet_mock.rs @@ -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( @@ -17,7 +14,7 @@ pub fn request_airdrop_transaction( _blockhash: Hash, ) -> Result { 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(); diff --git a/genesis/src/main.rs b/genesis/src/main.rs index 518fa3f6e405dd..c20861468a8023 100644 --- a/genesis/src/main.rs +++ b/genesis/src/main.rs @@ -64,8 +64,8 @@ pub enum AccountFileFormat { fn pubkey_from_str(key_str: &str) -> Result> { Pubkey::from_str(key_str).or_else(|_| { let bytes: Vec = serde_json::from_str(key_str)?; - let keypair = Keypair::from_bytes(&bytes) - .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?; + let keypair = + Keypair::from_bytes(&bytes).map_err(|e| std::io::Error::other(e.to_string()))?; Ok(keypair.pubkey()) }) } @@ -76,21 +76,17 @@ pub fn load_genesis_accounts(file: &str, genesis_config: &mut GenesisConfig) -> let genesis_accounts: HashMap = serde_yaml::from_reader(accounts_file) - .map_err(|err| io::Error::new(io::ErrorKind::Other, format!("{err:?}")))?; + .map_err(|err| io::Error::other(format!("{err:?}")))?; for (key, account_details) in genesis_accounts { - let pubkey = pubkey_from_str(key.as_str()).map_err(|err| { - io::Error::new( - io::ErrorKind::Other, - format!("Invalid pubkey/keypair {key}: {err:?}"), - ) - })?; + let pubkey = pubkey_from_str(key.as_str()) + .map_err(|err| io::Error::other(format!("Invalid pubkey/keypair {key}: {err:?}")))?; let owner_program_id = Pubkey::from_str(account_details.owner.as_str()).map_err(|err| { - io::Error::new( - io::ErrorKind::Other, - format!("Invalid owner: {}: {:?}", account_details.owner, err), - ) + io::Error::other(format!( + "Invalid owner: {}: {:?}", + account_details.owner, err + )) })?; let mut account = AccountSharedData::new(account_details.balance, 0, &owner_program_id); @@ -99,10 +95,10 @@ pub fn load_genesis_accounts(file: &str, genesis_config: &mut GenesisConfig) -> &BASE64_STANDARD .decode(account_details.data.as_str()) .map_err(|err| { - io::Error::new( - io::ErrorKind::Other, - format!("Invalid account data: {}: {:?}", account_details.data, err), - ) + io::Error::other(format!( + "Invalid account data: {}: {:?}", + account_details.data, err + )) })?, ); } @@ -123,37 +119,28 @@ pub fn load_validator_accounts( let accounts_file = File::open(file)?; let validator_genesis_accounts: Vec = serde_yaml::from_reader::<_, ValidatorAccountsFile>(accounts_file) - .map_err(|err| io::Error::new(io::ErrorKind::Other, format!("{err:?}")))? + .map_err(|err| io::Error::other(format!("{err:?}")))? .validator_accounts; for account_details in validator_genesis_accounts { let pubkeys = [ pubkey_from_str(account_details.identity_account.as_str()).map_err(|err| { - io::Error::new( - io::ErrorKind::Other, - format!( - "Invalid pubkey/keypair {}: {:?}", - account_details.identity_account, err - ), - ) + io::Error::other(format!( + "Invalid pubkey/keypair {}: {:?}", + account_details.identity_account, err + )) })?, pubkey_from_str(account_details.vote_account.as_str()).map_err(|err| { - io::Error::new( - io::ErrorKind::Other, - format!( - "Invalid pubkey/keypair {}: {:?}", - account_details.vote_account, err - ), - ) + io::Error::other(format!( + "Invalid pubkey/keypair {}: {:?}", + account_details.vote_account, err + )) })?, pubkey_from_str(account_details.stake_account.as_str()).map_err(|err| { - io::Error::new( - io::ErrorKind::Other, - format!( - "Invalid pubkey/keypair {}: {:?}", - account_details.stake_account, err - ), - ) + io::Error::other(format!( + "Invalid pubkey/keypair {}: {:?}", + account_details.stake_account, err + )) })?, ]; @@ -286,8 +273,7 @@ fn add_validator_accounts( fn rent_exempt_check(stake_lamports: u64, exempt: u64) -> io::Result<()> { if stake_lamports < exempt { - Err(io::Error::new( - io::ErrorKind::Other, + Err(io::Error::other( format!( "error: insufficient validator stake lamports: {stake_lamports} for rent exemption, requires {exempt}" ), diff --git a/gossip/src/gossip_service.rs b/gossip/src/gossip_service.rs index 6fd5af85510a04..f244406fb6cc9e 100644 --- a/gossip/src/gossip_service.rs +++ b/gossip/src/gossip_service.rs @@ -242,10 +242,7 @@ pub fn discover( } info!("discover failed...\n{}", spy_ref.contact_info_trace()); - Err(std::io::Error::new( - std::io::ErrorKind::Other, - "Discover failed", - )) + Err(std::io::Error::other("Discover failed")) } /// Creates a TpuClient by selecting a valid node at random diff --git a/install/src/command.rs b/install/src/command.rs index 8e2ec34892fe35..c9f21c4c9e93d5 100644 --- a/install/src/command.rs +++ b/install/src/command.rs @@ -151,7 +151,7 @@ fn download_to_temp( .map_err(|err| format!("Unable to hash {temp_file:?}: {err}"))?; if expected_sha256.is_some() && expected_sha256 != Some(&temp_file_sha256) { - return Err(io::Error::new(io::ErrorKind::Other, "Incorrect hash").into()); + return Err(io::Error::other("Incorrect hash").into()); } source.progress_bar.finish_and_clear(); diff --git a/install/src/config.rs b/install/src/config.rs index 68263d29898af4..bfc5e5665ed858 100644 --- a/install/src/config.rs +++ b/install/src/config.rs @@ -54,10 +54,9 @@ impl Config { if err_string.contains(LEGACY_FMT_LOAD_ERR) { // looks like a config written by serde_yaml <0.9.0. // let's try to upgrade it - Self::try_migrate_08(config_file) - .map_err(|_| io::Error::new(io::ErrorKind::Other, err_string)) + Self::try_migrate_08(config_file).map_err(|_| io::Error::other(err_string)) } else { - Err(io::Error::new(io::ErrorKind::Other, err_string)) + Err(io::Error::other(err_string)) } }) } @@ -68,7 +67,7 @@ impl Config { std::fs::copy(config_file, &bak_filename)?; let result = File::open(config_file).and_then(|file| { serde_yaml_08::from_reader(file) - .map_err(|err| io::Error::new(io::ErrorKind::Other, format!("{err:?}"))) + .map_err(|err| io::Error::other(format!("{err:?}"))) .and_then(|config_08: Self| { let save = config_08._save(config_file).map(|_| config_08); if save.is_ok() { @@ -97,8 +96,8 @@ impl Config { } fn _save(&self, config_file: &str) -> Result<(), io::Error> { - let serialized = serde_yaml::to_string(self) - .map_err(|err| io::Error::new(io::ErrorKind::Other, format!("{err:?}")))?; + let serialized = + serde_yaml::to_string(self).map_err(|err| io::Error::other(format!("{err:?}")))?; if let Some(outdir) = Path::new(&config_file).parent() { create_dir_all(outdir)?; diff --git a/install/src/update_manifest.rs b/install/src/update_manifest.rs index f86a2979ebebbe..c186dc5250bceb 100644 --- a/install/src/update_manifest.rs +++ b/install/src/update_manifest.rs @@ -49,7 +49,7 @@ impl SignedUpdateManifest { let mut manifest: SignedUpdateManifest = bincode::deserialize(input)?; manifest.account_pubkey = *account_pubkey; if !manifest.verify() { - Err(io::Error::new(io::ErrorKind::Other, "Manifest failed to verify").into()) + Err(io::Error::other("Manifest failed to verify").into()) } else { Ok(manifest) } diff --git a/ledger-tool/src/main.rs b/ledger-tool/src/main.rs index 996967f44fd809..c5af8ad5680077 100644 --- a/ledger-tool/src/main.rs +++ b/ledger-tool/src/main.rs @@ -139,10 +139,10 @@ fn render_dot(dot: String, output_file: &str, output_format: &str) -> io::Result let status = child.wait_with_output()?.status; if !status.success() { - return Err(io::Error::new( - io::ErrorKind::Other, - format!("dot failed with error {}", status.code().unwrap_or(-1)), - )); + return Err(io::Error::other(format!( + "dot failed with error {}", + status.code().unwrap_or(-1) + ))); } Ok(()) } diff --git a/ledger/src/blockstore.rs b/ledger/src/blockstore.rs index 4a95b5906fc19e..3fad0083dd40de 100644 --- a/ledger/src/blockstore.rs +++ b/ledger/src/blockstore.rs @@ -3312,10 +3312,7 @@ impl Blockstore { fn get_block_signatures_rev(&self, slot: Slot) -> Result> { let block = self.get_complete_block(slot, false).map_err(|err| { - BlockstoreError::Io(IoError::new( - ErrorKind::Other, - format!("Unable to get block: {err}"), - )) + BlockstoreError::Io(IoError::other(format!("Unable to get block: {err}"))) })?; Ok(block @@ -4954,10 +4951,9 @@ pub fn create_new_ledger( ); }); - return Err(BlockstoreError::Io(IoError::new( - ErrorKind::Other, - format!("Error checking to unpack genesis archive: {unpack_err}{error_messages}"), - ))); + return Err(BlockstoreError::Io(IoError::other(format!( + "Error checking to unpack genesis archive: {unpack_err}{error_messages}" + )))); } } @@ -11018,8 +11014,7 @@ pub mod tests { Ok((_entries, _num_shreds, is_full)) => { if is_full { signal_sender - .send(Err(IoError::new( - ErrorKind::Other, + .send(Err(IoError::other( "got full slot entries for dead slot", ))) .unwrap(); diff --git a/local-cluster/src/local_cluster.rs b/local-cluster/src/local_cluster.rs index 26c8989f613dd0..c8e0a112e8e5e0 100644 --- a/local-cluster/src/local_cluster.rs +++ b/local-cluster/src/local_cluster.rs @@ -60,7 +60,7 @@ use { }, std::{ collections::HashMap, - io::{Error, ErrorKind, Result}, + io::{Error, Result}, iter, net::{IpAddr, Ipv4Addr, SocketAddr}, path::{Path, PathBuf}, @@ -755,11 +755,7 @@ impl LocalCluster { warn!("Sending transaction with retries, attempt {attempt} failed"); } - Err(std::io::Error::new( - std::io::ErrorKind::Other, - "failed to confirm transaction".to_string(), - ) - .into()) + Err(std::io::Error::other("failed to confirm transaction").into()) } fn transfer_with_client( @@ -909,9 +905,9 @@ impl LocalCluster { if stake_state.delegation.voter_pubkey != vote_account_pubkey || stake_state.delegation.stake != amount { - Err(Error::new(ErrorKind::Other, "invalid stake account state")) + Err(Error::other("invalid stake account state")) } else if vote_state.node_pubkey != node_pubkey { - Err(Error::new(ErrorKind::Other, "invalid vote account state")) + Err(Error::other("invalid vote account state")) } else { info!( "node {} {:?} {:?}", @@ -921,32 +917,16 @@ impl LocalCluster { return Ok(()); } } - (None, _) => { - Err(Error::new(ErrorKind::Other, "invalid stake account data")) - } - (_, None) => { - Err(Error::new(ErrorKind::Other, "invalid vote account data")) - } + (None, _) => Err(Error::other("invalid stake account data")), + (_, None) => Err(Error::other("invalid vote account data")), } } - (None, _) => Err(Error::new( - ErrorKind::Other, - "unable to retrieve stake account data", - )), - (_, None) => Err(Error::new( - ErrorKind::Other, - "unable to retrieve vote account data", - )), + (None, _) => Err(Error::other("unable to retrieve stake account data")), + (_, None) => Err(Error::other("unable to retrieve vote account data")), } } - (Err(_), _) => Err(Error::new( - ErrorKind::Other, - "unable to retrieve stake account data", - )), - (_, Err(_)) => Err(Error::new( - ErrorKind::Other, - "unable to retrieve vote account data", - )), + (Err(_), _) => Err(Error::other("unable to retrieve stake account data")), + (_, Err(_)) => Err(Error::other("unable to retrieve vote account data")), } } @@ -971,10 +951,7 @@ impl LocalCluster { let cache = match &*self.connection_cache { ConnectionCache::Quic(cache) => cache, ConnectionCache::Udp(_) => { - return Err(Error::new( - ErrorKind::Other, - "Expected a Quic ConnectionCache. Got UDP", - )) + return Err(Error::other("Expected a Quic ConnectionCache. Got UDP")) } }; @@ -984,7 +961,7 @@ impl LocalCluster { TpuClientConfig::default(), cache.clone(), ) - .map_err(|err| Error::new(ErrorKind::Other, format!("TpuSenderError: {}", err)))?; + .map_err(|err| Error::other(format!("TpuSenderError: {}", err)))?; Ok(tpu_client) } diff --git a/net-utils/src/ip_echo_server.rs b/net-utils/src/ip_echo_server.rs index 702ed5128e2ec6..3854160aede741 100644 --- a/net-utils/src/ip_echo_server.rs +++ b/net-utils/src/ip_echo_server.rs @@ -92,18 +92,16 @@ async fn process_connection( .await??; return Ok(()); } - return Err(io::Error::new( - io::ErrorKind::Other, - format!("Bad request header: {request_header}"), - )); + return Err(io::Error::other(format!( + "Bad request header: {request_header}" + ))); } let msg = bincode::deserialize::(&data[HEADER_LENGTH..]).map_err(|err| { - io::Error::new( - io::ErrorKind::Other, - format!("Failed to deserialize IpEchoServerMessage: {err:?}"), - ) + io::Error::other(format!( + "Failed to deserialize IpEchoServerMessage: {err:?}" + )) })?; trace!("request: {:?}", msg); diff --git a/net-utils/src/lib.rs b/net-utils/src/lib.rs index b917c908452862..f7c353d8f5a646 100644 --- a/net-utils/src/lib.rs +++ b/net-utils/src/lib.rs @@ -325,10 +325,9 @@ pub fn bind_common_in_range_with_config( } } - Err(io::Error::new( - io::ErrorKind::Other, - format!("No available TCP/UDP ports in {range:?}"), - )) + Err(io::Error::other(format!( + "No available TCP/UDP ports in {range:?}" + ))) } // Find a port in the given range that is available for both TCP and UDP @@ -364,10 +363,9 @@ pub fn bind_in_range_with_config( } } - Err(io::Error::new( - io::ErrorKind::Other, - format!("No available UDP ports in {range:?}"), - )) + Err(io::Error::other(format!( + "No available UDP ports in {range:?}" + ))) } pub fn bind_with_any_port_with_config( @@ -378,10 +376,7 @@ pub fn bind_with_any_port_with_config( let addr = SocketAddr::new(ip_addr, 0); match sock.bind(&SockAddr::from(addr)) { Ok(_) => Result::Ok(sock.into()), - Err(err) => Err(io::Error::new( - io::ErrorKind::Other, - format!("No available UDP port: {err}"), - )), + Err(err) => Err(io::Error::other(format!("No available UDP port: {err}"))), } } @@ -575,8 +570,7 @@ pub fn bind_two_in_range_with_offset_and_config( sock2_config: SocketConfig, ) -> io::Result<((u16, UdpSocket), (u16, UdpSocket))> { if range.1.saturating_sub(range.0) < offset { - return Err(io::Error::new( - io::ErrorKind::Other, + return Err(io::Error::other( "range too small to find two ports with the correct offset".to_string(), )); } @@ -596,8 +590,7 @@ pub fn bind_two_in_range_with_offset_and_config( } } } - Err(io::Error::new( - io::ErrorKind::Other, + Err(io::Error::other( "couldn't find two ports with the correct offset in range".to_string(), )) } diff --git a/program-test/src/lib.rs b/program-test/src/lib.rs index e56235c291a292..0a6bb9181fca01 100644 --- a/program-test/src/lib.rs +++ b/program-test/src/lib.rs @@ -1003,15 +1003,12 @@ impl ProgramTestBanksClientExt for BanksClient { num_retries += 1; } - Err(io::Error::new( - io::ErrorKind::Other, - format!( - "Unable to get new blockhash after {}ms (retried {} times), stuck at {}", - start.elapsed().as_millis(), - num_retries, - blockhash - ), - )) + Err(io::Error::other(format!( + "Unable to get new blockhash after {}ms (retried {} times), stuck at {}", + start.elapsed().as_millis(), + num_retries, + blockhash + ))) } } diff --git a/runtime/src/bank_client.rs b/runtime/src/bank_client.rs index b702a3e7502dcf..77f560e1af2f5d 100644 --- a/runtime/src/bank_client.rs +++ b/runtime/src/bank_client.rs @@ -168,13 +168,10 @@ impl SyncClient for BankClient { break; } if now.elapsed().as_secs() > 15 { - return Err(TransportError::IoError(io::Error::new( - io::ErrorKind::Other, - format!( - "signature not found after {} seconds", - now.elapsed().as_secs() - ), - ))); + return Err(TransportError::IoError(io::Error::other(format!( + "signature not found after {} seconds", + now.elapsed().as_secs() + )))); } sleep(Duration::from_millis(250)); } @@ -191,13 +188,10 @@ impl SyncClient for BankClient { } } if now.elapsed().as_secs() > 15 { - return Err(TransportError::IoError(io::Error::new( - io::ErrorKind::Other, - format!( - "signature not found after {} seconds", - now.elapsed().as_secs() - ), - ))); + return Err(TransportError::IoError(io::Error::other(format!( + "signature not found after {} seconds", + now.elapsed().as_secs() + )))); } sleep(Duration::from_millis(250)); } @@ -239,9 +233,7 @@ impl SyncClient for BankClient { ) .ok() .and_then(|sanitized_message| self.bank.get_fee_for_message(&sanitized_message)) - .ok_or_else(|| { - TransportError::IoError(io::Error::new(io::ErrorKind::Other, "Unable calculate fee")) - }) + .ok_or_else(|| TransportError::IoError(io::Error::other("Unable calculate fee"))) } } diff --git a/storage-bigtable/src/compression.rs b/storage-bigtable/src/compression.rs index 1609cc2c534d4a..a931b707721d0b 100644 --- a/storage-bigtable/src/compression.rs +++ b/storage-bigtable/src/compression.rs @@ -28,17 +28,13 @@ fn decompress_reader<'a, R: Read + 'a>( pub fn decompress(data: &[u8]) -> Result, io::Error> { let method_size = bincode::serialized_size(&CompressionMethod::NoCompression).unwrap(); if (data.len() as u64) < method_size { - return Err(io::Error::new( - io::ErrorKind::Other, - format!("data len too small: {}", data.len()), - )); + return Err(io::Error::other(format!( + "data len too small: {}", + data.len() + ))); } - let method = bincode::deserialize(&data[..method_size as usize]).map_err(|err| { - io::Error::new( - io::ErrorKind::Other, - format!("method deserialize failed: {err}"), - ) - })?; + let method = bincode::deserialize(&data[..method_size as usize]) + .map_err(|err| io::Error::other(format!("method deserialize failed: {err}")))?; let mut reader = decompress_reader(method, &data[method_size as usize..])?; let mut uncompressed_data = vec![]; diff --git a/thin-client/src/thin_client.rs b/thin-client/src/thin_client.rs index 13bbfc77b12140..0e0f615f029eb3 100644 --- a/thin-client/src/thin_client.rs +++ b/thin-client/src/thin_client.rs @@ -250,11 +250,7 @@ where let blockhash = self.get_latest_blockhash()?; transaction.sign(keypairs, blockhash); } - Err(io::Error::new( - io::ErrorKind::Other, - format!("retry_transfer failed in {tries} retries"), - ) - .into()) + Err(io::Error::other(format!("retry_transfer failed in {tries} retries")).into()) } pub fn poll_get_balance(&self, pubkey: &Pubkey) -> TransportResult { @@ -423,10 +419,7 @@ where .rpc_client() .get_signature_status(signature) .map_err(|err| { - io::Error::new( - io::ErrorKind::Other, - format!("send_transaction failed with error {err:?}"), - ) + io::Error::other(format!("send_transaction failed with error {err:?}")) })?; Ok(status) } @@ -440,10 +433,7 @@ where .rpc_client() .get_signature_status_with_commitment(signature, commitment_config) .map_err(|err| { - io::Error::new( - io::ErrorKind::Other, - format!("send_transaction failed with error {err:?}"), - ) + io::Error::other(format!("send_transaction failed with error {err:?}")) })?; Ok(status) } @@ -460,10 +450,7 @@ where .rpc_client() .get_slot_with_commitment(commitment_config) .map_err(|err| { - io::Error::new( - io::ErrorKind::Other, - format!("send_transaction failed with error {err:?}"), - ) + io::Error::other(format!("send_transaction failed with error {err:?}")) })?; Ok(slot) } diff --git a/tpu-client-next/src/quic_networking.rs b/tpu-client-next/src/quic_networking.rs index fe5121df428e56..a9f8660d6bc58a 100644 --- a/tpu-client-next/src/quic_networking.rs +++ b/tpu-client-next/src/quic_networking.rs @@ -57,9 +57,7 @@ pub(crate) fn create_client_endpoint( } BindTarget::Socket(socket) => { let runtime = default_runtime() - .ok_or_else(|| { - std::io::Error::new(std::io::ErrorKind::Other, "no async runtime found") - }) + .ok_or_else(|| std::io::Error::other("no async runtime found")) .map_err(IoErrorWithPartialEq::from)?; Endpoint::new(EndpointConfig::default(), None, socket, runtime) .map_err(IoErrorWithPartialEq::from)? diff --git a/tpu-client/src/nonblocking/tpu_client.rs b/tpu-client/src/nonblocking/tpu_client.rs index 90e0d75c64b19a..4e87e46330e18a 100644 --- a/tpu-client/src/nonblocking/tpu_client.rs +++ b/tpu-client/src/nonblocking/tpu_client.rs @@ -458,7 +458,7 @@ where Err(if let Some(err) = last_error { err } else { - std::io::Error::new(std::io::ErrorKind::Other, "No sends attempted").into() + std::io::Error::other("No sends attempted").into() }) } else { Ok(()) @@ -502,7 +502,7 @@ where Err(if let Some(err) = last_error { err } else { - std::io::Error::new(std::io::ErrorKind::Other, "No sends attempted").into() + std::io::Error::other("No sends attempted").into() }) } else { Ok(()) diff --git a/tpu-client/src/tpu_client.rs b/tpu-client/src/tpu_client.rs index 1ad22033553c93..12fc59883ddb81 100644 --- a/tpu-client/src/tpu_client.rs +++ b/tpu-client/src/tpu_client.rs @@ -136,7 +136,7 @@ where if let Some(err) = last_error { Err(err) } else if !some_success { - Err(std::io::Error::new(std::io::ErrorKind::Other, "No sends attempted").into()) + Err(std::io::Error::other("No sends attempted").into()) } else { Ok(()) } diff --git a/zk-sdk/src/encryption/elgamal.rs b/zk-sdk/src/encryption/elgamal.rs index d36d12c66184c8..d68613d020a8d5 100644 --- a/zk-sdk/src/encryption/elgamal.rs +++ b/zk-sdk/src/encryption/elgamal.rs @@ -225,9 +225,9 @@ impl ElGamalKeypair { /// Reads a JSON-encoded keypair from a `Reader` implementor pub fn read_json(reader: &mut R) -> Result> { let bytes: Vec = serde_json::from_reader(reader)?; - Self::try_from(bytes.as_slice()).ok().ok_or_else(|| { - std::io::Error::new(std::io::ErrorKind::Other, "Invalid ElGamalKeypair").into() - }) + Self::try_from(bytes.as_slice()) + .ok() + .ok_or_else(|| std::io::Error::other("Invalid ElGamalKeypair").into()) } /// Reads keypair from a file @@ -389,9 +389,9 @@ impl ElGamalPubkey { impl EncodableKey for ElGamalPubkey { fn read(reader: &mut R) -> Result> { let bytes: Vec = serde_json::from_reader(reader)?; - Self::try_from(bytes.as_slice()).ok().ok_or_else(|| { - std::io::Error::new(std::io::ErrorKind::Other, "Invalid ElGamalPubkey").into() - }) + Self::try_from(bytes.as_slice()) + .ok() + .ok_or_else(|| std::io::Error::other("Invalid ElGamalPubkey").into()) } fn write(&self, writer: &mut W) -> Result> { @@ -546,9 +546,9 @@ impl ElGamalSecretKey { impl EncodableKey for ElGamalSecretKey { fn read(reader: &mut R) -> Result> { let bytes: Vec = serde_json::from_reader(reader)?; - Self::try_from(bytes.as_slice()).ok().ok_or_else(|| { - std::io::Error::new(std::io::ErrorKind::Other, "Invalid ElGamalSecretKey").into() - }) + Self::try_from(bytes.as_slice()) + .ok() + .ok_or_else(|| std::io::Error::other("Invalid ElGamalSecretKey").into()) } fn write(&self, writer: &mut W) -> Result> { diff --git a/zk-token-sdk/src/encryption/elgamal.rs b/zk-token-sdk/src/encryption/elgamal.rs index 5ebf8107d5a0cc..4fc4cd58e4389f 100644 --- a/zk-token-sdk/src/encryption/elgamal.rs +++ b/zk-token-sdk/src/encryption/elgamal.rs @@ -244,9 +244,9 @@ impl ElGamalKeypair { /// Reads a JSON-encoded keypair from a `Reader` implementor pub fn read_json(reader: &mut R) -> Result> { let bytes: Vec = serde_json::from_reader(reader)?; - Self::try_from(bytes.as_slice()).ok().ok_or_else(|| { - std::io::Error::new(std::io::ErrorKind::Other, "Invalid ElGamalKeypair").into() - }) + Self::try_from(bytes.as_slice()) + .ok() + .ok_or_else(|| std::io::Error::other("Invalid ElGamalKeypair").into()) } /// Reads keypair from a file @@ -409,9 +409,9 @@ impl ElGamalPubkey { impl EncodableKey for ElGamalPubkey { fn read(reader: &mut R) -> Result> { let bytes: Vec = serde_json::from_reader(reader)?; - Self::try_from(bytes.as_slice()).ok().ok_or_else(|| { - std::io::Error::new(std::io::ErrorKind::Other, "Invalid ElGamalPubkey").into() - }) + Self::try_from(bytes.as_slice()) + .ok() + .ok_or_else(|| std::io::Error::other("Invalid ElGamalPubkey").into()) } fn write(&self, writer: &mut W) -> Result> { @@ -566,9 +566,9 @@ impl ElGamalSecretKey { impl EncodableKey for ElGamalSecretKey { fn read(reader: &mut R) -> Result> { let bytes: Vec = serde_json::from_reader(reader)?; - Self::try_from(bytes.as_slice()).ok().ok_or_else(|| { - std::io::Error::new(std::io::ErrorKind::Other, "Invalid ElGamalSecretKey").into() - }) + Self::try_from(bytes.as_slice()) + .ok() + .ok_or_else(|| std::io::Error::other("Invalid ElGamalSecretKey").into()) } fn write(&self, writer: &mut W) -> Result> {