From 873a67d0fbe2512b03c0cf75b3ea7a89d4aecb1c Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Sun, 11 Feb 2024 16:29:37 +0200 Subject: [PATCH] Replace erroneous use of set_err_kind with set_kind set_err_kind() is a method of the IntoError trait, not an Error method; it is meant to be used for any error type that can be converted into Error. Since melib::Error implements Into tautologically, this was not a compilation error. Nevertheless, the correct thing to do is use the type method directly to set ErrorKind. Signed-off-by: Manos Pitsidianakis --- meli/src/types/helpers.rs | 2 +- melib/src/gpgme/mod.rs | 8 ++++---- melib/src/imap/connection.rs | 6 +++--- melib/src/nntp/connection.rs | 4 ++-- melib/src/utils/mod.rs | 9 ++++++--- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/meli/src/types/helpers.rs b/meli/src/types/helpers.rs index 2bfd405e..d293b227 100644 --- a/meli/src/types/helpers.rs +++ b/meli/src/types/helpers.rs @@ -131,7 +131,7 @@ pub fn pipe() -> Result<(OwnedFd, OwnedFd)> { .set_source(Some( (Box::new(err) as Box).into(), )) - .set_err_kind(ErrorKind::OSError) + .set_kind(ErrorKind::OSError) }) } diff --git a/melib/src/gpgme/mod.rs b/melib/src/gpgme/mod.rs index 6d151a36..d1a0ecce 100644 --- a/melib/src/gpgme/mod.rs +++ b/melib/src/gpgme/mod.rs @@ -49,7 +49,7 @@ use crate::{ pgp::{DecryptionMetadata, Recipient}, Address, }, - error::{Error, ErrorKind, IntoError, Result, ResultIntoError}, + error::{Error, ErrorKind, Result, ResultIntoError}, }; macro_rules! call { @@ -557,7 +557,7 @@ impl Context { return Err(Error::new( "Unspecified libgpgme error: gpgme_op_verify_result returned NULL.", ) - .set_err_kind(ErrorKind::External)); + .set_kind(ErrorKind::External)); } } let io_state_lck = io_state.lock().unwrap(); @@ -914,7 +914,7 @@ impl Context { return Err(Error::new( "Unspecified libgpgme error: gpgme_op_decrypt_result returned NULL.", ) - .set_err_kind(ErrorKind::External)); + .set_kind(ErrorKind::External)); } let mut recipients = vec![]; let is_mime; @@ -1123,7 +1123,7 @@ impl Context { return Err(Error::new( "Unspecified libgpgme error: gpgme_op_encrypt_result returned NULL.", ) - .set_err_kind(ErrorKind::External)); + .set_kind(ErrorKind::External)); } /* Rewind cursor */ cipher diff --git a/melib/src/imap/connection.rs b/melib/src/imap/connection.rs index d4e0a45e..1650caae 100644 --- a/melib/src/imap/connection.rs +++ b/melib/src/imap/connection.rs @@ -368,7 +368,7 @@ impl ImapStream { "Could not connect to {}: server does not accept logins [LOGINDISABLED]", &server_conf.server_hostname )) - .set_err_kind(ErrorKind::Authentication)); + .set_kind(ErrorKind::Authentication)); } (uid_store.event_consumer)( @@ -395,7 +395,7 @@ impl ImapStream { .collect::>() .join(" ") )) - .set_err_kind(ErrorKind::Authentication)); + .set_kind(ErrorKind::Authentication)); } let xoauth2 = base64::decode(&server_conf.server_password) .chain_err_summary(|| { @@ -442,7 +442,7 @@ impl ImapStream { "Could not connect. Server replied with '{}'", String::from_utf8_lossy(l[tag_start.len()..].trim()) )) - .set_err_kind(ErrorKind::Authentication)); + .set_kind(ErrorKind::Authentication)); } should_break = true; } diff --git a/melib/src/nntp/connection.rs b/melib/src/nntp/connection.rs index 950d2d08..33e090a2 100644 --- a/melib/src/nntp/connection.rs +++ b/melib/src/nntp/connection.rs @@ -263,7 +263,7 @@ impl NntpStream { "Could not connect: no supported auth mechanisms in server capabilities: {:?}", capabilities )) - .set_err_kind(ErrorKind::Authentication)); + .set_kind(ErrorKind::Authentication)); } } @@ -335,7 +335,7 @@ impl NntpStream { || ret.starts_with("401 ") { return Err(Error::new(format!("Connection state error: {}", ret)) - .set_err_kind(ErrorKind::Authentication)); + .set_kind(ErrorKind::Authentication)); } else if !expected_reply_code.iter().any(|r| ret.starts_with(r)) { return Err(Error::new(format!("Unexpected reply code: {}", ret))); } diff --git a/melib/src/utils/mod.rs b/melib/src/utils/mod.rs index 1bc5ef14..ba66a435 100644 --- a/melib/src/utils/mod.rs +++ b/melib/src/utils/mod.rs @@ -210,16 +210,19 @@ impl std::ops::Not for SortOrder { pub mod hostname { //! Get local hostname. - use crate::error::{Error, ErrorKind, IntoError, Result}; - use crate::src_err_arc_wrap; use std::io::Read; + use crate::{ + error::{Error, ErrorKind, Result}, + src_err_arc_wrap, + }; + /// Get local hostname with the `gethostname()` libc function. pub fn hostname() -> Result { let retval = nix::unistd::gethostname().map_err(|err| { Error::new("Could not discover local hostname") .set_source(Some(src_err_arc_wrap! {err})) - .set_err_kind(ErrorKind::OSError) + .set_kind(ErrorKind::OSError) }); if retval.is_err() { let mut hostn_buf = String::with_capacity(256);