diff --git a/.github/workflows/ci-contracts.yml b/.github/workflows/ci-contracts.yml index 2814fd0a26e..35a4fb4f15c 100644 --- a/.github/workflows/ci-contracts.yml +++ b/.github/workflows/ci-contracts.yml @@ -20,6 +20,7 @@ jobs: runs-on: ubuntu-22.04 env: CARGO_TERM_COLOR: always + RUSTUP_PERMIT_COPY_RENAME: 1 steps: - uses: actions/checkout@v4 @@ -27,7 +28,8 @@ jobs: uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: stable + # pinned due to issues building contracts + toolchain: 1.86.0 target: wasm32-unknown-unknown override: true components: rustfmt, clippy diff --git a/clients/socks5/src/main.rs b/clients/socks5/src/main.rs index 36161d3dcdf..9153dc6e850 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 9b4ca613ab6..e3fb64181f4 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 315b6c2b491..58c938a7fe0 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 42dcea8610f..78d72bc7f79 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 9f6d3e283b5..4d50a0e2fe1 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/common/wasm/utils/src/websocket/mod.rs b/common/wasm/utils/src/websocket/mod.rs index be95a8bf124..902042738d4 100644 --- a/common/wasm/utils/src/websocket/mod.rs +++ b/common/wasm/utils/src/websocket/mod.rs @@ -25,10 +25,8 @@ fn map_ws_error(err: WebSocketError) -> WsError { // TODO: are we preserving correct semantics? WebSocketError::ConnectionError => WsError::ConnectionClosed, WebSocketError::ConnectionClose(_event) => WsError::ConnectionClosed, - WebSocketError::MessageSendError(err) => { - WsError::Io(io::Error::new(io::ErrorKind::Other, err.to_string())) - } - _ => WsError::Io(io::Error::new(io::ErrorKind::Other, "new websocket error")), + WebSocketError::MessageSendError(err) => WsError::Io(io::Error::other(err.to_string())), + _ => WsError::Io(io::Error::other("new websocket error")), } } diff --git a/nym-api/src/main.rs b/nym-api/src/main.rs index faf39f2c14e..193402b7320 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 04ff85bb917..dda0ece873b 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 e8945316a5d..e93fc6fc976 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/nym-wallet/src-tauri/src/config/mod.rs b/nym-wallet/src-tauri/src/config/mod.rs index 418e07eda9e..1dacb1e9a70 100644 --- a/nym-wallet/src-tauri/src/config/mod.rs +++ b/nym-wallet/src-tauri/src/config/mod.rs @@ -142,7 +142,7 @@ impl Config { let location = Self::config_file_path(None); match toml::to_string_pretty(&global) - .map_err(|toml_err| io::Error::new(io::ErrorKind::Other, toml_err)) + .map_err(io::Error::other) .map(|toml| fs::write(location.clone(), toml)) { Ok(_) => log::debug!("Writing to: {:#?}", location), @@ -162,7 +162,7 @@ impl Config { let location = Self::config_file_path(Some(network)); match toml::to_string_pretty(config) - .map_err(|toml_err| io::Error::new(io::ErrorKind::Other, toml_err)) + .map_err(io::Error::other) .map(|toml| fs::write(location.clone(), toml)) { Ok(_) => log::debug!("Writing to: {:#?}", location), @@ -367,10 +367,8 @@ fn load_from_file(file: PathBuf) -> Result where T: DeserializeOwned, { - fs::read_to_string(file).and_then(|contents| { - toml::from_str::(&contents) - .map_err(|toml_err| io::Error::new(io::ErrorKind::Other, toml_err)) - }) + fs::read_to_string(file) + .and_then(|contents| toml::from_str::(&contents).map_err(io::Error::other)) } #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)] diff --git a/nyx-chain-watcher/src/main.rs b/nyx-chain-watcher/src/main.rs index 96b531ddba1..46a57b06346 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/examples/libp2p_shared/substream.rs b/sdk/rust/nym-sdk/examples/libp2p_shared/substream.rs index f7620a835c3..e2cd9d7c3e3 100644 --- a/sdk/rust/nym-sdk/examples/libp2p_shared/substream.rs +++ b/sdk/rust/nym-sdk/examples/libp2p_shared/substream.rs @@ -68,7 +68,7 @@ impl Substream { } fn check_closed(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Result<(), IoError> { - let closed_err = IoError::new(ErrorKind::Other, "stream closed"); + let closed_err = IoError::other("stream closed"); // close_rx will return an error if the channel is closed (ie. sender was dropped), // or if it's empty @@ -172,12 +172,7 @@ impl AsyncWrite for Substream { ), }), }) - .map_err(|e| { - IoError::new( - ErrorKind::Other, - format!("poll_write outbound_tx error: {}", e), - ) - })?; + .map_err(|e| IoError::other(format!("poll_write outbound_tx error: {}", e)))?; Poll::Ready(Ok(buf.len())) } @@ -195,7 +190,7 @@ impl AsyncWrite for Substream { let mut closed = self.closed.lock(); if *closed { - return Poll::Ready(Err(IoError::new(ErrorKind::Other, "stream closed"))); + return Poll::Ready(Err(IoError::other("stream closed"))); } *closed = true; @@ -210,12 +205,7 @@ impl AsyncWrite for Substream { message: SubstreamMessage::new_close(self.substream_id.clone()), }), }) - .map_err(|e| { - IoError::new( - ErrorKind::Other, - format!("poll_close outbound_rx error: {}", e), - ) - })?; + .map_err(|e| IoError::other(format!("poll_close outbound_rx error: {}", e)))?; Poll::Ready(Ok(())) } diff --git a/sdk/rust/nym-sdk/src/mixnet/sink.rs b/sdk/rust/nym-sdk/src/mixnet/sink.rs index 5a0c1f4ab3b..a3b8fd8adab 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 abeea0ed701..50b997be806 100644 --- a/tools/nymvisor/src/upgrades/types.rs +++ b/tools/nymvisor/src/upgrades/types.rs @@ -150,10 +150,7 @@ impl UpgradePlan { pub(crate) fn try_load>(path: P) -> Result { let path = path.as_ref(); 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)) - }) + .and_then(|file| serde_json::from_reader(file).map_err(io::Error::other)) .map_err(|source| NymvisorError::UpgradePlanLoadFailure { path: path.to_path_buf(), source, @@ -274,10 +271,7 @@ impl UpgradeInfo { pub(crate) fn try_load>(path: P) -> Result { let path = path.as_ref(); 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)) - }) + .and_then(|file| serde_json::from_reader(file).map_err(io::Error::other)) .map_err(|source| NymvisorError::UpgradeInfoLoadFailure { path: path.to_path_buf(), source, @@ -426,10 +420,7 @@ impl UpgradeHistory { pub(crate) fn try_load>(path: P) -> Result { let path = path.as_ref(); 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)) - }) + .and_then(|file| serde_json::from_reader(file).map_err(io::Error::other)) .map_err(|source| NymvisorError::UpgradeHistoryLoadFailure { path: path.to_path_buf(), source, @@ -481,10 +472,7 @@ impl CurrentVersionInfo { pub(crate) fn try_load>(path: P) -> Result { let path = path.as_ref(); 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)) - }) + .and_then(|file| serde_json::from_reader(file).map_err(io::Error::other)) .map_err(|source| NymvisorError::CurrentVersionInfoLoadFailure { path: path.to_path_buf(), source,