diff options
| author | Joakim Hulthe <joakim@hulthe.net> | 2024-02-26 14:24:15 +0100 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2024-02-27 10:38:19 +0100 |
| commit | a6d3578d256349ffe74b7c6a7a80ac2d70b7f68e (patch) | |
| tree | 92d6bfab07a4d7d8d88fce7680ffd8278c37d4ce /talpid-core/src | |
| parent | 0a4915b113263f8353663e4fc07297d2862f2bc0 (diff) | |
| download | mullvadvpn-a6d3578d256349ffe74b7c6a7a80ac2d70b7f68e.tar.xz mullvadvpn-a6d3578d256349ffe74b7c6a7a80ac2d70b7f68e.zip | |
Replace err_derive with thiserror
`err_derive` is unmaintained and will probably stop working with rust
edition 2024. `thiserror` is almost a drop-in replacement. This commit
simply replaces all occurences of `derive(err_derive::Error)` with
`derive(thiserror::Error)` and fixes the attributes, but the Error and
Display impls should be identical.
Diffstat (limited to 'talpid-core/src')
28 files changed, 268 insertions, 288 deletions
diff --git a/talpid-core/src/dns/android.rs b/talpid-core/src/dns/android.rs index 3e9e0ef81b..6f4e110d3f 100644 --- a/talpid-core/src/dns/android.rs +++ b/talpid-core/src/dns/android.rs @@ -1,8 +1,8 @@ use std::net::IpAddr; /// Stub error type for DNS errors on Android. -#[derive(Debug, err_derive::Error)] -#[error(display = "Unknown Android DNS error")] +#[derive(Debug, thiserror::Error)] +#[error("Unknown Android DNS error")] pub struct Error; pub struct DnsMonitor; diff --git a/talpid-core/src/dns/linux/mod.rs b/talpid-core/src/dns/linux/mod.rs index 38d15b4f5d..3e7f6ac0b8 100644 --- a/talpid-core/src/dns/linux/mod.rs +++ b/talpid-core/src/dns/linux/mod.rs @@ -13,26 +13,26 @@ use talpid_routing::RouteManagerHandle; pub type Result<T> = std::result::Result<T, Error>; /// Errors that can happen in the Linux DNS monitor -#[derive(err_derive::Error, Debug)] +#[derive(thiserror::Error, Debug)] pub enum Error { /// Error in systemd-resolved DNS monitor - #[error(display = "Error in systemd-resolved DNS monitor")] - SystemdResolved(#[error(source)] systemd_resolved::Error), + #[error("Error in systemd-resolved DNS monitor")] + SystemdResolved(#[from] systemd_resolved::Error), /// Error in NetworkManager DNS monitor - #[error(display = "Error in NetworkManager DNS monitor")] - NetworkManager(#[error(source)] network_manager::Error), + #[error("Error in NetworkManager DNS monitor")] + NetworkManager(#[from] network_manager::Error), /// Error in resolvconf DNS monitor - #[error(display = "Error in resolvconf DNS monitor")] - Resolvconf(#[error(source)] resolvconf::Error), + #[error("Error in resolvconf DNS monitor")] + Resolvconf(#[from] resolvconf::Error), /// Error in static /etc/resolv.conf DNS monitor - #[error(display = "Error in static /etc/resolv.conf DNS monitor")] - StaticResolvConf(#[error(source)] static_resolv_conf::Error), + #[error("Error in static /etc/resolv.conf DNS monitor")] + StaticResolvConf(#[from] static_resolv_conf::Error), /// No suitable DNS monitor implementation detected - #[error(display = "No suitable DNS monitor implementation detected")] + #[error("No suitable DNS monitor implementation detected")] NoDnsMonitor, } diff --git a/talpid-core/src/dns/linux/resolvconf.rs b/talpid-core/src/dns/linux/resolvconf.rs index 4c7c066f20..0e1ac33c30 100644 --- a/talpid-core/src/dns/linux/resolvconf.rs +++ b/talpid-core/src/dns/linux/resolvconf.rs @@ -10,27 +10,27 @@ use which::which; pub type Result<T> = std::result::Result<T, Error>; -#[derive(err_derive::Error, Debug)] +#[derive(thiserror::Error, Debug)] pub enum Error { - #[error(display = "Failed to detect 'resolvconf' program")] + #[error("Failed to detect 'resolvconf' program")] NoResolvconf, - #[error(display = "The resolvconf in PATH is just a symlink to systemd-resolved")] + #[error("The resolvconf in PATH is just a symlink to systemd-resolved")] ResolvconfUsesResolved, - #[error(display = "Failed to execute 'resolvconf' program")] - RunResolvconf(#[error(source)] io::Error), + #[error("Failed to execute 'resolvconf' program")] + RunResolvconf(#[from] io::Error), - #[error(display = "Using 'resolvconf' to add a record failed: {}", stderr)] + #[error("Using 'resolvconf' to add a record failed: {}", stderr)] AddRecord { stderr: String }, - #[error(display = "Using 'resolvconf' to delete a record failed")] + #[error("Using 'resolvconf' to delete a record failed")] DeleteRecord, - #[error(display = "Detected dnsmasq is running and misconfigured")] + #[error("Detected dnsmasq is running and misconfigured")] DnsmasqMisconfiguration, - #[error(display = "Current /etc/resolv.conf is not generated by resolvconf")] + #[error("Current /etc/resolv.conf is not generated by resolvconf")] ResolvconfNotInUse, } diff --git a/talpid-core/src/dns/linux/static_resolv_conf.rs b/talpid-core/src/dns/linux/static_resolv_conf.rs index b1f28f5f52..59c5e2fbb9 100644 --- a/talpid-core/src/dns/linux/static_resolv_conf.rs +++ b/talpid-core/src/dns/linux/static_resolv_conf.rs @@ -11,22 +11,22 @@ const RESOLV_CONF_PATH: &str = "/etc/resolv.conf"; pub type Result<T> = std::result::Result<T, Error>; -#[derive(err_derive::Error, Debug)] +#[derive(thiserror::Error, Debug)] pub enum Error { - #[error(display = "Failed to watch /etc/resolv.conf for changes")] - WatchResolvConf(#[error(source)] std::io::Error), + #[error("Failed to watch /etc/resolv.conf for changes")] + WatchResolvConf(#[source] std::io::Error), - #[error(display = "Failed to write to {}", _0)] - WriteResolvConf(&'static str, #[error(source)] io::Error), + #[error("Failed to write to {0}")] + WriteResolvConf(&'static str, #[source] io::Error), - #[error(display = "Failed to read from {}", _0)] - ReadResolvConf(&'static str, #[error(source)] io::Error), + #[error("Failed to read from {0}")] + ReadResolvConf(&'static str, #[source] io::Error), - #[error(display = "resolv.conf at {} could not be parsed", _0)] - Parse(&'static str, #[error(source)] resolv_conf::ParseError), + #[error("resolv.conf at {0} could not be parsed")] + Parse(&'static str, #[source] resolv_conf::ParseError), - #[error(display = "Failed to remove stale resolv.conf backup at {}", _0)] - RemoveBackup(&'static str, #[error(source)] io::Error), + #[error("Failed to remove stale resolv.conf backup at {0}")] + RemoveBackup(&'static str, #[source] io::Error), } pub struct StaticResolvConf { diff --git a/talpid-core/src/dns/linux/systemd_resolved.rs b/talpid-core/src/dns/linux/systemd_resolved.rs index 7094a5f28b..5e0e4a8409 100644 --- a/talpid-core/src/dns/linux/systemd_resolved.rs +++ b/talpid-core/src/dns/linux/systemd_resolved.rs @@ -8,13 +8,13 @@ pub(crate) use talpid_dbus::systemd_resolved::Error as SystemdDbusError; pub type Result<T> = std::result::Result<T, Error>; -#[derive(err_derive::Error, Debug)] +#[derive(thiserror::Error, Debug)] pub enum Error { - #[error(display = "systemd-resolved operation failed")] - SystemdResolvedError(#[error(source)] SystemdDbusError), + #[error("systemd-resolved operation failed")] + SystemdResolvedError(#[from] SystemdDbusError), - #[error(display = "Failed to resolve interface index with error {}", _0)] - InterfaceNameError(#[error(source)] IfaceIndexLookupError), + #[error("Failed to resolve interface index with error {0}")] + InterfaceNameError(#[from] IfaceIndexLookupError), } pub struct SystemdResolved { diff --git a/talpid-core/src/dns/macos.rs b/talpid-core/src/dns/macos.rs index 39bce1c094..c68165737f 100644 --- a/talpid-core/src/dns/macos.rs +++ b/talpid-core/src/dns/macos.rs @@ -28,30 +28,30 @@ use crate::tunnel_state_machine::TunnelCommand; pub type Result<T> = std::result::Result<T, Error>; /// Errors that can happen when setting/monitoring DNS on macOS. -#[derive(err_derive::Error, Debug)] +#[derive(thiserror::Error, Debug)] pub enum Error { /// Error while setting DNS servers - #[error(display = "Error while setting DNS servers")] + #[error("Error while setting DNS servers")] SettingDnsFailed, /// Failed to initialize dynamic store - #[error(display = "Failed to initialize dynamic store")] + #[error("Failed to initialize dynamic store")] DynamicStoreInitError, /// Failed to parse IP address from config string - #[error(display = "Failed to parse an IP address from a config string")] + #[error("Failed to parse an IP address from a config string")] AddrParseError(String, String, AddrParseError), /// Failed to obtain name for interface - #[error(display = "Failed to obtain interface name")] + #[error("Failed to obtain interface name")] GetInterfaceNameError, /// Failed to load interface config - #[error(display = "Failed to load interface config at path {}", _0)] + #[error("Failed to load interface config at path {0}")] LoadInterfaceConfigError(String), /// Failed to load DNS config - #[error(display = "Failed to load DNS config at path {}", _0)] + #[error("Failed to load DNS config at path {0}")] LoadDnsConfigError(String), } diff --git a/talpid-core/src/dns/windows/dnsapi.rs b/talpid-core/src/dns/windows/dnsapi.rs index b9458a70b9..cd7731119b 100644 --- a/talpid-core/src/dns/windows/dnsapi.rs +++ b/talpid-core/src/dns/windows/dnsapi.rs @@ -13,19 +13,18 @@ static DNSAPI_HANDLE: OnceLock<DnsApi> = OnceLock::new(); const MAX_CONCURRENT_FLUSHES: usize = 5; /// Errors that can happen when configuring DNS on Windows. -#[derive(err_derive::Error, Debug)] -#[error(no_from)] +#[derive(thiserror::Error, Debug)] pub enum Error { /// Failed to flush the DNS cache. - #[error(display = "Call to flush DNS cache failed")] + #[error("Call to flush DNS cache failed")] FlushCache, /// Too many flush attempts in progress. - #[error(display = "Too many flush attempts in progress")] + #[error("Too many flush attempts in progress")] TooManyFlushAttempts, /// Flushing the DNS cache timed out. - #[error(display = "Timeout while flushing DNS cache")] + #[error("Timeout while flushing DNS cache")] Timeout, } diff --git a/talpid-core/src/dns/windows/iphlpapi.rs b/talpid-core/src/dns/windows/iphlpapi.rs index e48b3b65f5..fa47a695c1 100644 --- a/talpid-core/src/dns/windows/iphlpapi.rs +++ b/talpid-core/src/dns/windows/iphlpapi.rs @@ -30,32 +30,31 @@ use windows_sys::{ }; /// Errors that can happen when configuring DNS on Windows. -#[derive(err_derive::Error, Debug)] -#[error(no_from)] +#[derive(thiserror::Error, Debug)] pub enum Error { /// Failure to obtain an interface LUID given an alias. - #[error(display = "Failed to obtain LUID for the interface alias")] - ObtainInterfaceLuid(#[error(source)] io::Error), + #[error("Failed to obtain LUID for the interface alias")] + ObtainInterfaceLuid(#[source] io::Error), /// Failure to obtain an interface GUID. - #[error(display = "Failed to obtain GUID for the interface")] - ObtainInterfaceGuid(#[error(source)] io::Error), + #[error("Failed to obtain GUID for the interface")] + ObtainInterfaceGuid(#[source] io::Error), /// Failed to set DNS settings on interface. - #[error(display = "Failed to set DNS settings on interface")] - SetInterfaceDnsSettings(#[error(source)] io::Error), + #[error("Failed to set DNS settings on interface")] + SetInterfaceDnsSettings(#[source] io::Error), /// Failure to flush DNS cache. - #[error(display = "Failed to flush DNS resolver cache")] - FlushResolverCache(#[error(source)] super::dnsapi::Error), + #[error("Failed to flush DNS resolver cache")] + FlushResolverCache(#[source] super::dnsapi::Error), /// Failed to load iphlpapi.dll. - #[error(display = "Failed to load iphlpapi.dll")] - LoadDll(#[error(source)] io::Error), + #[error("Failed to load iphlpapi.dll")] + LoadDll(#[source] io::Error), /// Failed to obtain exported function. - #[error(display = "Failed to obtain DNS function")] - GetFunction(#[error(source)] io::Error), + #[error("Failed to obtain DNS function")] + GetFunction(#[source] io::Error), } type SetInterfaceDnsSettingsFn = unsafe extern "stdcall" fn( diff --git a/talpid-core/src/dns/windows/mod.rs b/talpid-core/src/dns/windows/mod.rs index 4ab9976417..889f8b4126 100644 --- a/talpid-core/src/dns/windows/mod.rs +++ b/talpid-core/src/dns/windows/mod.rs @@ -9,19 +9,19 @@ mod netsh; mod tcpip; /// Errors that can happen when configuring DNS on Windows. -#[derive(err_derive::Error, Debug)] +#[derive(thiserror::Error, Debug)] pub enum Error { /// Failed to set DNS config using the iphlpapi module. - #[error(display = "Error in iphlpapi module")] - Iphlpapi(#[error(source)] iphlpapi::Error), + #[error("Error in iphlpapi module")] + Iphlpapi(#[from] iphlpapi::Error), /// Failed to set DNS config using the netsh module. - #[error(display = "Error in netsh module")] - Netsh(#[error(source)] netsh::Error), + #[error("Error in netsh module")] + Netsh(#[from] netsh::Error), /// Failed to set DNS config using the tcpip module. - #[error(display = "Error in tcpip module")] - Tcpip(#[error(source)] tcpip::Error), + #[error("Error in tcpip module")] + Tcpip(#[from] tcpip::Error), } pub struct DnsMonitor { diff --git a/talpid-core/src/dns/windows/netsh.rs b/talpid-core/src/dns/windows/netsh.rs index 7de3fe7900..25a11b826a 100644 --- a/talpid-core/src/dns/windows/netsh.rs +++ b/talpid-core/src/dns/windows/netsh.rs @@ -21,39 +21,38 @@ use windows_sys::Win32::{ const NETSH_TIMEOUT: Duration = Duration::from_secs(10); /// Errors that can happen when configuring DNS on Windows. -#[derive(err_derive::Error, Debug)] -#[error(no_from)] +#[derive(thiserror::Error, Debug)] pub enum Error { /// Failure to obtain an interface LUID given an alias. - #[error(display = "Failed to obtain LUID for the interface alias")] - ObtainInterfaceLuid(#[error(source)] io::Error), + #[error("Failed to obtain LUID for the interface alias")] + ObtainInterfaceLuid(#[source] io::Error), /// Failure to obtain an interface index. - #[error(display = "Failed to obtain index of the interface")] - ObtainInterfaceIndex(#[error(source)] io::Error), + #[error("Failed to obtain index of the interface")] + ObtainInterfaceIndex(#[source] io::Error), /// Failure to spawn netsh subprocess. - #[error(display = "Failed to spawn 'netsh'")] - SpawnNetsh(#[error(source)] io::Error), + #[error("Failed to spawn 'netsh'")] + SpawnNetsh(#[source] io::Error), /// Failure to spawn netsh subprocess. - #[error(display = "Failed to obtain system directory")] - GetSystemDir(#[error(source)] io::Error), + #[error("Failed to obtain system directory")] + GetSystemDir(#[source] io::Error), /// Failure to write to stdin. - #[error(display = "Failed to write to stdin for 'netsh'")] - NetshInput(#[error(source)] io::Error), + #[error("Failed to write to stdin for 'netsh'")] + NetshInput(#[source] io::Error), /// Failure to wait for netsh result. - #[error(display = "Failed to wait for 'netsh'")] - WaitNetsh(#[error(source)] io::Error), + #[error("Failed to wait for 'netsh'")] + WaitNetsh(#[source] io::Error), /// netsh returned a non-zero status. - #[error(display = "'netsh' returned an error: {:?}", _0)] + #[error("'netsh' returned an error: {0:?}")] Netsh(Option<i32>), /// netsh did not return in a timely manner. - #[error(display = "'netsh' took too long to complete")] + #[error("'netsh' took too long to complete")] NetshTimeout, } diff --git a/talpid-core/src/dns/windows/tcpip.rs b/talpid-core/src/dns/windows/tcpip.rs index 244417e119..7581d3c470 100644 --- a/talpid-core/src/dns/windows/tcpip.rs +++ b/talpid-core/src/dns/windows/tcpip.rs @@ -10,24 +10,23 @@ use winreg::{ }; /// Errors that can happen when configuring DNS on Windows. -#[derive(err_derive::Error, Debug)] -#[error(no_from)] +#[derive(thiserror::Error, Debug)] pub enum Error { /// Failure to obtain an interface LUID given an alias. - #[error(display = "Failed to obtain LUID for the interface alias")] - ObtainInterfaceLuid(#[error(source)] io::Error), + #[error("Failed to obtain LUID for the interface alias")] + ObtainInterfaceLuid(#[source] io::Error), /// Failure to obtain an interface GUID. - #[error(display = "Failed to obtain GUID for the interface")] - ObtainInterfaceGuid(#[error(source)] io::Error), + #[error("Failed to obtain GUID for the interface")] + ObtainInterfaceGuid(#[source] io::Error), /// Failure to flush DNS cache. - #[error(display = "Failed to flush DNS resolver cache")] - FlushResolverCache(#[error(source)] super::dnsapi::Error), + #[error("Failed to flush DNS resolver cache")] + FlushResolverCache(#[source] super::dnsapi::Error), /// Failed to update DNS servers for interface. - #[error(display = "Failed to update interface DNS servers")] - SetResolvers(#[error(source)] io::Error), + #[error("Failed to update interface DNS servers")] + SetResolvers(#[source] io::Error), } pub struct DnsMonitor { diff --git a/talpid-core/src/firewall/android.rs b/talpid-core/src/firewall/android.rs index fc854bc804..b9fa1eb442 100644 --- a/talpid-core/src/firewall/android.rs +++ b/talpid-core/src/firewall/android.rs @@ -1,8 +1,8 @@ use super::{FirewallArguments, FirewallPolicy}; /// Stub error type for Firewall errors on Android. -#[derive(Debug, err_derive::Error)] -#[error(display = "Unknown Android Firewall error")] +#[derive(Debug, thiserror::Error)] +#[error("Unknown Android Firewall error")] pub struct Error; /// The Android stub implementation for the firewall. diff --git a/talpid-core/src/firewall/linux.rs b/talpid-core/src/firewall/linux.rs index 717945c649..7c3cb26ec7 100644 --- a/talpid-core/src/firewall/linux.rs +++ b/talpid-core/src/firewall/linux.rs @@ -22,36 +22,32 @@ const PROC_SYS_NET_IPV4_CONF_SRC_VALID_MARK: &str = "/proc/sys/net/ipv4/conf/all pub type Result<T> = std::result::Result<T, Error>; /// Errors that can happen when interacting with Linux netfilter. -#[derive(err_derive::Error, Debug)] -#[error(no_from)] +#[derive(thiserror::Error, Debug)] pub enum Error { /// Unable to open netlink socket to netfilter. - #[error(display = "Unable to open netlink socket to netfilter")] - NetlinkOpenError(#[error(source)] io::Error), + #[error("Unable to open netlink socket to netfilter")] + NetlinkOpenError(#[source] io::Error), /// Unable to send netlink command to netfilter. - #[error(display = "Unable to send netlink command to netfilter")] - NetlinkSendError(#[error(source)] io::Error), + #[error("Unable to send netlink command to netfilter")] + NetlinkSendError(#[source] io::Error), /// Error while reading from netlink socket. - #[error(display = "Error while reading from netlink socket")] - NetlinkRecvError(#[error(source)] io::Error), + #[error("Error while reading from netlink socket")] + NetlinkRecvError(#[source] io::Error), /// Error while processing an incoming netlink message. - #[error(display = "Error while processing an incoming netlink message")] - ProcessNetlinkError(#[error(source)] io::Error), + #[error("Error while processing an incoming netlink message")] + ProcessNetlinkError(#[source] io::Error), /// Failed to verify that our tables are set. Probably means that /// it's the host that does not support nftables properly. - #[error(display = "Failed to set firewall rules")] + #[error("Failed to set firewall rules")] NetfilterTableNotSetError, /// Unable to translate network interface name into index. - #[error( - display = "Unable to translate network interface name \"{}\" into index", - _0 - )] - LookupIfaceIndexError(String, #[error(source)] crate::linux::IfaceIndexLookupError), + #[error("Unable to translate network interface name \"{0}\" into index")] + LookupIfaceIndexError(String, #[source] crate::linux::IfaceIndexLookupError), } /// TODO(linus): This crate is not supposed to be Mullvad-aware. So at some point this should be diff --git a/talpid-core/src/firewall/windows.rs b/talpid-core/src/firewall/windows.rs index c751a283a5..eda06ce5fd 100644 --- a/talpid-core/src/firewall/windows.rs +++ b/talpid-core/src/firewall/windows.rs @@ -12,32 +12,31 @@ use widestring::WideCString; use windows_sys::Win32::Globalization::{MultiByteToWideChar, CP_ACP}; /// Errors that can happen when configuring the Windows firewall. -#[derive(err_derive::Error, Debug)] -#[error(no_from)] +#[derive(thiserror::Error, Debug)] pub enum Error { /// Failure to initialize windows firewall module - #[error(display = "Failed to initialize windows firewall module")] + #[error("Failed to initialize windows firewall module")] Initialization, /// Failure to deinitialize windows firewall module - #[error(display = "Failed to deinitialize windows firewall module")] + #[error("Failed to deinitialize windows firewall module")] Deinitialization, /// Failure to apply a firewall _connecting_ policy - #[error(display = "Failed to apply connecting firewall policy")] - ApplyingConnectingPolicy(#[error(source)] FirewallPolicyError), + #[error("Failed to apply connecting firewall policy")] + ApplyingConnectingPolicy(#[source] FirewallPolicyError), /// Failure to apply a firewall _connected_ policy - #[error(display = "Failed to apply connected firewall policy")] - ApplyingConnectedPolicy(#[error(source)] FirewallPolicyError), + #[error("Failed to apply connected firewall policy")] + ApplyingConnectedPolicy(#[source] FirewallPolicyError), /// Failure to apply firewall _blocked_ policy - #[error(display = "Failed to apply blocked firewall policy")] - ApplyingBlockedPolicy(#[error(source)] FirewallPolicyError), + #[error("Failed to apply blocked firewall policy")] + ApplyingBlockedPolicy(#[source] FirewallPolicyError), /// Failure to reset firewall policies - #[error(display = "Failed to reset firewall policies")] - ResettingPolicy(#[error(source)] FirewallPolicyError), + #[error("Failed to reset firewall policies")] + ResettingPolicy(#[source] FirewallPolicyError), } /// Timeout for acquiring the WFP transaction lock diff --git a/talpid-core/src/linux/mod.rs b/talpid-core/src/linux/mod.rs index 05655bf4be..4b5321e4f0 100644 --- a/talpid-core/src/linux/mod.rs +++ b/talpid-core/src/linux/mod.rs @@ -18,10 +18,10 @@ pub fn iface_index(name: &str) -> Result<libc::c_uint, IfaceIndexLookupError> { } } -#[derive(Debug, err_derive::Error)] +#[derive(Debug, thiserror::Error)] pub enum IfaceIndexLookupError { - #[error(display = "Invalid network interface name: {}", _0)] - InvalidInterfaceName(String, #[error(source)] ffi::NulError), - #[error(display = "Failed to get index for interface {}", _0)] - InterfaceLookupError(String, #[error(source)] io::Error), + #[error("Invalid network interface name: {0}")] + InvalidInterfaceName(String, #[source] ffi::NulError), + #[error("Failed to get index for interface {0}")] + InterfaceLookupError(String, #[source] io::Error), } diff --git a/talpid-core/src/logging/mod.rs b/talpid-core/src/logging/mod.rs index 3251a39799..0e15054dd4 100644 --- a/talpid-core/src/logging/mod.rs +++ b/talpid-core/src/logging/mod.rs @@ -1,9 +1,9 @@ use std::{fs, io, path::Path}; /// Unable to create new log file -#[derive(err_derive::Error, Debug)] -#[error(display = "Unable to create new log file")] -pub struct RotateLogError(#[error(source)] io::Error); +#[derive(thiserror::Error, Debug)] +#[error("Unable to create new log file")] +pub struct RotateLogError(#[from] io::Error); /// Create a new log file while backing up a previous version of it. /// diff --git a/talpid-core/src/mpsc.rs b/talpid-core/src/mpsc.rs index 6492796cfc..d95f99fc7b 100644 --- a/talpid-core/src/mpsc.rs +++ b/talpid-core/src/mpsc.rs @@ -1,8 +1,8 @@ /// Error type for `Sender` trait. -#[derive(err_derive::Error, Debug)] +#[derive(thiserror::Error, Debug)] pub enum Error { /// The underlying channel is closed. - #[error(display = "Channel is closed")] + #[error("Channel is closed")] ChannelClosed, } diff --git a/talpid-core/src/offline/android.rs b/talpid-core/src/offline/android.rs index 936da896bd..7dc8389ed3 100644 --- a/talpid-core/src/offline/android.rs +++ b/talpid-core/src/offline/android.rs @@ -12,30 +12,21 @@ use jnix::{ use std::sync::{Arc, Weak}; use talpid_types::{android::AndroidContext, net::Connectivity, ErrorExt}; -#[derive(err_derive::Error, Debug)] -#[error(no_from)] +#[derive(thiserror::Error, Debug)] pub enum Error { - #[error(display = "Failed to attach Java VM to tunnel thread")] - AttachJvmToThread(#[error(source)] jni::errors::Error), + #[error("Failed to attach Java VM to tunnel thread")] + AttachJvmToThread(#[source] jni::errors::Error), - #[error(display = "Failed to call Java method {}.{}", _0, _1)] - CallMethod( - &'static str, - &'static str, - #[error(source)] jni::errors::Error, - ), + #[error("Failed to call Java method {0}.{1}")] + CallMethod(&'static str, &'static str, #[source] jni::errors::Error), - #[error(display = "Failed to create global reference to Java object")] - CreateGlobalRef(#[error(source)] jni::errors::Error), + #[error("Failed to create global reference to Java object")] + CreateGlobalRef(#[source] jni::errors::Error), - #[error(display = "Failed to find {}.{} method", _0, _1)] - FindMethod( - &'static str, - &'static str, - #[error(source)] jni::errors::Error, - ), + #[error("Failed to find {0}.{1} method")] + FindMethod(&'static str, &'static str, #[source] jni::errors::Error), - #[error(display = "Received an invalid result from {}.{}: {}", _0, _1, _2)] + #[error("Received an invalid result from {0}.{1}: {2}")] InvalidMethodResult(&'static str, &'static str, String), } diff --git a/talpid-core/src/offline/linux.rs b/talpid-core/src/offline/linux.rs index 6f37ef89e9..1bb07149bf 100644 --- a/talpid-core/src/offline/linux.rs +++ b/talpid-core/src/offline/linux.rs @@ -8,11 +8,10 @@ use talpid_types::{net::Connectivity, ErrorExt}; pub type Result<T> = std::result::Result<T, Error>; -#[derive(err_derive::Error, Debug)] -#[error(no_from)] +#[derive(thiserror::Error, Debug)] pub enum Error { - #[error(display = "The route manager returned an error")] - RouteManagerError(#[error(source)] talpid_routing::Error), + #[error("The route manager returned an error")] + RouteManagerError(#[source] talpid_routing::Error), } pub struct MonitorHandle { diff --git a/talpid-core/src/offline/macos.rs b/talpid-core/src/offline/macos.rs index dff62a975d..51596f77c2 100644 --- a/talpid-core/src/offline/macos.rs +++ b/talpid-core/src/offline/macos.rs @@ -22,10 +22,10 @@ use talpid_types::net::Connectivity; const SYNTHETIC_OFFLINE_DURATION: Duration = Duration::from_secs(1); -#[derive(err_derive::Error, Debug)] +#[derive(thiserror::Error, Debug)] pub enum Error { - #[error(display = "Failed to initialize route monitor")] - StartMonitorError(#[error(source)] talpid_routing::Error), + #[error("Failed to initialize route monitor")] + StartMonitorError(#[from] talpid_routing::Error), } pub struct MonitorHandle { diff --git a/talpid-core/src/offline/windows.rs b/talpid-core/src/offline/windows.rs index caa3ac8f5e..f47fe8dd4d 100644 --- a/talpid-core/src/offline/windows.rs +++ b/talpid-core/src/offline/windows.rs @@ -10,12 +10,12 @@ use talpid_routing::{get_best_default_route, CallbackHandle, EventType, RouteMan use talpid_types::{net::Connectivity, ErrorExt}; use talpid_windows::net::AddressFamily; -#[derive(err_derive::Error, Debug)] +#[derive(thiserror::Error, Debug)] pub enum Error { - #[error(display = "Unable to create listener thread")] - ThreadCreationError(#[error(source)] io::Error), - #[error(display = "Failed to start connectivity monitor")] - ConnectivityMonitorError(#[error(source)] talpid_routing::Error), + #[error("Unable to create listener thread")] + ThreadCreationError(#[from] io::Error), + #[error("Failed to start connectivity monitor")] + ConnectivityMonitorError(#[from] talpid_routing::Error), } pub struct BroadcastListener { diff --git a/talpid-core/src/resolver.rs b/talpid-core/src/resolver.rs index ed703c86fd..4fffced977 100644 --- a/talpid-core/src/resolver.rs +++ b/talpid-core/src/resolver.rs @@ -54,16 +54,15 @@ pub(crate) async fn start_resolver() -> Result<ResolverHandle, Error> { } /// Resolver errors -#[derive(err_derive::Error, Debug)] -#[error(no_from)] +#[derive(thiserror::Error, Debug)] pub enum Error { /// Failed to bind UDP socket - #[error(display = "Failed to bind UDP socket")] - UdpBindError(#[error(source)] io::Error), + #[error("Failed to bind UDP socket")] + UdpBindError(#[source] io::Error), /// Failed to get local address of a bound UDP socket - #[error(display = "Failed to get local address of a bound UDP socket")] - GetSocketAddrError(#[error(source)] io::Error), + #[error("Failed to get local address of a bound UDP socket")] + GetSocketAddrError(#[source] io::Error), } /// A filtering resolver. Listens on a specified port for DNS queries and responds queries for diff --git a/talpid-core/src/split_tunnel/linux.rs b/talpid-core/src/split_tunnel/linux.rs index 67d671d13c..787ced68da 100644 --- a/talpid-core/src/split_tunnel/linux.rs +++ b/talpid-core/src/split_tunnel/linux.rs @@ -16,36 +16,35 @@ pub const NET_CLS_CLASSID: u32 = 0x4d9f41; pub const MARK: i32 = 0xf41; /// Errors related to split tunneling. -#[derive(err_derive::Error, Debug)] -#[error(no_from)] +#[derive(thiserror::Error, Debug)] pub enum Error { /// Unable to create cgroup. - #[error(display = "Unable to initialize net_cls cgroup instance")] - InitNetClsCGroup(#[error(source)] nix::Error), + #[error("Unable to initialize net_cls cgroup instance")] + InitNetClsCGroup(#[source] nix::Error), /// Unable to create cgroup. - #[error(display = "Unable to create cgroup for excluded processes")] - CreateCGroup(#[error(source)] io::Error), + #[error("Unable to create cgroup for excluded processes")] + CreateCGroup(#[source] io::Error), /// Unable to set class ID for cgroup. - #[error(display = "Unable to set cgroup class ID")] - SetCGroupClassId(#[error(source)] io::Error), + #[error("Unable to set cgroup class ID")] + SetCGroupClassId(#[source] io::Error), /// Unable to add PID to cgroup.procs. - #[error(display = "Unable to add PID to cgroup.procs")] - AddCGroupPid(#[error(source)] io::Error), + #[error("Unable to add PID to cgroup.procs")] + AddCGroupPid(#[source] io::Error), /// Unable to remove PID to cgroup.procs. - #[error(display = "Unable to remove PID from cgroup")] - RemoveCGroupPid(#[error(source)] io::Error), + #[error("Unable to remove PID from cgroup")] + RemoveCGroupPid(#[source] io::Error), /// Unable to read cgroup.procs. - #[error(display = "Unable to obtain PIDs from cgroup.procs")] - ListCGroupPids(#[error(source)] io::Error), + #[error("Unable to obtain PIDs from cgroup.procs")] + ListCGroupPids(#[source] io::Error), /// Unable to read /proc/mounts - #[error(display = "Failed to read /proc/mounts")] - ListMounts(#[error(source)] io::Error), + #[error("Failed to read /proc/mounts")] + ListMounts(#[source] io::Error), } /// Manages PIDs in the Linux Cgroup excluded from the VPN tunnel. diff --git a/talpid-core/src/split_tunnel/windows/driver.rs b/talpid-core/src/split_tunnel/windows/driver.rs index 3f5a4e6a6d..ab1edf86f9 100644 --- a/talpid-core/src/split_tunnel/windows/driver.rs +++ b/talpid-core/src/split_tunnel/windows/driver.rs @@ -81,8 +81,8 @@ pub enum DriverState { Terminating = 5, } -#[derive(err_derive::Error, Debug)] -#[error(display = "Unknown driver state: {}", _0)] +#[derive(thiserror::Error, Debug)] +#[error("Unknown driver state: {0}")] pub struct UnknownDriverState(u64); impl TryFrom<u64> for DriverState { @@ -117,8 +117,8 @@ pub enum EventId { ErrorMessage, } -#[derive(err_derive::Error, Debug)] -#[error(display = "Unknown event id: {}", _0)] +#[derive(thiserror::Error, Debug)] +#[error("Unknown event id: {0}")] pub struct UnknownEventId(u32); impl TryFrom<u32> for EventId { @@ -170,42 +170,45 @@ pub struct DeviceHandle { unsafe impl Sync for DeviceHandle {} unsafe impl Send for DeviceHandle {} -#[derive(err_derive::Error, Debug)] -#[error(no_from)] +#[derive(thiserror::Error, Debug)] pub enum DeviceHandleError { /// Failed to connect because there's no such device - #[error(display = "Failed to connect to driver, no such device. \ - The driver is probably not loaded")] + #[error( + "Failed to connect to driver, no such device. \ + The driver is probably not loaded" + )] ConnectionFailed, /// Failed to connect because the connection was denied - #[error(display = "Failed to connect to driver, connection denied. \ - The exclusive connection is probably hogged")] + #[error( + "Failed to connect to driver, connection denied. \ + The exclusive connection is probably hogged" + )] ConnectionDenied, /// Failed to connect to driver - #[error(display = "Failed to connect to driver")] - ConnectionError(#[error(source)] io::Error), + #[error("Failed to connect to driver")] + ConnectionError(#[source] io::Error), /// Failed to inquire about driver state - #[error(display = "Failed to inquire about driver state")] - GetStateError(#[error(source)] io::Error), + #[error("Failed to inquire about driver state")] + GetStateError(#[source] io::Error), /// Failed to initialize driver - #[error(display = "Failed to initialize driver")] - InitializationError(#[error(source)] io::Error), + #[error("Failed to initialize driver")] + InitializationError(#[source] io::Error), /// Failed to register process tree with driver - #[error(display = "Failed to register process tree with driver")] - RegisterProcessesError(#[error(source)] io::Error), + #[error("Failed to register process tree with driver")] + RegisterProcessesError(#[source] io::Error), /// Failed to clear configuration in driver - #[error(display = "Failed to clear configuration in driver")] - ClearConfigError(#[error(source)] io::Error), + #[error("Failed to clear configuration in driver")] + ClearConfigError(#[source] io::Error), /// Failed to reset driver state to "started" - #[error(display = "Failed to reset driver state")] - ResetError(#[error(source)] io::Error), + #[error("Failed to reset driver state")] + ResetError(#[source] io::Error), } impl DeviceHandle { diff --git a/talpid-core/src/split_tunnel/windows/mod.rs b/talpid-core/src/split_tunnel/windows/mod.rs index c5b08706ff..68030691a9 100644 --- a/talpid-core/src/split_tunnel/windows/mod.rs +++ b/talpid-core/src/split_tunnel/windows/mod.rs @@ -31,75 +31,74 @@ const DRIVER_EVENT_BUFFER_SIZE: usize = 2048; const RESERVED_IP_V4: Ipv4Addr = Ipv4Addr::new(192, 0, 2, 123); /// Errors that may occur in [`SplitTunnel`]. -#[derive(err_derive::Error, Debug)] -#[error(no_from)] +#[derive(thiserror::Error, Debug)] pub enum Error { /// Failed to install or start driver service - #[error(display = "Failed to start driver service")] - ServiceError(#[error(source)] service::Error), + #[error("Failed to start driver service")] + ServiceError(#[source] service::Error), /// Failed to initialize the driver - #[error(display = "Failed to initialize driver")] - InitializationError(#[error(source)] driver::DeviceHandleError), + #[error("Failed to initialize driver")] + InitializationError(#[source] driver::DeviceHandleError), /// Failed to reset the driver - #[error(display = "Failed to reset driver")] - ResetError(#[error(source)] io::Error), + #[error("Failed to reset driver")] + ResetError(#[source] io::Error), /// Failed to set paths to excluded applications - #[error(display = "Failed to set list of excluded applications")] - SetConfiguration(#[error(source)] io::Error), + #[error("Failed to set list of excluded applications")] + SetConfiguration(#[source] io::Error), /// Failed to obtain the current driver state - #[error(display = "Failed to obtain the driver state")] - GetState(#[error(source)] io::Error), + #[error("Failed to obtain the driver state")] + GetState(#[source] io::Error), /// Failed to register interface IP addresses - #[error(display = "Failed to register IP addresses for exclusions")] - RegisterIps(#[error(source)] io::Error), + #[error("Failed to register IP addresses for exclusions")] + RegisterIps(#[source] io::Error), /// Failed to clear interface IP addresses - #[error(display = "Failed to clear registered IP addresses")] - ClearIps(#[error(source)] io::Error), + #[error("Failed to clear registered IP addresses")] + ClearIps(#[source] io::Error), /// Failed to set up the driver event loop - #[error(display = "Failed to set up the driver event loop")] - EventThreadError(#[error(source)] io::Error), + #[error("Failed to set up the driver event loop")] + EventThreadError(#[source] io::Error), /// Failed to obtain default route - #[error(display = "Failed to obtain the default route")] - ObtainDefaultRoute(#[error(source)] talpid_routing::Error), + #[error("Failed to obtain the default route")] + ObtainDefaultRoute(#[source] talpid_routing::Error), /// Failed to obtain an IP address given a network interface LUID - #[error(display = "Failed to obtain IP address for interface LUID")] - LuidToIp(#[error(source)] talpid_windows::net::Error), + #[error("Failed to obtain IP address for interface LUID")] + LuidToIp(#[source] talpid_windows::net::Error), /// Failed to set up callback for monitoring default route changes - #[error(display = "Failed to register default route change callback")] + #[error("Failed to register default route change callback")] RegisterRouteChangeCallback, /// Unexpected IP parsing error - #[error(display = "Failed to parse IP address")] + #[error("Failed to parse IP address")] IpParseError, /// The request handling thread is stuck - #[error(display = "The ST request thread is stuck")] + #[error("The ST request thread is stuck")] RequestThreadStuck, /// The request handling thread is down - #[error(display = "The split tunnel monitor is down")] + #[error("The split tunnel monitor is down")] SplitTunnelDown, /// Failed to start the NTFS reparse point monitor - #[error(display = "Failed to start path monitor")] - StartPathMonitor(#[error(source)] io::Error), + #[error("Failed to start path monitor")] + StartPathMonitor(#[source] io::Error), /// A previous path update has not yet completed - #[error(display = "A previous update is not yet complete")] + #[error("A previous update is not yet complete")] AlreadySettingPaths, /// Resetting in the engaged state risks leaking into the tunnel - #[error(display = "Failed to reset driver because it is engaged")] + #[error("Failed to reset driver because it is engaged")] CannotResetEngaged, } diff --git a/talpid-core/src/split_tunnel/windows/service.rs b/talpid-core/src/split_tunnel/windows/service.rs index e71e9abc1d..95756acca8 100644 --- a/talpid-core/src/split_tunnel/windows/service.rs +++ b/talpid-core/src/split_tunnel/windows/service.rs @@ -19,44 +19,43 @@ const DRIVER_FILENAME: &str = "mullvad-split-tunnel.sys"; const WAIT_STATUS_TIMEOUT: Duration = Duration::from_secs(8); -#[derive(err_derive::Error, Debug)] -#[error(no_from)] +#[derive(thiserror::Error, Debug)] pub enum Error { /// Failed to open service control manager - #[error(display = "Failed to connect to service control manager")] - OpenServiceControlManager(#[error(source)] windows_service::Error), + #[error("Failed to connect to service control manager")] + OpenServiceControlManager(#[source] windows_service::Error), /// Failed to create a service handle - #[error(display = "Failed to open service")] - OpenServiceHandle(#[error(source)] windows_service::Error), + #[error("Failed to open service")] + OpenServiceHandle(#[source] windows_service::Error), /// Failed to start split tunnel service - #[error(display = "Failed to start split tunnel device driver service")] - StartService(#[error(source)] windows_service::Error), + #[error("Failed to start split tunnel device driver service")] + StartService(#[source] windows_service::Error), /// Failed to check service status - #[error(display = "Failed to query service status")] - QueryServiceStatus(#[error(source)] windows_service::Error), + #[error("Failed to query service status")] + QueryServiceStatus(#[source] windows_service::Error), /// Failed to open service config - #[error(display = "Failed to retrieve service config")] - QueryServiceConfig(#[error(source)] windows_service::Error), + #[error("Failed to retrieve service config")] + QueryServiceConfig(#[source] windows_service::Error), /// Failed to install ST service - #[error(display = "Failed to install split tunnel driver")] - InstallService(#[error(source)] windows_service::Error), + #[error("Failed to install split tunnel driver")] + InstallService(#[source] windows_service::Error), /// Failed to start ST service - #[error(display = "Timed out waiting on service to start")] + #[error("Timed out waiting on service to start")] StartTimeout, /// Failed to connect to existing driver - #[error(display = "Failed to open service handle")] - OpenHandle(#[error(source)] super::driver::DeviceHandleError), + #[error("Failed to open service handle")] + OpenHandle(#[source] super::driver::DeviceHandleError), /// Failed to reset existing driver - #[error(display = "Failed to reset driver state")] - ResetDriver(#[error(source)] io::Error), + #[error("Failed to reset driver state")] + ResetDriver(#[source] io::Error), } pub fn install_driver_if_required(resource_dir: &Path) -> Result<(), Error> { diff --git a/talpid-core/src/tunnel/mod.rs b/talpid-core/src/tunnel/mod.rs index 3ef05201b5..0daa8b996c 100644 --- a/talpid-core/src/tunnel/mod.rs +++ b/talpid-core/src/tunnel/mod.rs @@ -24,35 +24,35 @@ const DEFAULT_MTU: u16 = if cfg!(target_os = "android") { pub type Result<T> = std::result::Result<T, Error>; /// Errors that can occur in the [`TunnelMonitor`]. -#[derive(err_derive::Error, Debug)] +#[derive(thiserror::Error, Debug)] pub enum Error { /// Tunnel can't have IPv6 enabled because the system has disabled IPv6 support. - #[error(display = "Can't enable IPv6 on tunnel interface because IPv6 is disabled")] + #[error("Can't enable IPv6 on tunnel interface because IPv6 is disabled")] EnableIpv6Error, /// Running on an operating system which is not supported yet. - #[error(display = "Tunnel type not supported on this operating system")] + #[error("Tunnel type not supported on this operating system")] UnsupportedPlatform, /// Failed to rotate tunnel log file - #[error(display = "Failed to rotate tunnel log file")] - RotateLogError(#[error(source)] crate::logging::RotateLogError), + #[error("Failed to rotate tunnel log file")] + RotateLogError(#[from] crate::logging::RotateLogError), /// Failure to build Wireguard configuration. - #[error(display = "Failed to configure Wireguard with the given parameters")] - WireguardConfigError(#[error(source)] talpid_wireguard::config::Error), + #[error("Failed to configure Wireguard with the given parameters")] + WireguardConfigError(#[from] talpid_wireguard::config::Error), /// There was an error listening for events from the OpenVPN tunnel #[cfg(not(target_os = "android"))] - #[error(display = "Failed while listening for events from the OpenVPN tunnel")] - OpenVpnTunnelMonitoringError(#[error(source)] talpid_openvpn::Error), + #[error("Failed while listening for events from the OpenVPN tunnel")] + OpenVpnTunnelMonitoringError(#[from] talpid_openvpn::Error), /// There was an error listening for events from the Wireguard tunnel - #[error(display = "Failed while listening for events from the Wireguard tunnel")] - WireguardTunnelMonitoringError(#[error(source)] talpid_wireguard::Error), + #[error("Failed while listening for events from the Wireguard tunnel")] + WireguardTunnelMonitoringError(#[from] talpid_wireguard::Error), /// Could not detect and assign the correct mtu - #[error(display = "Could not detect and assign a correct MTU for the Wireguard tunnel")] + #[error("Could not detect and assign a correct MTU for the Wireguard tunnel")] AssignMtuError, } diff --git a/talpid-core/src/tunnel_state_machine/mod.rs b/talpid-core/src/tunnel_state_machine/mod.rs index 6be9b8a1c3..26a03328a4 100644 --- a/talpid-core/src/tunnel_state_machine/mod.rs +++ b/talpid-core/src/tunnel_state_machine/mod.rs @@ -49,40 +49,40 @@ use talpid_types::{ const TUNNEL_STATE_MACHINE_SHUTDOWN_TIMEOUT: Duration = Duration::from_secs(5); /// Errors that can happen when setting up or using the state machine. -#[derive(err_derive::Error, Debug)] +#[derive(thiserror::Error, Debug)] pub enum Error { /// Unable to spawn offline state monitor - #[error(display = "Unable to spawn offline state monitor")] - OfflineMonitorError(#[error(source)] crate::offline::Error), + #[error("Unable to spawn offline state monitor")] + OfflineMonitorError(#[from] crate::offline::Error), /// Unable to set up split tunneling #[cfg(target_os = "windows")] - #[error(display = "Failed to initialize split tunneling")] - InitSplitTunneling(#[error(source)] split_tunnel::Error), + #[error("Failed to initialize split tunneling")] + InitSplitTunneling(#[from] split_tunnel::Error), /// Failed to initialize the system firewall integration. - #[error(display = "Failed to initialize the system firewall integration")] - InitFirewallError(#[error(source)] crate::firewall::Error), + #[error("Failed to initialize the system firewall integration")] + InitFirewallError(#[from] crate::firewall::Error), /// Failed to initialize the system DNS manager and monitor. - #[error(display = "Failed to initialize the system DNS manager and monitor")] - InitDnsMonitorError(#[error(source)] crate::dns::Error), + #[error("Failed to initialize the system DNS manager and monitor")] + InitDnsMonitorError(#[from] crate::dns::Error), /// Failed to initialize the route manager. - #[error(display = "Failed to initialize the route manager")] - InitRouteManagerError(#[error(source)] talpid_routing::Error), + #[error("Failed to initialize the route manager")] + InitRouteManagerError(#[from] talpid_routing::Error), /// Failed to initialize filtering resolver #[cfg(target_os = "macos")] - #[error(display = "Failed to initialize filtering resolver")] - InitFilteringResolver(#[error(source)] crate::resolver::Error), + #[error("Failed to initialize filtering resolver")] + InitFilteringResolver(#[from] crate::resolver::Error), /// Failed to initialize tunnel state machine event loop executor - #[error(display = "Failed to initialize tunnel state machine event loop executor")] - ReactorError(#[error(source)] io::Error), + #[error("Failed to initialize tunnel state machine event loop executor")] + ReactorError(#[from] io::Error), /// Failed to send state change event to listener - #[error(display = "Failed to send state change event to listener")] + #[error("Failed to send state change event to listener")] SendStateChange, } |
