Skip to content

Commit

Permalink
refactor: add clippy unwrap lint to workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
b-zee authored and joshuef committed Jan 5, 2024
1 parent 5edac4d commit fded357
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 14 deletions.
1 change: 1 addition & 0 deletions .clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
allow-unwrap-in-tests = true
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ unused_import_braces = "warn"
uninlined_format_args = "warn"
unicode_not_nfc = "warn"
unused_async = "warn"
unwrap_used = "warn"
6 changes: 3 additions & 3 deletions sn_cli/benches/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn safe_files_upload(dir: &str) {

if !output.status.success() {
let err = output.stderr;
let err_string = String::from_utf8(err).unwrap();
let err_string = String::from_utf8(err).expect("Failed to parse error string");
panic!("Upload command executed with failing error code: {err_string:?}");
}
}
Expand All @@ -51,7 +51,7 @@ fn safe_files_download() {

if !output.status.success() {
let err = output.stderr;
let err_string = String::from_utf8(err).unwrap();
let err_string = String::from_utf8(err).expect("Failed to parse error string");
panic!("Download command executed with failing error code: {err_string:?}");
}
}
Expand Down Expand Up @@ -92,7 +92,7 @@ fn criterion_benchmark(c: &mut Criterion) {
for size in sizes.iter() {
let temp_dir = tempdir().expect("Failed to create temp dir");
let temp_dir_path = temp_dir.into_path();
let temp_dir_path_str = temp_dir_path.to_str().unwrap();
let temp_dir_path_str = temp_dir_path.to_str().expect("Invalid unicode encountered");

// create 23 random files. This is to keep the benchmark results consistent with prior runs. The change to make
// use of ChunkManager means that we don't upload the same file twice and the `uploaded_files` file is now read
Expand Down
5 changes: 2 additions & 3 deletions sn_client/src/chunks/pac_man.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,17 @@ pub(crate) fn encrypt_large(
Some(Box::new(output_dir.to_path_buf())),
)?;

let mut data_map = None;
let data_map;
loop {
match encryptor.next_encryption()? {
(None, Some(m)) => {
// Returning a data_map means file encryption is completed.
data_map = Some(m);
data_map = m;
break;
}
_ => continue,
}
}
let data_map = data_map.unwrap();
let mut encrypted_chunks: Vec<_> = data_map
.infos()
.iter()
Expand Down
2 changes: 1 addition & 1 deletion sn_client/src/files/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ impl FilesApi {
let serialized_chunk = self
.read_all(data_map, None, false, batch_size)
.await?
.unwrap();
.expect("error encountered on reading additional datamap");
chunk = rmp_serde::from_slice(&serialized_chunk)
.map_err(ChunksError::Deserialisation)?;
}
Expand Down
2 changes: 1 addition & 1 deletion sn_node/src/bin/safenode/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ fn get_root_dir_and_keypair(root_dir: &Option<PathBuf>) -> Result<(PathBuf, Keyp
/// the current process
fn start_new_node_process() {
// Retrieve the current executable's path
let current_exe = env::current_exe().unwrap();
let current_exe = env::current_exe().expect("could not get current executable path");

// Retrieve the command-line arguments passed to this process
let args: Vec<String> = env::args().collect();
Expand Down
6 changes: 3 additions & 3 deletions sn_node/src/bin/safenode/rpc_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl SafeNode for SafeNodeRpcService {
request.get_ref()
);

let state = self.running_node.get_swarm_local_state().await.unwrap();
let state = self.running_node.get_swarm_local_state().await.expect("failed to get local swarm state");
let connected_peers = state.connected_peers.iter().map(|p| p.to_bytes()).collect();
let listeners = state.listeners.iter().map(|m| m.to_string()).collect();

Expand Down Expand Up @@ -181,7 +181,7 @@ impl SafeNode for SafeNodeRpcService {
.running_node
.get_all_record_addresses()
.await
.unwrap()
.expect("failed to get record addresses")
.into_iter()
.map(|addr| addr.as_bytes())
.collect();
Expand All @@ -203,7 +203,7 @@ impl SafeNode for SafeNodeRpcService {
.running_node
.get_kbuckets()
.await
.unwrap()
.expect("failed to get k-buckets")
.into_iter()
.map(|(ilog2_distance, peers)| {
let peers = peers.into_iter().map(|peer| peer.to_bytes()).collect();
Expand Down
2 changes: 1 addition & 1 deletion sn_node/tests/verify_data_location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ fn print_node_close_groups(all_peers: &[PeerId]) {
sort_peers_by_key(&all_peers, &key, CLOSE_GROUP_SIZE).expect("failed to sort peer");
let closest_peers_idx = closest_peers
.iter()
.map(|&&peer| all_peers.iter().position(|&p| p == peer).unwrap())
.map(|&&peer| all_peers.iter().position(|&p| p == peer).expect("peer to be in iterator"))
.collect::<Vec<_>>();
println!("Close for {node_index}: {peer:?} are {closest_peers_idx:?}");
}
Expand Down
2 changes: 1 addition & 1 deletion sn_transfers/benches/reissue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// KIND, either express or implied. Please review the Licences for the specific language governing
// permissions and limitations relating to use of the SAFE Network Software.

#![allow(clippy::from_iter_instead_of_collect)]
#![allow(clippy::from_iter_instead_of_collect, clippy::unwrap_used)]

use criterion::{black_box, criterion_group, criterion_main, Criterion};
use sn_transfers::{
Expand Down
2 changes: 1 addition & 1 deletion sn_transfers/src/wallet/data_payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl PaymentQuote {
bytes.extend_from_slice(
&timestamp
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap()
.expect("Unix epoch to be in the past")
.as_secs()
.to_le_bytes(),
);
Expand Down

0 comments on commit fded357

Please sign in to comment.