diff --git a/clients/socks5/src/main.rs b/clients/socks5/src/main.rs index 36161d3dcd..9153dc6e85 100644 --- a/clients/socks5/src/main.rs +++ b/clients/socks5/src/main.rs @@ -1,6 +1,8 @@ // Copyright 2021 - Nym Technologies SA // SPDX-License-Identifier: Apache-2.0 +#![allow(clippy::result_large_err)] + use std::error::Error; use clap::{crate_name, crate_version, Parser}; diff --git a/clippy.toml b/clippy.toml index 9b4ca613ab..e3fb64181f 100644 --- a/clippy.toml +++ b/clippy.toml @@ -1,3 +1,5 @@ allow-unwrap-in-tests = true allow-expect-in-tests = true -allow-panic-in-tests = true \ No newline at end of file +allow-panic-in-tests = true +large-error-threshold = 196 +enum-variant-size-threshold = 1000 diff --git a/common/config/src/legacy_helpers.rs b/common/config/src/legacy_helpers.rs index 315b6c2b49..58c938a7fe 100644 --- a/common/config/src/legacy_helpers.rs +++ b/common/config/src/legacy_helpers.rs @@ -48,8 +48,7 @@ pub mod nym_config { log::trace!("Loading from file: {:#?}", filepath.as_ref().to_owned()); let config_contents = fs::read_to_string(filepath)?; - toml::from_str(&config_contents) - .map_err(|toml_err| io::Error::new(io::ErrorKind::Other, toml_err)) + toml::from_str(&config_contents).map_err(io::Error::other) } } } diff --git a/common/config/src/lib.rs b/common/config/src/lib.rs index 42dcea8610..78d72bc7f7 100644 --- a/common/config/src/lib.rs +++ b/common/config/src/lib.rs @@ -151,8 +151,7 @@ where let content = fs::read_to_string(path)?; // TODO: should we be preserving original error type instead? - deserialize_config_from_toml_str(&content) - .map_err(|toml_err| io::Error::new(io::ErrorKind::Other, toml_err)) + deserialize_config_from_toml_str(&content).map_err(io::Error::other) } // diff --git a/common/pemstore/src/lib.rs b/common/pemstore/src/lib.rs index 9f6d3e283b..4d50a0e2fe 100644 --- a/common/pemstore/src/lib.rs +++ b/common/pemstore/src/lib.rs @@ -54,14 +54,11 @@ where let key_pem = read_pem_file(path)?; if T::pem_type() != key_pem.tag { - return Err(io::Error::new( - io::ErrorKind::Other, - format!( - "unexpected key pem tag. Got '{}', expected: '{}'", - key_pem.tag, - T::pem_type() - ), - )); + return Err(io::Error::other(format!( + "unexpected key pem tag. Got '{}', expected: '{}'", + key_pem.tag, + T::pem_type() + ))); } let key = match T::from_bytes(&key_pem.contents) { @@ -84,7 +81,7 @@ fn read_pem_file>(filepath: P) -> io::Result { let mut pem_bytes = File::open(filepath)?; let mut buf = Vec::new(); pem_bytes.read_to_end(&mut buf)?; - pem::parse(&buf).map_err(|e| io::Error::new(io::ErrorKind::Other, e)) + pem::parse(&buf).map_err(io::Error::other) } fn write_pem_file>(filepath: P, data: Vec, tag: &str) -> io::Result<()> { diff --git a/nym-api/src/main.rs b/nym-api/src/main.rs index faf39f2c14..193402b732 100644 --- a/nym-api/src/main.rs +++ b/nym-api/src/main.rs @@ -1,6 +1,7 @@ // Copyright 2020-2023 - Nym Technologies SA // SPDX-License-Identifier: GPL-3.0-only +#![allow(clippy::result_large_err)] #![warn(clippy::todo)] #![warn(clippy::dbg_macro)] diff --git a/nym-node/src/main.rs b/nym-node/src/main.rs index 04ff85bb91..dda0ece873 100644 --- a/nym-node/src/main.rs +++ b/nym-node/src/main.rs @@ -1,6 +1,7 @@ // Copyright 2024 - Nym Technologies SA // SPDX-License-Identifier: GPL-3.0-only +#![allow(clippy::result_large_err)] #![warn(clippy::expect_used)] #![warn(clippy::unwrap_used)] diff --git a/nym-validator-rewarder/src/main.rs b/nym-validator-rewarder/src/main.rs index e8945316a5..e93fc6fc97 100644 --- a/nym-validator-rewarder/src/main.rs +++ b/nym-validator-rewarder/src/main.rs @@ -1,6 +1,7 @@ // Copyright 2023-2024 - Nym Technologies SA // SPDX-License-Identifier: GPL-3.0-only +#![allow(clippy::result_large_err)] #![warn(clippy::expect_used)] #![warn(clippy::unwrap_used)] #![warn(clippy::todo)] diff --git a/nyx-chain-watcher/src/main.rs b/nyx-chain-watcher/src/main.rs index 96b531ddba..46a57b0634 100644 --- a/nyx-chain-watcher/src/main.rs +++ b/nyx-chain-watcher/src/main.rs @@ -1,3 +1,5 @@ +#![allow(clippy::result_large_err)] + use clap::{crate_name, crate_version, Parser}; use nym_bin_common::bin_info_owned; use nym_bin_common::logging::maybe_print_banner; diff --git a/sdk/rust/nym-sdk/src/mixnet/sink.rs b/sdk/rust/nym-sdk/src/mixnet/sink.rs index 5a0c1f4ab3..a3b8fd8ada 100644 --- a/sdk/rust/nym-sdk/src/mixnet/sink.rs +++ b/sdk/rust/nym-sdk/src/mixnet/sink.rs @@ -212,19 +212,18 @@ where cx: &mut Context<'_>, buf: &[u8], ) -> Poll> { - ready!(self.tx.poll_ready_unpin(cx)).map_err(|_| { - std::io::Error::new(std::io::ErrorKind::Other, "failed to send packet to mixnet") - })?; + ready!(self.tx.poll_ready_unpin(cx)) + .map_err(|_| std::io::Error::other("failed to send packet to mixnet"))?; let input_message = self .message_translator .to_input_message(buf) - .map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err))?; + .map_err(std::io::Error::other)?; // Pass it to the mixnet sender - self.tx.start_send_unpin(input_message).map_err(|_| { - std::io::Error::new(std::io::ErrorKind::Other, "failed to send packet to mixnet") - })?; + self.tx + .start_send_unpin(input_message) + .map_err(|_| std::io::Error::other("failed to send packet to mixnet"))?; Poll::Ready(Ok(buf.len())) } @@ -233,9 +232,8 @@ where mut self: Pin<&mut Self>, cx: &mut Context, ) -> Poll> { - ready!(self.tx.poll_flush_unpin(cx)).map_err(|_| { - std::io::Error::new(std::io::ErrorKind::Other, "failed to send packet to mixnet") - })?; + ready!(self.tx.poll_flush_unpin(cx)) + .map_err(|_| std::io::Error::other("failed to send packet to mixnet"))?; Poll::Ready(Ok(())) } diff --git a/tools/nymvisor/src/upgrades/types.rs b/tools/nymvisor/src/upgrades/types.rs index abeea0ed70..41322d8c36 100644 --- a/tools/nymvisor/src/upgrades/types.rs +++ b/tools/nymvisor/src/upgrades/types.rs @@ -152,7 +152,7 @@ impl UpgradePlan { let mut upgrade_plan: UpgradePlan = fs::File::open(path) .and_then(|file| { serde_json::from_reader(file) - .map_err(|serde_json_err| io::Error::new(io::ErrorKind::Other, serde_json_err)) + .map_err(io::Error::other) }) .map_err(|source| NymvisorError::UpgradePlanLoadFailure { path: path.to_path_buf(), @@ -276,7 +276,7 @@ impl UpgradeInfo { fs::File::open(path) .and_then(|file| { serde_json::from_reader(file) - .map_err(|serde_json_err| io::Error::new(io::ErrorKind::Other, serde_json_err)) + .map_err(io::Error::other) }) .map_err(|source| NymvisorError::UpgradeInfoLoadFailure { path: path.to_path_buf(), @@ -428,7 +428,7 @@ impl UpgradeHistory { let mut history: UpgradeHistory = fs::File::open(path) .and_then(|file| { serde_json::from_reader(file) - .map_err(|serde_json_err| io::Error::new(io::ErrorKind::Other, serde_json_err)) + .map_err(io::Error::other) }) .map_err(|source| NymvisorError::UpgradeHistoryLoadFailure { path: path.to_path_buf(), @@ -483,7 +483,7 @@ impl CurrentVersionInfo { fs::File::open(path) .and_then(|file| { serde_json::from_reader(file) - .map_err(|serde_json_err| io::Error::new(io::ErrorKind::Other, serde_json_err)) + .map_err(io::Error::other) }) .map_err(|source| NymvisorError::CurrentVersionInfoLoadFailure { path: path.to_path_buf(),