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 | |
| 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.
146 files changed, 1343 insertions, 1482 deletions
diff --git a/Cargo.lock b/Cargo.lock index 969b5f371e..f495a2e281 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -185,7 +185,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.51", ] [[package]] @@ -196,7 +196,7 @@ checksum = "bc00ceb34980c03614e35a3a4e218276a0a824e911d07651cd0d858a51e8c0f0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.51", ] [[package]] @@ -490,7 +490,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.51", ] [[package]] @@ -659,7 +659,7 @@ checksum = "83fdaf97f4804dcebfa5862639bc9ce4121e82140bec2a987ac5140294865b5b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.51", ] [[package]] @@ -884,7 +884,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.51", ] [[package]] @@ -1098,7 +1098,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.51", ] [[package]] @@ -1816,7 +1816,6 @@ version = "0.0.0" dependencies = [ "cbindgen", "chrono", - "err-derive", "futures", "http", "hyper", @@ -1832,6 +1831,7 @@ dependencies = [ "shadowsocks", "talpid-time", "talpid-types", + "thiserror", "tokio", "tokio-rustls", "tokio-socks", @@ -1846,7 +1846,6 @@ dependencies = [ "chrono", "clap", "clap_complete", - "err-derive", "futures", "itertools", "mullvad-management-interface", @@ -1854,6 +1853,7 @@ dependencies = [ "mullvad-version", "natord", "talpid-types", + "thiserror", "tokio", "windows-sys 0.48.0", "winres", @@ -1868,7 +1868,6 @@ dependencies = [ "clap", "ctrlc", "dirs", - "err-derive", "fern", "futures", "libc", @@ -1895,6 +1894,7 @@ dependencies = [ "talpid-time", "talpid-types", "talpid-windows", + "thiserror", "tokio", "tokio-stream", "winapi", @@ -1907,9 +1907,9 @@ dependencies = [ name = "mullvad-exclude" version = "0.0.0" dependencies = [ - "err-derive", "nix 0.23.2", "talpid-types", + "thiserror", ] [[package]] @@ -1926,7 +1926,6 @@ dependencies = [ name = "mullvad-jni" version = "0.0.0" dependencies = [ - "err-derive", "futures", "ipnetwork", "jnix", @@ -1940,6 +1939,7 @@ dependencies = [ "rand 0.8.5", "talpid-tunnel", "talpid-types", + "thiserror", ] [[package]] @@ -1947,7 +1947,6 @@ name = "mullvad-management-interface" version = "0.0.0" dependencies = [ "chrono", - "err-derive", "futures", "log", "mullvad-paths", @@ -1958,6 +1957,7 @@ dependencies = [ "prost", "prost-types", "talpid-types", + "thiserror", "tokio", "tonic", "tonic-build", @@ -1977,9 +1977,9 @@ dependencies = [ name = "mullvad-paths" version = "0.0.0" dependencies = [ - "err-derive", "log", "once_cell", + "thiserror", "widestring", "windows-sys 0.48.0", ] @@ -1992,7 +1992,6 @@ dependencies = [ "dirs", "duct", "env_logger 0.10.0", - "err-derive", "log", "mullvad-api", "mullvad-paths", @@ -2001,6 +2000,7 @@ dependencies = [ "regex", "talpid-platform-metadata", "talpid-types", + "thiserror", "tokio", "uuid", "windows-sys 0.48.0", @@ -2012,7 +2012,6 @@ name = "mullvad-relay-selector" version = "0.0.0" dependencies = [ "chrono", - "err-derive", "ipnetwork", "log", "mullvad-types", @@ -2020,6 +2019,7 @@ dependencies = [ "rand 0.8.5", "serde_json", "talpid-types", + "thiserror", ] [[package]] @@ -2028,7 +2028,6 @@ version = "0.0.0" dependencies = [ "clap", "env_logger 0.10.0", - "err-derive", "mullvad-api", "mullvad-daemon", "mullvad-management-interface", @@ -2039,6 +2038,7 @@ dependencies = [ "talpid-core", "talpid-future", "talpid-types", + "thiserror", "tokio", ] @@ -2048,7 +2048,6 @@ version = "0.0.0" dependencies = [ "chrono", "clap", - "err-derive", "ipnetwork", "jnix", "log", @@ -2056,6 +2055,7 @@ dependencies = [ "regex", "serde", "talpid-types", + "thiserror", "uuid", ] @@ -2438,7 +2438,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.51", ] [[package]] @@ -2531,7 +2531,7 @@ checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" dependencies = [ "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.51", ] [[package]] @@ -2656,7 +2656,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae005bd773ab59b4725093fd7df83fd7892f7d8eafb48dbd7de6e024e4215f9d" dependencies = [ "proc-macro2", - "syn 2.0.31", + "syn 2.0.51", ] [[package]] @@ -2685,9 +2685,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.66" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] @@ -2739,7 +2739,7 @@ dependencies = [ "prost", "prost-types", "regex", - "syn 2.0.31", + "syn 2.0.51", "tempfile", "which", ] @@ -2754,7 +2754,7 @@ dependencies = [ "itertools", "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.51", ] [[package]] @@ -2784,9 +2784,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.33" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -3154,7 +3154,7 @@ checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" dependencies = [ "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.51", ] [[package]] @@ -3494,9 +3494,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.31" +version = "2.0.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "718fa2415bcb8d8bd775917a1bf12a7931b6dfa890753378538118181e0cb398" +checksum = "6ab617d94515e94ae53b8406c628598680aa0c9587474ecbe58188f7b345d66c" dependencies = [ "proc-macro2", "quote", @@ -3550,7 +3550,6 @@ dependencies = [ "bitflags 1.3.2", "chrono", "duct", - "err-derive", "futures", "inotify 0.10.2", "ipnetwork", @@ -3577,6 +3576,7 @@ dependencies = [ "talpid-types", "talpid-windows", "talpid-wireguard", + "thiserror", "tokio", "tonic-build", "triggered", @@ -3594,10 +3594,10 @@ name = "talpid-dbus" version = "0.0.0" dependencies = [ "dbus", - "err-derive", "libc", "log", "once_cell", + "thiserror", "tokio", ] @@ -3616,7 +3616,6 @@ name = "talpid-openvpn" version = "0.0.0" dependencies = [ "async-trait", - "err-derive", "futures", "log", "once_cell", @@ -3628,6 +3627,7 @@ dependencies = [ "talpid-tunnel", "talpid-types", "talpid-windows", + "thiserror", "tokio", "tonic", "tonic-build", @@ -3643,13 +3643,13 @@ name = "talpid-openvpn-plugin" version = "0.0.0" dependencies = [ "env_logger 0.10.0", - "err-derive", "log", "mullvad-version", "openvpn-plugin", "parity-tokio-ipc", "prost", "talpid-types", + "thiserror", "tokio", "tonic", "tonic-build", @@ -3672,7 +3672,6 @@ name = "talpid-routing" version = "0.0.0" dependencies = [ "bitflags 1.3.2", - "err-derive", "futures", "ipnetwork", "libc", @@ -3685,6 +3684,7 @@ dependencies = [ "system-configuration", "talpid-types", "talpid-windows", + "thiserror", "tokio", "widestring", "windows-sys 0.48.0", @@ -3704,7 +3704,6 @@ version = "0.0.0" dependencies = [ "cfg-if", "duct", - "err-derive", "futures", "ipnetwork", "jnix", @@ -3713,6 +3712,7 @@ dependencies = [ "talpid-routing", "talpid-types", "talpid-windows", + "thiserror", "tokio", "tun", "windows-sys 0.48.0", @@ -3742,10 +3742,10 @@ name = "talpid-types" version = "0.0.0" dependencies = [ "base64 0.13.1", - "err-derive", "ipnetwork", "jnix", "serde", + "thiserror", "x25519-dalek", "zeroize", ] @@ -3754,10 +3754,10 @@ dependencies = [ name = "talpid-windows" version = "0.0.0" dependencies = [ - "err-derive", "futures", "socket2 0.5.3", "talpid-types", + "thiserror", "windows-sys 0.48.0", ] @@ -3769,7 +3769,6 @@ dependencies = [ "byteorder", "chrono", "duct", - "err-derive", "futures", "hex", "internet-checksum", @@ -3794,6 +3793,7 @@ dependencies = [ "talpid-tunnel-config-client", "talpid-types", "talpid-windows", + "thiserror", "tokio", "tokio-stream", "tunnel-obfuscation", @@ -3826,22 +3826,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.48" +version = "1.0.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d6d7a740b8a666a7e828dd00da9c0dc290dff53154ea77ac109281de90589b7" +checksum = "1e45bcbe8ed29775f228095caf2cd67af7a4ccf756ebff23a306bf3e8b47b24b" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.48" +version = "1.0.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49922ecae66cc8a249b77e68d1d0623c1b2c514f0060c27cdc68bd62a1219d35" +checksum = "a953cb265bef375dae3de6663da4d3804eee9682ea80d8e2542529b73c531c81" dependencies = [ "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.51", ] [[package]] @@ -3913,7 +3913,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.51", ] [[package]] @@ -4060,7 +4060,7 @@ dependencies = [ "proc-macro2", "prost-build", "quote", - "syn 2.0.31", + "syn 2.0.51", ] [[package]] @@ -4116,7 +4116,7 @@ checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" dependencies = [ "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.51", ] [[package]] @@ -4132,12 +4132,12 @@ dependencies = [ name = "translations-converter" version = "0.0.0" dependencies = [ - "err-derive", "htmlize", "once_cell", "quick-xml", "regex", "serde", + "thiserror", ] [[package]] @@ -4239,7 +4239,7 @@ name = "tunnel-obfuscation" version = "0.0.0" dependencies = [ "async-trait", - "err-derive", + "thiserror", "tokio", "udp-over-tcp", ] @@ -4424,7 +4424,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.51", "wasm-bindgen-shared", ] @@ -4446,7 +4446,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.51", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -4801,5 +4801,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.51", ] diff --git a/Cargo.toml b/Cargo.toml index e2a95e7d95..81efa9b85c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -56,7 +56,7 @@ prost = "0.12.0" prost-types = "0.12.0" env_logger = "0.10.0" -err-derive = "0.3.1" +thiserror = "1.0.57" log = "0.4" shadowsocks = { version = "1.16" } diff --git a/android/translations-converter/Cargo.toml b/android/translations-converter/Cargo.toml index 3629b7372f..57deb26a57 100644 --- a/android/translations-converter/Cargo.toml +++ b/android/translations-converter/Cargo.toml @@ -11,7 +11,7 @@ rust-version.workspace = true workspace = true [dependencies] -err-derive = { workspace = true } +thiserror = { workspace = true } htmlize = { version = "1.0.2", features = ["unescape"] } once_cell = { workspace = true } regex = "1" diff --git a/android/translations-converter/src/gettext/messages.rs b/android/translations-converter/src/gettext/messages.rs index e9dc151bfc..25316afae4 100644 --- a/android/translations-converter/src/gettext/messages.rs +++ b/android/translations-converter/src/gettext/messages.rs @@ -103,13 +103,13 @@ impl From<MsgString> for MsgValue { } } -#[derive(Debug, err_derive::Error)] +#[derive(Debug, thiserror::Error)] pub enum Error { /// Parser error while parsing file - #[error(display = "Failed to parse input file")] - Parse(#[error(source)] super::parser::Error), + #[error("Failed to parse input file")] + Parse(#[from] super::parser::Error), /// IO error while reading input file. - #[error(display = "Failed to read from the input file")] - Io(#[error(source)] std::io::Error), + #[error("Failed to read from the input file")] + Io(#[from] std::io::Error), } diff --git a/android/translations-converter/src/gettext/parser.rs b/android/translations-converter/src/gettext/parser.rs index 177f15d15a..4d1928b473 100644 --- a/android/translations-converter/src/gettext/parser.rs +++ b/android/translations-converter/src/gettext/parser.rs @@ -526,35 +526,29 @@ fn collect_variants( } /// Parsing errors. -#[derive(Clone, Debug, Eq, PartialEq, err_derive::Error)] +#[derive(Clone, Debug, Eq, PartialEq, thiserror::Error)] pub enum Error { /// An unexpected line was read while parsing. - #[error(display = "Unexpected line parsing gettext messages: {}", _0)] + #[error("Unexpected line parsing gettext messages: {0}")] UnexpectedLine(String), /// Input uses an unrecognized plural forumal. - #[error( - display = "Input uses an unrecognized formula for the plural form: {}", - _0 - )] + #[error("Input uses an unrecognized formula for the plural form: {0}")] UnrecognizedPluralFormula(String), /// Input ended with an incomplete entry. - #[error( - display = "Input ended with an incomplete gettext entry with ID: {}", - _0 - )] + #[error("Input ended with an incomplete gettext entry with ID: {0}")] IncompleteEntry(MsgString), /// Plural entry definition is missing a plural variant. - #[error(display = "Plural entry is missing a plural variant: {}", _0)] + #[error("Plural entry is missing a plural variant: {0}")] IncompletePluralEntry(MsgString), /// Plural variant is invalid. - #[error(display = "Plural variant line is invalid: {}", _0)] + #[error("Plural variant line is invalid: {0}")] InvalidPluralVariant(String), /// Plural variant index was not parsable. - #[error(display = "Plural variant line contains an invalid index: {}", _0)] + #[error("Plural variant line contains an invalid index: {0}")] InvalidPluralIndex(String), } diff --git a/android/translations-converter/src/gettext/plural_form.rs b/android/translations-converter/src/gettext/plural_form.rs index 6d3436b8c2..7eac7de0d6 100644 --- a/android/translations-converter/src/gettext/plural_form.rs +++ b/android/translations-converter/src/gettext/plural_form.rs @@ -44,6 +44,6 @@ impl FromStr for PluralForm { /// Failed to create [`PluralForm`] from specified plural formula. /// /// The formula could be an invalid formula, or support for it hasn't been added yet. -#[derive(Clone, Debug, err_derive::Error)] -#[error(display = "Unsupported plural formula: {}", _0)] +#[derive(Clone, Debug, thiserror::Error)] +#[error("Unsupported plural formula: {0}")] pub struct UnsupportedPluralFormulaError(String); diff --git a/mullvad-api/Cargo.toml b/mullvad-api/Cargo.toml index b81725bbbb..4e82f630b5 100644 --- a/mullvad-api/Cargo.toml +++ b/mullvad-api/Cargo.toml @@ -17,7 +17,7 @@ api-override = [] [dependencies] libc = "0.2" chrono = { workspace = true } -err-derive = { workspace = true } +thiserror = { workspace = true } futures = "0.3" http = "0.2" hyper = { version = "0.14", features = ["client", "stream", "http1", "tcp" ] } diff --git a/mullvad-api/src/abortable_stream.rs b/mullvad-api/src/abortable_stream.rs index 261693eb27..a1426f07f1 100644 --- a/mullvad-api/src/abortable_stream.rs +++ b/mullvad-api/src/abortable_stream.rs @@ -12,8 +12,8 @@ use std::{ }; use tokio::io::{AsyncRead, AsyncWrite, ReadBuf}; -#[derive(err_derive::Error, Debug)] -#[error(display = "Stream is closed")] +#[derive(thiserror::Error, Debug)] +#[error("Stream is closed")] pub struct Aborted(()); #[derive(Clone, Debug)] diff --git a/mullvad-api/src/address_cache.rs b/mullvad-api/src/address_cache.rs index aa9a155bec..dfa586daf4 100644 --- a/mullvad-api/src/address_cache.rs +++ b/mullvad-api/src/address_cache.rs @@ -8,20 +8,19 @@ use tokio::{ sync::Mutex, }; -#[derive(err_derive::Error, Debug)] -#[error(no_from)] +#[derive(thiserror::Error, Debug)] pub enum Error { - #[error(display = "Failed to open the address cache file")] - Open(#[error(source)] io::Error), + #[error("Failed to open the address cache file")] + Open(#[source] io::Error), - #[error(display = "Failed to read the address cache file")] - Read(#[error(source)] io::Error), + #[error("Failed to read the address cache file")] + Read(#[source] io::Error), - #[error(display = "Failed to parse the address cache file")] + #[error("Failed to parse the address cache file")] Parse, - #[error(display = "Failed to update the address cache file")] - Write(#[error(source)] io::Error), + #[error("Failed to update the address cache file")] + Write(#[source] io::Error), } #[derive(Clone)] diff --git a/mullvad-api/src/availability.rs b/mullvad-api/src/availability.rs index f66fb4053a..ba33836b16 100644 --- a/mullvad-api/src/availability.rs +++ b/mullvad-api/src/availability.rs @@ -11,11 +11,11 @@ const CHANNEL_CAPACITY: usize = 100; /// called for this long. const INACTIVITY_TIME: Duration = Duration::from_secs(3 * 24 * 60 * 60); -#[derive(err_derive::Error, Debug)] +#[derive(thiserror::Error, Debug)] pub enum Error { /// The [`ApiAvailability`] instance was dropped, or the receiver lagged behind. - #[error(display = "API availability instance was dropped")] - Interrupted(#[error(source)] broadcast::error::RecvError), + #[error("API availability instance was dropped")] + Interrupted(#[from] broadcast::error::RecvError), } #[derive(PartialEq, Eq, Clone, Copy, Debug, Default)] diff --git a/mullvad-api/src/https_client_with_sni.rs b/mullvad-api/src/https_client_with_sni.rs index 28f40a7d87..afd044aa30 100644 --- a/mullvad-api/src/https_client_with_sni.rs +++ b/mullvad-api/src/https_client_with_sni.rs @@ -222,9 +222,9 @@ struct SocksConfig { authentication: Option<proxy::SocksAuth>, } -#[derive(err_derive::Error, Debug)] +#[derive(thiserror::Error, Debug)] enum ProxyConfigError { - #[error(display = "Unrecognized cipher selected: {}", _0)] + #[error("Unrecognized cipher selected: {0}")] InvalidCipher(String), } diff --git a/mullvad-api/src/lib.rs b/mullvad-api/src/lib.rs index e78535dfc0..c4d5665a01 100644 --- a/mullvad-api/src/lib.rs +++ b/mullvad-api/src/lib.rs @@ -314,16 +314,16 @@ pub struct Runtime { socket_bypass_tx: Option<mpsc::Sender<SocketBypassRequest>>, } -#[derive(err_derive::Error, Debug)] +#[derive(thiserror::Error, Debug)] pub enum Error { - #[error(display = "Failed to construct a rest client")] - RestError(#[error(source)] rest::Error), + #[error("Failed to construct a rest client")] + RestError(#[from] rest::Error), - #[error(display = "Failed to load address cache")] - AddressCacheError(#[error(source)] address_cache::Error), + #[error("Failed to load address cache")] + AddressCacheError(#[from] address_cache::Error), - #[error(display = "API availability check failed")] - ApiCheckError(#[error(source)] availability::Error), + #[error("API availability check failed")] + ApiCheckError(#[from] availability::Error), } impl Runtime { diff --git a/mullvad-api/src/rest.rs b/mullvad-api/src/rest.rs index 0fd826abc4..238d73206a 100644 --- a/mullvad-api/src/rest.rs +++ b/mullvad-api/src/rest.rs @@ -34,38 +34,38 @@ pub type Result<T> = std::result::Result<T, Error>; const DEFAULT_TIMEOUT: Duration = Duration::from_secs(10); /// Describes all the ways a REST request can fail -#[derive(err_derive::Error, Debug, Clone)] +#[derive(thiserror::Error, Debug, Clone)] pub enum Error { - #[error(display = "REST client service is down")] + #[error("REST client service is down")] RestServiceDown, - #[error(display = "Request cancelled")] + #[error("Request cancelled")] Aborted, - #[error(display = "Hyper error")] - HyperError(#[error(source)] Arc<hyper::Error>), + #[error("Hyper error")] + HyperError(#[from] Arc<hyper::Error>), - #[error(display = "Invalid header value")] + #[error("Invalid header value")] InvalidHeaderError, - #[error(display = "HTTP error")] - HttpError(#[error(source)] Arc<http::Error>), + #[error("HTTP error")] + HttpError(#[from] Arc<http::Error>), - #[error(display = "Request timed out")] + #[error("Request timed out")] TimeoutError, - #[error(display = "Failed to deserialize data")] - DeserializeError(#[error(source)] Arc<serde_json::Error>), + #[error("Failed to deserialize data")] + DeserializeError(#[from] Arc<serde_json::Error>), /// Unexpected response code - #[error(display = "Unexpected response status code {} - {}", _0, _1)] + #[error("Unexpected response status code {0} - {1}")] ApiError(StatusCode, String), /// The string given was not a valid URI. - #[error(display = "Not a valid URI")] + #[error("Not a valid URI")] InvalidUri, - #[error(display = "Set account token on factory with no access token store")] + #[error("Set account token on factory with no access token store")] NoAccessTokenStore, } diff --git a/mullvad-cli/Cargo.toml b/mullvad-cli/Cargo.toml index 13f3878a14..516296eef0 100644 --- a/mullvad-cli/Cargo.toml +++ b/mullvad-cli/Cargo.toml @@ -18,7 +18,7 @@ path = "src/main.rs" anyhow = "1.0" chrono = { workspace = true } clap = { workspace = true } -err-derive = { workspace = true } +thiserror = { workspace = true } futures = "0.3" itertools = "0.10" natord = "1.0.9" diff --git a/mullvad-cli/src/cmds/proxies.rs b/mullvad-cli/src/cmds/proxies.rs index 5c8a79ff6c..68ab1c036c 100644 --- a/mullvad-cli/src/cmds/proxies.rs +++ b/mullvad-cli/src/cmds/proxies.rs @@ -5,10 +5,10 @@ use talpid_types::net::{ Endpoint, TransportProtocol, }; -#[derive(err_derive::Error, Debug)] +#[derive(thiserror::Error, Debug)] pub enum Error { - #[error(display = "{}", _0)] - InvalidAuth(#[error(source)] talpid_types::net::proxy::Error), + #[error(transparent)] + InvalidAuth(#[from] talpid_types::net::proxy::Error), } #[derive(Args, Debug, Clone)] diff --git a/mullvad-daemon/Cargo.toml b/mullvad-daemon/Cargo.toml index a1f60672d6..c71a8ae07b 100644 --- a/mullvad-daemon/Cargo.toml +++ b/mullvad-daemon/Cargo.toml @@ -16,7 +16,7 @@ api-override = ["mullvad-api/api-override"] [dependencies] chrono = { workspace = true } -err-derive = { workspace = true } +thiserror = { workspace = true } fern = { version = "0.6", features = ["colored"] } futures = "0.3" once_cell = { workspace = true } diff --git a/mullvad-daemon/src/access_method.rs b/mullvad-daemon/src/access_method.rs index 793d82bb5c..bc843f529e 100644 --- a/mullvad-daemon/src/access_method.rs +++ b/mullvad-daemon/src/access_method.rs @@ -5,27 +5,27 @@ use mullvad_types::{ settings::Settings, }; -#[derive(err_derive::Error, Debug)] +#[derive(thiserror::Error, Debug)] pub enum Error { /// Can not add access method - #[error(display = "Cannot add custom access method")] + #[error("Cannot add custom access method")] Add, /// Can not find access method - #[error(display = "Cannot find custom access method {}", _0)] + #[error("Cannot find custom access method {0}")] NoSuchMethod(access_method::Id), /// Some error occured in the daemon's state of handling /// [`AccessMethodSetting`]s & [`ApiConnectionMode`]s - #[error(display = "Error occured when handling connection settings & details")] - ApiService(#[error(source)] api::Error), + #[error("Error occured when handling connection settings & details")] + ApiService(#[from] api::Error), /// A REST request failed - #[error(display = "Reset request failed")] - Rest(#[error(source)] rest::Error), + #[error("Reset request failed")] + Rest(#[from] rest::Error), /// Something went wrong in the [`access_method`](mod@access_method) module. - #[error(display = "Access method error")] - AccessMethod(#[error(source)] access_method::Error), + #[error("Access method error")] + AccessMethod(#[from] access_method::Error), /// Access methods settings error - #[error(display = "Settings error")] - Settings(#[error(source)] settings::Error), + #[error("Settings error")] + Settings(#[from] settings::Error), } impl<L> Daemon<L> diff --git a/mullvad-daemon/src/account_history.rs b/mullvad-daemon/src/account_history.rs index 1df9180f34..c03a84f0cc 100644 --- a/mullvad-daemon/src/account_history.rs +++ b/mullvad-daemon/src/account_history.rs @@ -10,20 +10,19 @@ use tokio::{ 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 = "Unable to open or read account history file")] - Read(#[error(source)] io::Error), + #[error("Unable to open or read account history file")] + Read(#[source] io::Error), - #[error(display = "Failed to serialize account history")] - Serialize(#[error(source)] serde_json::Error), + #[error("Failed to serialize account history")] + Serialize(#[source] serde_json::Error), - #[error(display = "Unable to write account history file")] - Write(#[error(source)] io::Error), + #[error("Unable to write account history file")] + Write(#[source] io::Error), - #[error(display = "Write task panicked or was cancelled")] - WriteCancelled(#[error(source)] tokio::task::JoinError), + #[error("Write task panicked or was cancelled")] + WriteCancelled(#[source] tokio::task::JoinError), } static ACCOUNT_HISTORY_FILE: &str = "account-history.json"; diff --git a/mullvad-daemon/src/api.rs b/mullvad-daemon/src/api.rs index ccdf9e7bf3..f31b46d548 100644 --- a/mullvad-daemon/src/api.rs +++ b/mullvad-daemon/src/api.rs @@ -97,16 +97,16 @@ pub struct ResolvedConnectionMode { /// Describes all the ways the daemon service which handles access methods can /// fail. -#[derive(err_derive::Error, Debug)] +#[derive(thiserror::Error, Debug)] pub enum Error { - #[error(display = "No access methods were provided.")] + #[error("No access methods were provided.")] NoAccessMethods, - #[error(display = "AccessModeSelector is not receiving any messages.")] - SendFailed(#[error(source)] mpsc::TrySendError<Message>), - #[error(display = "AccessModeSelector is not receiving any messages.")] + #[error("AccessModeSelector is not receiving any messages.")] + SendFailed(#[from] mpsc::TrySendError<Message>), + #[error("AccessModeSelector is not receiving any messages.")] OneshotSendFailed, - #[error(display = "AccessModeSelector is not responding.")] - NotRunning(#[error(source)] oneshot::Canceled), + #[error("AccessModeSelector is not responding.")] + NotRunning(#[from] oneshot::Canceled), } impl std::fmt::Display for Message { diff --git a/mullvad-daemon/src/cleanup.rs b/mullvad-daemon/src/cleanup.rs index 1f0cbdf309..3d9c688f47 100644 --- a/mullvad-daemon/src/cleanup.rs +++ b/mullvad-daemon/src/cleanup.rs @@ -3,30 +3,29 @@ use std::path::Path; use tokio::{fs, io}; -#[derive(err_derive::Error, Debug)] -#[error(no_from)] +#[derive(thiserror::Error, Debug)] pub enum Error { - #[error(display = "Failed to get path")] - Path(#[error(source)] mullvad_paths::Error), + #[error("Failed to get path")] + Path(#[source] mullvad_paths::Error), - #[error(display = "Failed to remove directory {}", _0)] - RemoveDir(String, #[error(source)] io::Error), + #[error("Failed to remove directory {0}")] + RemoveDir(String, #[source] io::Error), #[cfg(not(target_os = "windows"))] - #[error(display = "Failed to create directory {}", _0)] - CreateDir(String, #[error(source)] io::Error), + #[error("Failed to create directory {0}")] + CreateDir(String, #[source] io::Error), #[cfg(target_os = "windows")] - #[error(display = "Failed to get file type info")] - FileType(#[error(source)] io::Error), + #[error("Failed to get file type info")] + FileType(#[source] io::Error), #[cfg(target_os = "windows")] - #[error(display = "Failed to get dir entry")] - FileEntry(#[error(source)] io::Error), + #[error("Failed to get dir entry")] + FileEntry(#[source] io::Error), #[cfg(target_os = "windows")] - #[error(display = "Failed to read dir entries")] - ReadDir(#[error(source)] io::Error), + #[error("Failed to read dir entries")] + ReadDir(#[source] io::Error), } pub async fn clear_directories() -> Result<(), Error> { diff --git a/mullvad-daemon/src/device/mod.rs b/mullvad-daemon/src/device/mod.rs index 8f836d90d5..0493976a41 100644 --- a/mullvad-daemon/src/device/mod.rs +++ b/mullvad-daemon/src/device/mod.rs @@ -48,31 +48,31 @@ const LOGOUT_TIMEOUT: Duration = Duration::from_secs(2); /// a WireGuard tunnel. const WG_DEVICE_CHECK_THRESHOLD: usize = 3; -#[derive(err_derive::Error, Debug, Clone)] +#[derive(thiserror::Error, Debug, Clone)] pub enum Error { - #[error(display = "The account already has a maximum number of devices")] + #[error("The account already has a maximum number of devices")] MaxDevicesReached, - #[error(display = "No device is set")] + #[error("No device is set")] NoDevice, - #[error(display = "Device not found")] + #[error("Device not found")] InvalidDevice, - #[error(display = "Invalid account")] + #[error("Invalid account")] InvalidAccount, - #[error(display = "Invalid voucher code")] + #[error("Invalid voucher code")] InvalidVoucher, - #[error(display = "The voucher has already been used")] + #[error("The voucher has already been used")] UsedVoucher, - #[error(display = "Failed to read or write device cache")] - DeviceIoError(#[error(source)] Arc<io::Error>), - #[error(display = "Failed parse device cache")] - ParseDeviceCache(#[error(source)] Arc<serde_json::Error>), - #[error(display = "Unexpected HTTP request error")] - OtherRestError(#[error(source)] rest::Error), - #[error(display = "The device update task is not running")] + #[error("Failed to read or write device cache")] + DeviceIoError(#[from] Arc<io::Error>), + #[error("Failed parse device cache")] + ParseDeviceCache(#[from] Arc<serde_json::Error>), + #[error("Unexpected HTTP request error")] + OtherRestError(#[from] rest::Error), + #[error("The device update task is not running")] Cancelled, - #[error(display = "Account changed during operation")] + #[error("Account changed during operation")] AccountChange, - #[error(display = "The account manager is down")] + #[error("The account manager is down")] AccountManagerDown, } diff --git a/mullvad-daemon/src/early_boot_firewall.rs b/mullvad-daemon/src/early_boot_firewall.rs index a5df67be0b..6195c15bb4 100644 --- a/mullvad-daemon/src/early_boot_firewall.rs +++ b/mullvad-daemon/src/early_boot_firewall.rs @@ -1,16 +1,16 @@ use mullvad_daemon::settings::{self, SettingsPersister}; use talpid_core::firewall::{self, Firewall, FirewallPolicy}; -#[derive(err_derive::Error, Debug)] +#[derive(thiserror::Error, Debug)] pub enum Error { - #[error(display = "Failed to initialize firewall")] - Firewall(#[error(source)] firewall::Error), + #[error("Failed to initialize firewall")] + Firewall(#[from] firewall::Error), - #[error(display = "Failed to get settings path")] - Path(#[error(source)] mullvad_paths::Error), + #[error("Failed to get settings path")] + Path(#[from] mullvad_paths::Error), - #[error(display = "Failed to get settings")] - Settings(#[error(source)] settings::Error), + #[error("Failed to get settings")] + Settings(#[from] settings::Error), } pub async fn initialize_firewall() -> Result<(), Error> { diff --git a/mullvad-daemon/src/exception_logging/win.rs b/mullvad-daemon/src/exception_logging/win.rs index 85f16019b0..b33a188a32 100644 --- a/mullvad-daemon/src/exception_logging/win.rs +++ b/mullvad-daemon/src/exception_logging/win.rs @@ -60,13 +60,12 @@ extern "system" { ) -> BOOL; } -#[derive(err_derive::Error, Debug)] -#[error(no_from)] +#[derive(thiserror::Error, Debug)] enum MinidumpError { - #[error(display = "Failed to create mini dump file")] - CreateFileError(#[error(source)] io::Error), - #[error(display = "Failed to produce mini dump and write it to disk")] - GenerateError(#[error(source)] io::Error), + #[error("Failed to create mini dump file")] + CreateFileError(#[source] io::Error), + #[error("Failed to produce mini dump and write it to disk")] + GenerateError(#[source] io::Error), } fn generate_minidump( diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs index 55d1fed16e..6ffd696890 100644 --- a/mullvad-daemon/src/lib.rs +++ b/mullvad-daemon/src/lib.rs @@ -94,108 +94,107 @@ const WG_RECONNECT_DELAY: Duration = Duration::from_secs(4 * 60); pub type ResponseTx<T, E> = oneshot::Sender<Result<T, E>>; -#[derive(err_derive::Error, Debug)] -#[error(no_from)] +#[derive(thiserror::Error, Debug)] pub enum Error { - #[error(display = "Failed to send command to daemon because it is not running")] + #[error("Failed to send command to daemon because it is not running")] DaemonUnavailable, - #[error(display = "Unable to initialize network event loop")] - InitIoEventLoop(#[error(source)] io::Error), + #[error("Unable to initialize network event loop")] + InitIoEventLoop(#[source] io::Error), - #[error(display = "Unable to create RPC client")] - InitRpcFactory(#[error(source)] mullvad_api::Error), + #[error("Unable to create RPC client")] + InitRpcFactory(#[source] mullvad_api::Error), - #[error(display = "REST request failed")] - RestError(#[error(source)] mullvad_api::rest::Error), + #[error("REST request failed")] + RestError(#[source] mullvad_api::rest::Error), - #[error(display = "API availability check failed")] - ApiCheckError(#[error(source)] mullvad_api::availability::Error), + #[error("API availability check failed")] + ApiCheckError(#[source] mullvad_api::availability::Error), - #[error(display = "Unable to load account history")] - LoadAccountHistory(#[error(source)] account_history::Error), + #[error("Unable to load account history")] + LoadAccountHistory(#[source] account_history::Error), - #[error(display = "Failed to start account manager")] - LoadAccountManager(#[error(source)] device::Error), + #[error("Failed to start account manager")] + LoadAccountManager(#[source] device::Error), - #[error(display = "Failed to log in to account")] - LoginError(#[error(source)] device::Error), + #[error("Failed to log in to account")] + LoginError(#[source] device::Error), - #[error(display = "Failed to log out of account")] - LogoutError(#[error(source)] device::Error), + #[error("Failed to log out of account")] + LogoutError(#[source] device::Error), - #[error(display = "Failed to rotate WireGuard key")] - KeyRotationError(#[error(source)] device::Error), + #[error("Failed to rotate WireGuard key")] + KeyRotationError(#[source] device::Error), - #[error(display = "Failed to list devices")] - ListDevicesError(#[error(source)] device::Error), + #[error("Failed to list devices")] + ListDevicesError(#[source] device::Error), - #[error(display = "Failed to remove device")] - RemoveDeviceError(#[error(source)] device::Error), + #[error("Failed to remove device")] + RemoveDeviceError(#[source] device::Error), - #[error(display = "Failed to update device")] - UpdateDeviceError(#[error(source)] device::Error), + #[error("Failed to update device")] + UpdateDeviceError(#[source] device::Error), - #[error(display = "Failed to submit voucher")] - VoucherSubmission(#[error(source)] device::Error), + #[error("Failed to submit voucher")] + VoucherSubmission(#[source] device::Error), #[cfg(target_os = "linux")] - #[error(display = "Unable to initialize split tunneling")] - InitSplitTunneling(#[error(source)] split_tunnel::Error), + #[error("Unable to initialize split tunneling")] + InitSplitTunneling(#[source] split_tunnel::Error), #[cfg(windows)] - #[error(display = "Split tunneling error")] - SplitTunnelError(#[error(source)] split_tunnel::Error), + #[error("Split tunneling error")] + SplitTunnelError(#[source] split_tunnel::Error), - #[error(display = "An account is already set")] + #[error("An account is already set")] AlreadyLoggedIn, - #[error(display = "No account token is set")] + #[error("No account token is set")] NoAccountToken, - #[error(display = "No account history available for the token")] + #[error("No account history available for the token")] NoAccountTokenHistory, - #[error(display = "Settings error")] - SettingsError(#[error(source)] settings::Error), + #[error("Settings error")] + SettingsError(#[source] settings::Error), - #[error(display = "Account history error")] - AccountHistory(#[error(source)] account_history::Error), + #[error("Account history error")] + AccountHistory(#[source] account_history::Error), #[cfg(not(target_os = "android"))] - #[error(display = "Factory reset partially failed: {}", _0)] + #[error("Factory reset partially failed: {0}")] FactoryResetError(&'static str), - #[error(display = "Tunnel state machine error")] - TunnelError(#[error(source)] tunnel_state_machine::Error), + #[error("Tunnel state machine error")] + TunnelError(#[source] tunnel_state_machine::Error), /// Custom list already exists - #[error(display = "A list with that name already exists")] + #[error("A list with that name already exists")] CustomListExists, /// Custom list does not exist - #[error(display = "A list with that name does not exist")] + #[error("A list with that name does not exist")] CustomListNotFound, - #[error(display = "Access method error")] - AccessMethodError(#[error(source)] access_method::Error), + #[error("Access method error")] + AccessMethodError(#[source] access_method::Error), - #[error(display = "API connection mode error")] - ApiConnectionModeError(#[error(source)] api::Error), - #[error(display = "No custom bridge has been specified")] + #[error("API connection mode error")] + ApiConnectionModeError(#[source] api::Error), + #[error("No custom bridge has been specified")] NoCustomProxySaved, #[cfg(target_os = "macos")] - #[error(display = "Failed to set exclusion group")] - GroupIdError(#[error(source)] io::Error), + #[error("Failed to set exclusion group")] + GroupIdError(#[source] io::Error), #[cfg(target_os = "android")] - #[error(display = "Failed to initialize play purchase")] - InitPlayPurchase(#[error(source)] device::Error), + #[error("Failed to initialize play purchase")] + InitPlayPurchase(#[source] device::Error), #[cfg(target_os = "android")] - #[error(display = "Failed to verify play purchase")] - VerifyPlayPurchase(#[error(source)] device::Error), + #[error("Failed to verify play purchase")] + VerifyPlayPurchase(#[source] device::Error), } /// Enum representing commands that can be sent to the daemon. diff --git a/mullvad-daemon/src/logging.rs b/mullvad-daemon/src/logging.rs index 719f273528..c31c9b868c 100644 --- a/mullvad-daemon/src/logging.rs +++ b/mullvad-daemon/src/logging.rs @@ -5,21 +5,21 @@ use fern::{ use std::{fmt, io, path::PathBuf}; use talpid_core::logging::rotate_log; -#[derive(err_derive::Error, Debug)] +#[derive(thiserror::Error, Debug)] pub enum Error { /// Unable to open log file for writing - #[error(display = "Unable to open log file for writing: {}", path)] + #[error("Unable to open log file for writing: {path}")] WriteFile { path: String, - #[error(source)] + #[source] source: io::Error, }, - #[error(display = "Unable to rotate daemon log file")] - RotateLog(#[error(source)] talpid_core::logging::RotateLogError), + #[error("Unable to rotate daemon log file")] + RotateLog(#[from] talpid_core::logging::RotateLogError), - #[error(display = "Unable to set logger")] - SetLoggerError(#[error(source)] log::SetLoggerError), + #[error("Unable to set logger")] + SetLoggerError(#[from] log::SetLoggerError), } pub const WARNING_SILENCED_CRATES: &[&str] = &["netlink_proto"]; diff --git a/mullvad-daemon/src/management_interface.rs b/mullvad-daemon/src/management_interface.rs index 41736f3f38..ee0fadaa0e 100644 --- a/mullvad-daemon/src/management_interface.rs +++ b/mullvad-daemon/src/management_interface.rs @@ -31,12 +31,11 @@ use std::{ use talpid_types::ErrorExt; use tokio_stream::wrappers::UnboundedReceiverStream; -#[derive(err_derive::Error, Debug)] -#[error(no_from)] +#[derive(thiserror::Error, Debug)] pub enum Error { // Unable to start the management interface server - #[error(display = "Unable to start management interface server")] - SetupError(#[error(source)] mullvad_management_interface::Error), + #[error("Unable to start management interface server")] + SetupError(#[source] mullvad_management_interface::Error), } struct ManagementServiceImpl { diff --git a/mullvad-daemon/src/migrations/mod.rs b/mullvad-daemon/src/migrations/mod.rs index f5a54867b2..05672d56a7 100644 --- a/mullvad-daemon/src/migrations/mod.rs +++ b/mullvad-daemon/src/migrations/mod.rs @@ -55,42 +55,41 @@ mod v7; const SETTINGS_FILE: &str = "settings.json"; -#[derive(err_derive::Error, Debug)] -#[error(no_from)] +#[derive(thiserror::Error, Debug)] pub enum Error { - #[error(display = "Failed to read the settings")] - Read(#[error(source)] io::Error), + #[error("Failed to read the settings")] + Read(#[source] io::Error), - #[error(display = "Failed to deserialize settings")] - Deserialize(#[error(source)] serde_json::Error), + #[error("Failed to deserialize settings")] + Deserialize(#[source] serde_json::Error), - #[error(display = "Unexpected settings format")] + #[error("Unexpected settings format")] InvalidSettingsContent, - #[error(display = "Unable to serialize settings to JSON")] - Serialize(#[error(source)] serde_json::Error), + #[error("Unable to serialize settings to JSON")] + Serialize(#[source] serde_json::Error), - #[error(display = "Unable to open settings for writing")] - Open(#[error(source)] io::Error), + #[error("Unable to open settings for writing")] + Open(#[source] io::Error), - #[error(display = "Unable to write new settings")] - Write(#[error(source)] io::Error), + #[error("Unable to write new settings")] + Write(#[source] io::Error), - #[error(display = "Unable to sync settings to disk")] - SyncSettings(#[error(source)] io::Error), + #[error("Unable to sync settings to disk")] + SyncSettings(#[source] io::Error), - #[error(display = "Failed to read the account history")] - ReadHistory(#[error(source)] io::Error), + #[error("Failed to read the account history")] + ReadHistory(#[source] io::Error), - #[error(display = "Failed to write new account history")] - WriteHistory(#[error(source)] io::Error), + #[error("Failed to write new account history")] + WriteHistory(#[source] io::Error), - #[error(display = "Failed to parse account history")] + #[error("Failed to parse account history")] ParseHistory, #[cfg(windows)] - #[error(display = "Failed to restore Windows update backup")] - WinMigration(#[error(source)] windows::Error), + #[error("Failed to restore Windows update backup")] + WinMigration(#[source] windows::Error), } pub type Result<T> = std::result::Result<T, Error>; @@ -226,20 +225,19 @@ mod windows { ("account-history.json", false), ]; - #[derive(err_derive::Error, Debug)] - #[error(no_from)] + #[derive(thiserror::Error, Debug)] pub enum Error { - #[error(display = "Unable to find local appdata directory")] + #[error("Unable to find local appdata directory")] FindAppData, - #[error(display = "Could not acquire security descriptor of backup directory")] - SecurityInformation(#[error(source)] io::Error), + #[error("Could not acquire security descriptor of backup directory")] + SecurityInformation(#[source] io::Error), - #[error(display = "Backup directory is not owned by SYSTEM or Built-in Administrators")] + #[error("Backup directory is not owned by SYSTEM or Built-in Administrators")] WrongOwner, - #[error(display = "Failed to copy files during migration")] - Io(#[error(source)] io::Error), + #[error("Failed to copy files during migration")] + Io(#[source] io::Error), } /// Attempts to restore the Mullvad settings from `C:\windows.old` after an update of Windows. diff --git a/mullvad-daemon/src/settings/mod.rs b/mullvad-daemon/src/settings/mod.rs index 4cae48a24f..abd6ea2e0a 100644 --- a/mullvad-daemon/src/settings/mod.rs +++ b/mullvad-daemon/src/settings/mod.rs @@ -20,26 +20,25 @@ pub mod patch; const SETTINGS_FILE: &str = "settings.json"; -#[derive(err_derive::Error, Debug)] -#[error(no_from)] +#[derive(thiserror::Error, Debug)] pub enum Error { - #[error(display = "Unable to read settings file {}", _0)] - ReadError(String, #[error(source)] io::Error), + #[error("Unable to read settings file {0}")] + ReadError(String, #[source] io::Error), - #[error(display = "Unable to parse settings file")] - ParseError(#[error(source)] serde_json::Error), + #[error("Unable to parse settings file")] + ParseError(#[source] serde_json::Error), - #[error(display = "Unable to remove settings file {}", _0)] + #[error("Unable to remove settings file {0}")] #[cfg(not(target_os = "android"))] - DeleteError(String, #[error(source)] io::Error), + DeleteError(String, #[source] io::Error), - #[error(display = "Unable to serialize settings to JSON")] - SerializeError(#[error(source)] serde_json::Error), + #[error("Unable to serialize settings to JSON")] + SerializeError(#[source] serde_json::Error), - #[error(display = "Unable to write settings to {}", _0)] - WriteError(String, #[error(source)] io::Error), + #[error("Unable to write settings to {0}")] + WriteError(String, #[source] io::Error), - #[error(display = "Failed to apply settings update")] + #[error("Failed to apply settings update")] UpdateFailed(Box<dyn std::error::Error + Send + Sync>), } @@ -274,9 +273,9 @@ impl SettingsPersister { /// to inspect the error closer. /// /// ```ignore - /// #[derive(Debug, err_derive::Error)] + /// #[derive(Debug, thiserror::Error)] /// pub enum MyError { - /// #[error(display = "Failed for this reason: {:?}", _0)] + /// #[error("Failed for this reason: {0:?}")] /// Failed(String), /// } /// diff --git a/mullvad-daemon/src/settings/patch.rs b/mullvad-daemon/src/settings/patch.rs index ad4826812b..094b66d4d0 100644 --- a/mullvad-daemon/src/settings/patch.rs +++ b/mullvad-daemon/src/settings/patch.rs @@ -18,33 +18,32 @@ use super::SettingsPersister; use mullvad_types::settings::Settings; -#[derive(err_derive::Error, Debug)] -#[error(no_from)] +#[derive(thiserror::Error, Debug)] pub enum Error { /// Missing expected JSON object - #[error(display = "Incorrect or missing value: {}", _0)] + #[error("Incorrect or missing value: {0}")] InvalidOrMissingValue(&'static str), /// Unknown or prohibited key - #[error(display = "Invalid or prohibited key: {}", _0)] + #[error("Invalid or prohibited key: {0}")] UnknownOrProhibitedKey(String), /// Failed to parse patch json - #[error(display = "Failed to parse settings patch")] - ParsePatch(#[error(source)] serde_json::Error), + #[error("Failed to parse settings patch")] + ParsePatch(#[source] serde_json::Error), /// Failed to deserialize patched settings - #[error(display = "Failed to deserialize patched settings")] - DeserializePatched(#[error(source)] serde_json::Error), + #[error("Failed to deserialize patched settings")] + DeserializePatched(#[source] serde_json::Error), /// Failed to serialize settings - #[error(display = "Failed to serialize current settings")] - SerializeSettings(#[error(source)] serde_json::Error), + #[error("Failed to serialize current settings")] + SerializeSettings(#[source] serde_json::Error), /// Failed to serialize field - #[error(display = "Failed to serialize value")] - SerializeValue(#[error(source)] serde_json::Error), + #[error("Failed to serialize value")] + SerializeValue(#[source] serde_json::Error), /// Recursion limit reached - #[error(display = "Maximum JSON object depth reached")] + #[error("Maximum JSON object depth reached")] RecursionLimit, /// Settings error - #[error(display = "Settings error")] - Settings(#[error(source)] super::Error), + #[error("Settings error")] + Settings(#[source] super::Error), } /// Converts an [Error] to a management interface status diff --git a/mullvad-daemon/src/shutdown.rs b/mullvad-daemon/src/shutdown.rs index 920648ffe4..2e7473b34f 100644 --- a/mullvad-daemon/src/shutdown.rs +++ b/mullvad-daemon/src/shutdown.rs @@ -14,9 +14,9 @@ mod platform { #[cfg(windows)] mod platform { - #[derive(err_derive::Error, Debug)] - #[error(display = "Unable to attach ctrl-c handler")] - pub struct Error(#[error(source)] ctrlc::Error); + #[derive(thiserror::Error, Debug)] + #[error("Unable to attach ctrl-c handler")] + pub struct Error(#[from] ctrlc::Error); pub fn set_shutdown_signal_handler(f: impl Fn() + 'static + Send) -> Result<(), Error> { ctrlc::set_handler(move || { diff --git a/mullvad-daemon/src/system_service.rs b/mullvad-daemon/src/system_service.rs index 07eb791584..21b881d1e0 100644 --- a/mullvad-daemon/src/system_service.rs +++ b/mullvad-daemon/src/system_service.rs @@ -318,14 +318,13 @@ fn accepted_controls_by_state(state: ServiceState) -> ServiceControlAccept { } } -#[derive(err_derive::Error, Debug)] -#[error(no_from)] +#[derive(thiserror::Error, Debug)] pub enum InstallError { - #[error(display = "Unable to connect to service manager")] - ConnectServiceManager(#[error(source)] windows_service::Error), + #[error("Unable to connect to service manager")] + ConnectServiceManager(#[source] windows_service::Error), - #[error(display = "Unable to create a service")] - CreateService(#[error(source)] windows_service::Error), + #[error("Unable to create a service")] + CreateService(#[source] windows_service::Error), } pub fn install_service() -> Result<(), InstallError> { diff --git a/mullvad-daemon/src/tunnel.rs b/mullvad-daemon/src/tunnel.rs index a19c81740c..2094838173 100644 --- a/mullvad-daemon/src/tunnel.rs +++ b/mullvad-daemon/src/tunnel.rs @@ -37,18 +37,18 @@ static SAME_IP_V6: Lazy<IpAddr> = Lazy::new(|| { .into() }); -#[derive(err_derive::Error, Debug)] +#[derive(thiserror::Error, Debug)] pub enum Error { - #[error(display = "Not logged in on a valid device")] + #[error("Not logged in on a valid device")] NoAuthDetails, - #[error(display = "No relay available")] + #[error("No relay available")] NoRelayAvailable, - #[error(display = "No bridge available")] + #[error("No bridge available")] NoBridgeAvailable, - #[error(display = "Failed to resolve hostname for custom relay")] + #[error("Failed to resolve hostname for custom relay")] ResolveCustomHostname, } diff --git a/mullvad-daemon/src/version_check.rs b/mullvad-daemon/src/version_check.rs index 69d2d61643..afb1d7bee8 100644 --- a/mullvad-daemon/src/version_check.rs +++ b/mullvad-daemon/src/version_check.rs @@ -60,34 +60,33 @@ impl From<AppVersionInfo> for CachedAppVersionInfo { } } -#[derive(err_derive::Error, Debug)] -#[error(no_from)] +#[derive(thiserror::Error, Debug)] pub enum Error { - #[error(display = "Failed to open app version cache file for reading")] - ReadVersionCache(#[error(source)] io::Error), + #[error("Failed to open app version cache file for reading")] + ReadVersionCache(#[source] io::Error), - #[error(display = "Failed to open app version cache file for writing")] - WriteVersionCache(#[error(source)] io::Error), + #[error("Failed to open app version cache file for writing")] + WriteVersionCache(#[source] io::Error), - #[error(display = "Failure in serialization of the version info")] - Serialize(#[error(source)] serde_json::Error), + #[error("Failure in serialization of the version info")] + Serialize(#[source] serde_json::Error), - #[error(display = "Failure in deserialization of the version info")] - Deserialize(#[error(source)] serde_json::Error), + #[error("Failure in deserialization of the version info")] + Deserialize(#[source] serde_json::Error), - #[error(display = "Failed to check the latest app version")] - Download(#[error(source)] mullvad_api::rest::Error), + #[error("Failed to check the latest app version")] + Download(#[source] mullvad_api::rest::Error), - #[error(display = "API availability check failed")] - ApiCheck(#[error(source)] mullvad_api::availability::Error), + #[error("API availability check failed")] + ApiCheck(#[source] mullvad_api::availability::Error), - #[error(display = "Clearing version check cache due to a version mismatch")] + #[error("Clearing version check cache due to a version mismatch")] CacheVersionMismatch, - #[error(display = "Version updater is down")] + #[error("Version updater is down")] VersionUpdaterDown, - #[error(display = "Version cache update was aborted")] + #[error("Version cache update was aborted")] UpdateAborted, } diff --git a/mullvad-exclude/Cargo.toml b/mullvad-exclude/Cargo.toml index 127fa7d1bb..e758aae58e 100644 --- a/mullvad-exclude/Cargo.toml +++ b/mullvad-exclude/Cargo.toml @@ -12,5 +12,5 @@ workspace = true [target.'cfg(target_os = "linux")'.dependencies] nix = "0.23" -err-derive = { workspace = true } +thiserror = { workspace = true } talpid-types = { path = "../talpid-types" } diff --git a/mullvad-exclude/src/main.rs b/mullvad-exclude/src/main.rs index 9135a6d292..238446875d 100644 --- a/mullvad-exclude/src/main.rs +++ b/mullvad-exclude/src/main.rs @@ -20,31 +20,30 @@ use talpid_types::cgroup::{find_net_cls_mount, SPLIT_TUNNEL_CGROUP_NAME}; const PROGRAM_NAME: &str = "mullvad-exclude"; #[cfg(target_os = "linux")] -#[derive(err_derive::Error, Debug)] -#[error(no_from)] +#[derive(thiserror::Error, Debug)] enum Error { - #[error(display = "Invalid arguments")] + #[error("Invalid arguments")] InvalidArguments, - #[error(display = "Cannot set the cgroup")] - AddProcToCGroup(#[error(source)] io::Error), + #[error("Cannot set the cgroup")] + AddProcToCGroup(#[source] io::Error), - #[error(display = "Failed to drop root user privileges for the process")] - DropRootUid(#[error(source)] nix::Error), + #[error("Failed to drop root user privileges for the process")] + DropRootUid(#[source] nix::Error), - #[error(display = "Failed to drop root group privileges for the process")] - DropRootGid(#[error(source)] nix::Error), + #[error("Failed to drop root group privileges for the process")] + DropRootGid(#[source] nix::Error), - #[error(display = "Failed to launch the process")] - Exec(#[error(source)] nix::Error), + #[error("Failed to launch the process")] + Exec(#[source] nix::Error), - #[error(display = "An argument contains interior nul bytes")] - ArgumentNul(#[error(source)] NulError), + #[error("An argument contains interior nul bytes")] + ArgumentNul(#[source] NulError), - #[error(display = "Failed to find net_cls controller")] - FindNetClsController(#[error(source)] io::Error), + #[error("Failed to find net_cls controller")] + FindNetClsController(#[source] io::Error), - #[error(display = "No net_cls controller")] + #[error("No net_cls controller")] NoNetClsController, } diff --git a/mullvad-jni/Cargo.toml b/mullvad-jni/Cargo.toml index ad6f9b59c9..9458a75327 100644 --- a/mullvad-jni/Cargo.toml +++ b/mullvad-jni/Cargo.toml @@ -18,7 +18,7 @@ api-override = ["mullvad-api/api-override"] crate_type = ["cdylib"] [target.'cfg(target_os = "android")'.dependencies] -err-derive = { workspace = true } +thiserror = { workspace = true } futures = "0.3" ipnetwork = "0.16" jnix = { version = "0.5.1", features = ["derive"] } diff --git a/mullvad-jni/src/daemon_interface.rs b/mullvad-jni/src/daemon_interface.rs index 7abd35cf5b..66cc8c3eb2 100644 --- a/mullvad-jni/src/daemon_interface.rs +++ b/mullvad-jni/src/daemon_interface.rs @@ -13,26 +13,25 @@ use mullvad_types::{ wireguard::QuantumResistantState, }; -#[derive(Debug, err_derive::Error)] -#[error(no_from)] +#[derive(Debug, thiserror::Error)] pub enum Error { - #[error(display = "Can't send command to daemon because it is not running")] - NoDaemon(#[error(source)] mullvad_daemon::Error), + #[error("Can't send command to daemon because it is not running")] + NoDaemon(#[source] mullvad_daemon::Error), - #[error(display = "No response received from daemon")] + #[error("No response received from daemon")] NoResponse, - #[error(display = "Attempt to use daemon command sender before it was configured")] + #[error("Attempt to use daemon command sender before it was configured")] NoSender, - #[error(display = "Error performing RPC with the remote API")] - Api(#[error(source)] mullvad_api::rest::Error), + #[error("Error performing RPC with the remote API")] + Api(#[source] mullvad_api::rest::Error), - #[error(display = "Failed to update settings")] + #[error("Failed to update settings")] UpdateSettings, - #[error(display = "Daemon returned an error")] - Other(#[error(source)] mullvad_daemon::Error), + #[error("Daemon returned an error")] + Other(#[source] mullvad_daemon::Error), } impl From<mullvad_daemon::Error> for Error { diff --git a/mullvad-jni/src/jni_event_listener.rs b/mullvad-jni/src/jni_event_listener.rs index 4567622975..ce6317262e 100644 --- a/mullvad-jni/src/jni_event_listener.rs +++ b/mullvad-jni/src/jni_event_listener.rs @@ -17,17 +17,16 @@ use mullvad_types::{ use std::{sync::mpsc, thread}; use talpid_types::ErrorExt; -#[derive(Debug, err_derive::Error)] -#[error(no_from)] +#[derive(Debug, thiserror::Error)] pub enum Error { - #[error(display = "Failed to create global reference to MullvadDaemon Java object")] - CreateGlobalReference(#[error(source)] jnix::jni::errors::Error), + #[error("Failed to create global reference to MullvadDaemon Java object")] + CreateGlobalReference(#[source] jnix::jni::errors::Error), - #[error(display = "Failed to find {} method", _0)] - FindMethod(&'static str, #[error(source)] jnix::jni::errors::Error), + #[error("Failed to find {0} method")] + FindMethod(&'static str, #[source] jnix::jni::errors::Error), - #[error(display = "Failed to retrieve Java VM instance")] - GetJvmInstance(#[error(source)] jnix::jni::errors::Error), + #[error("Failed to retrieve Java VM instance")] + GetJvmInstance(#[source] jnix::jni::errors::Error), } enum Event { diff --git a/mullvad-jni/src/lib.rs b/mullvad-jni/src/lib.rs index 1416fd70b5..e70027b68b 100644 --- a/mullvad-jni/src/lib.rs +++ b/mullvad-jni/src/lib.rs @@ -48,23 +48,22 @@ static LOAD_CLASSES: Once = Once::new(); static LOG_START: Once = Once::new(); static mut LOG_INIT_RESULT: Option<Result<(), String>> = None; -#[derive(Debug, err_derive::Error)] -#[error(no_from)] +#[derive(Debug, thiserror::Error)] pub enum Error { - #[error(display = "Failed to create global reference to Java object")] - CreateGlobalReference(#[error(cause)] jnix::jni::errors::Error), + #[error("Failed to create global reference to Java object")] + CreateGlobalReference(#[source] jnix::jni::errors::Error), - #[error(display = "Failed to get Java VM instance")] - GetJvmInstance(#[error(cause)] jnix::jni::errors::Error), + #[error("Failed to get Java VM instance")] + GetJvmInstance(#[source] jnix::jni::errors::Error), - #[error(display = "Failed to initialize the mullvad daemon")] - InitializeDaemon(#[error(source)] mullvad_daemon::Error), + #[error("Failed to initialize the mullvad daemon")] + InitializeDaemon(#[source] mullvad_daemon::Error), - #[error(display = "Failed to spawn the tokio runtime")] - InitializeTokioRuntime(#[error(source)] io::Error), + #[error("Failed to spawn the tokio runtime")] + InitializeTokioRuntime(#[source] io::Error), - #[error(display = "Failed to spawn the JNI event listener")] - SpawnJniEventListener(#[error(source)] jni_event_listener::Error), + #[error("Failed to spawn the JNI event listener")] + SpawnJniEventListener(#[source] jni_event_listener::Error), } #[derive(IntoJava)] diff --git a/mullvad-jni/src/talpid_vpn_service.rs b/mullvad-jni/src/talpid_vpn_service.rs index ba4f8a3470..d54e1ad671 100644 --- a/mullvad-jni/src/talpid_vpn_service.rs +++ b/mullvad-jni/src/talpid_vpn_service.rs @@ -21,15 +21,15 @@ use std::{ use talpid_tunnel::tun_provider::TunConfig; use talpid_types::ErrorExt; -#[derive(Debug, err_derive::Error)] +#[derive(Debug, thiserror::Error)] enum Error { - #[error(display = "Failed to verify the tunnel device")] - VerifyTunDevice(#[error(source)] SendRandomDataError), + #[error("Failed to verify the tunnel device")] + VerifyTunDevice(#[from] SendRandomDataError), - #[error(display = "Failed to select() on tunnel device")] - Select(#[error(source)] nix::Error), + #[error("Failed to select() on tunnel device")] + Select(#[from] nix::Error), - #[error(display = "Timed out while waiting for tunnel device to receive data")] + #[error("Timed out while waiting for tunnel device to receive data")] TunnelDeviceTimeout, } @@ -82,14 +82,13 @@ fn wait_for_tunnel_up(tun_fd: RawFd, is_ipv6_enabled: bool) -> Result<(), Error> Err(Error::TunnelDeviceTimeout) } -#[derive(Debug, err_derive::Error)] -#[error(no_from)] +#[derive(Debug, thiserror::Error)] enum SendRandomDataError { - #[error(display = "Failed to bind an UDP socket")] - BindUdpSocket(#[error(source)] io::Error), + #[error("Failed to bind an UDP socket")] + BindUdpSocket(#[source] io::Error), - #[error(display = "Failed to send random data through UDP socket")] - SendToUdpSocket(#[error(source)] io::Error), + #[error("Failed to send random data through UDP socket")] + SendToUdpSocket(#[source] io::Error), } fn try_sending_random_udp(is_ipv6_enabled: bool) -> Result<(), SendRandomDataError> { diff --git a/mullvad-management-interface/Cargo.toml b/mullvad-management-interface/Cargo.toml index cf0c29eeff..352b1e631c 100644 --- a/mullvad-management-interface/Cargo.toml +++ b/mullvad-management-interface/Cargo.toml @@ -12,7 +12,7 @@ workspace = true [dependencies] chrono = { workspace = true } -err-derive = { workspace = true } +thiserror = { workspace = true } mullvad-types = { path = "../mullvad-types" } mullvad-paths = { path = "../mullvad-paths" } talpid-types = { path = "../talpid-types" } diff --git a/mullvad-management-interface/src/lib.rs b/mullvad-management-interface/src/lib.rs index c9414d03bf..882db86ae1 100644 --- a/mullvad-management-interface/src/lib.rs +++ b/mullvad-management-interface/src/lib.rs @@ -29,85 +29,84 @@ static MULLVAD_MANAGEMENT_SOCKET_GROUP: Lazy<Option<String>> = pub const CUSTOM_LIST_LIST_NOT_FOUND_DETAILS: &[u8] = b"custom_list_list_not_found"; pub const CUSTOM_LIST_LIST_EXISTS_DETAILS: &[u8] = b"custom_list_list_exists"; -#[derive(err_derive::Error, Debug)] -#[error(no_from)] +#[derive(thiserror::Error, Debug)] pub enum Error { - #[error(display = "Management RPC server or client error")] - GrpcTransportError(#[error(source)] tonic::transport::Error), + #[error("Management RPC server or client error")] + GrpcTransportError(#[source] tonic::transport::Error), - #[error(display = "Failed to start IPC pipe/socket")] - StartServerError(#[error(source)] io::Error), + #[error("Failed to start IPC pipe/socket")] + StartServerError(#[source] io::Error), - #[error(display = "Failed to initialize pipe/socket security attributes")] - SecurityAttributes(#[error(source)] io::Error), + #[error("Failed to initialize pipe/socket security attributes")] + SecurityAttributes(#[source] io::Error), - #[error(display = "Unable to set permissions for IPC endpoint")] - PermissionsError(#[error(source)] io::Error), + #[error("Unable to set permissions for IPC endpoint")] + PermissionsError(#[source] io::Error), #[cfg(unix)] - #[error(display = "Group not found")] + #[error("Group not found")] NoGidError, #[cfg(unix)] - #[error(display = "Failed to obtain group ID")] - ObtainGidError(#[error(source)] nix::Error), + #[error("Failed to obtain group ID")] + ObtainGidError(#[source] nix::Error), #[cfg(unix)] - #[error(display = "Failed to set group ID")] - SetGidError(#[error(source)] nix::Error), + #[error("Failed to set group ID")] + SetGidError(#[source] nix::Error), - #[error(display = "gRPC call returned error")] - Rpc(#[error(source)] tonic::Status), + #[error("gRPC call returned error")] + Rpc(#[source] tonic::Status), - #[error(display = "Failed to parse gRPC response")] - InvalidResponse(#[error(source)] types::FromProtobufTypeError), + #[error("Failed to parse gRPC response")] + InvalidResponse(#[source] types::FromProtobufTypeError), - #[error(display = "Duration is too large")] + #[error("Duration is too large")] DurationTooLarge, - #[error(display = "Unexpected non-UTF8 string")] + #[error("Unexpected non-UTF8 string")] PathMustBeUtf8, - #[error(display = "Missing daemon event")] + #[error("Missing daemon event")] MissingDaemonEvent, - #[error(display = "This voucher code is invalid")] + #[error("This voucher code is invalid")] InvalidVoucher, - #[error(display = "This voucher code has already been used")] + #[error("This voucher code has already been used")] UsedVoucher, - #[error(display = "There are too many devices on the account. One must be revoked to log in")] + #[error("There are too many devices on the account. One must be revoked to log in")] TooManyDevices, - #[error(display = "You are already logged in. Log out to create a new account")] + #[error("You are already logged in. Log out to create a new account")] AlreadyLoggedIn, - #[error(display = "The account does not exist")] + #[error("The account does not exist")] InvalidAccount, - #[error(display = "There is no such device")] + #[error("There is no such device")] DeviceNotFound, - #[error(display = "Location data is unavailable")] + #[error("Location data is unavailable")] NoLocationData, - #[error(display = "A custom list with that name already exists")] + #[error("A custom list with that name already exists")] CustomListExists, - #[error(display = "A custom list with that name does not exist")] + #[error("A custom list with that name does not exist")] CustomListListNotFound, - #[error(display = "Location already exists in the custom list")] + #[error("Location already exists in the custom list")] LocationExistsInCustomList, - #[error(display = "Location was not found in the custom list")] + #[error("Location was not found in the custom list")] LocationNotFoundInCustomlist, - #[error(display = "Could not retrieve API access methods from settings")] + #[error("Could not retrieve API access methods from settings")] ApiAccessMethodSettingsNotFound, - #[error(display = "An access method with that id does not exist")] + #[error("An access method with that id does not exist")] ApiAccessMethodNotFound, } diff --git a/mullvad-management-interface/src/types/conversions/mod.rs b/mullvad-management-interface/src/types/conversions/mod.rs index 4c2151270f..02281846c3 100644 --- a/mullvad-management-interface/src/types/conversions/mod.rs +++ b/mullvad-management-interface/src/types/conversions/mod.rs @@ -16,9 +16,9 @@ mod states; mod version; mod wireguard; -#[derive(err_derive::Error, Debug)] +#[derive(thiserror::Error, Debug)] pub enum FromProtobufTypeError { - #[error(display = "Invalid argument for type conversion: {}", _0)] + #[error("Invalid argument for type conversion: {0}")] InvalidArgument(&'static str), } diff --git a/mullvad-paths/Cargo.toml b/mullvad-paths/Cargo.toml index 49391ac9b8..32f47efdaa 100644 --- a/mullvad-paths/Cargo.toml +++ b/mullvad-paths/Cargo.toml @@ -11,7 +11,7 @@ rust-version.workspace = true workspace = true [dependencies] -err-derive = { workspace = true } +thiserror = { workspace = true } [target.'cfg(not(target_os="android"))'.dependencies] log = { workspace = true } diff --git a/mullvad-paths/src/lib.rs b/mullvad-paths/src/lib.rs index 4fe401016b..8bfc27f4ff 100644 --- a/mullvad-paths/src/lib.rs +++ b/mullvad-paths/src/lib.rs @@ -7,29 +7,29 @@ use crate::windows::create_dir_recursive; 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 create directory {}", _0)] - CreateDirFailed(String, #[error(source)] io::Error), + #[error("Failed to create directory {0}")] + CreateDirFailed(String, #[source] io::Error), - #[error(display = "Failed to set directory permissions on {}", _0)] - SetDirPermissionFailed(String, #[error(source)] io::Error), + #[error("Failed to set directory permissions on {0}")] + SetDirPermissionFailed(String, #[source] io::Error), #[cfg(any(windows, target_os = "macos"))] - #[error(display = "Not able to find requested directory")] + #[error("Not able to find requested directory")] FindDirError, #[cfg(windows)] - #[error(display = "Missing %ALLUSERSPROFILE% environment variable")] + #[error("Missing %ALLUSERSPROFILE% environment variable")] NoProgramDataDir, #[cfg(windows)] - #[error(display = "Failed to create security attributes")] - GetSecurityAttributes(#[error(source)] io::Error), + #[error("Failed to create security attributes")] + GetSecurityAttributes(#[source] io::Error), #[cfg(all(windows, feature = "deduce-system-service"))] - #[error(display = "Failed to deduce system service directory")] - FailedToFindSystemServiceDir(#[error(source)] io::Error), + #[error("Failed to deduce system service directory")] + FailedToFindSystemServiceDir(#[source] io::Error), } #[cfg(any(target_os = "linux", target_os = "macos"))] diff --git a/mullvad-problem-report/Cargo.toml b/mullvad-problem-report/Cargo.toml index c5ef788670..53cc7a9d51 100644 --- a/mullvad-problem-report/Cargo.toml +++ b/mullvad-problem-report/Cargo.toml @@ -12,7 +12,7 @@ workspace = true [dependencies] dirs = "5.0.1" -err-derive = { workspace = true } +thiserror = { workspace = true } once_cell = { workspace = true } log = { workspace = true } regex = "1.0" diff --git a/mullvad-problem-report/src/lib.rs b/mullvad-problem-report/src/lib.rs index 05502bcc46..fc8306a8f1 100644 --- a/mullvad-problem-report/src/lib.rs +++ b/mullvad-problem-report/src/lib.rs @@ -44,63 +44,62 @@ macro_rules! write_line { /// These are critical errors that can happen when using the tool, that stops /// it from working. Meaning it will print the error and exit. -#[derive(err_derive::Error, Debug)] -#[error(no_from)] +#[derive(thiserror::Error, Debug)] pub enum Error { - #[error(display = "Failed to write the problem report to {}", path)] + #[error("Failed to write the problem report to {path}")] WriteReportError { path: String, - #[error(source)] + #[source] source: io::Error, }, - #[error(display = "Failed to read the problem report at {}", path)] + #[error("Failed to read the problem report at {path}")] ReadProblemReportError { path: String, - #[error(source)] + #[source] source: io::Error, }, - #[error(display = "Unable to create REST client")] - CreateRpcClientError(#[error(source)] mullvad_api::Error), + #[error("Unable to create REST client")] + CreateRpcClientError(#[source] mullvad_api::Error), - #[error(display = "Failed to send problem report")] - SendProblemReportError(#[error(source)] mullvad_api::rest::Error), + #[error("Failed to send problem report")] + SendProblemReportError(#[source] mullvad_api::rest::Error), - #[error(display = "Failed to send problem report {} times", MAX_SEND_ATTEMPTS)] + #[error("Failed to send problem report {} times", MAX_SEND_ATTEMPTS)] SendFailedTooManyTimes, - #[error(display = "Unable to spawn Tokio runtime")] - CreateRuntime(#[error(source)] io::Error), + #[error("Unable to spawn Tokio runtime")] + CreateRuntime(#[source] io::Error), - #[error(display = "Unable to find cache directory")] - ObtainCacheDirectory(#[error(source)] mullvad_paths::Error), + #[error("Unable to find cache directory")] + ObtainCacheDirectory(#[source] mullvad_paths::Error), } /// These are errors that can happen during problem report collection. /// They are not critical, but they will be added inside the problem report, /// instead of whatever content was supposed to be there. -#[derive(err_derive::Error, Debug)] +#[derive(thiserror::Error, Debug)] pub enum LogError { - #[error(display = "Unable to get log directory")] - GetLogDir(#[error(source)] mullvad_paths::Error), + #[error("Unable to get log directory")] + GetLogDir(#[source] mullvad_paths::Error), - #[error(display = "Failed to list the files in the log directory: {}", path)] + #[error("Failed to list the files in the log directory: {path}")] ListLogDir { path: String, - #[error(source)] + #[source] source: io::Error, }, - #[error(display = "Error reading the contents of log file: {}", path)] + #[error("Error reading the contents of log file: {path}")] ReadLogError { path: String }, #[cfg(any(target_os = "linux", target_os = "macos"))] - #[error(display = "No home directory for current user")] + #[error("No home directory for current user")] NoHomeDir, #[cfg(target_os = "windows")] - #[error(display = "Missing %LOCALAPPDATA% environment variable")] + #[error("Missing %LOCALAPPDATA% environment variable")] NoLocalAppDataDir, } diff --git a/mullvad-relay-selector/Cargo.toml b/mullvad-relay-selector/Cargo.toml index e38b44bd13..c5f83018ea 100644 --- a/mullvad-relay-selector/Cargo.toml +++ b/mullvad-relay-selector/Cargo.toml @@ -12,7 +12,7 @@ workspace = true [dependencies] chrono = { workspace = true } -err-derive = { workspace = true } +thiserror = { workspace = true } ipnetwork = "0.16" log = { workspace = true } rand = "0.8.5" diff --git a/mullvad-relay-selector/src/lib.rs b/mullvad-relay-selector/src/lib.rs index 196f0c8eef..b255ef9105 100644 --- a/mullvad-relay-selector/src/lib.rs +++ b/mullvad-relay-selector/src/lib.rs @@ -52,32 +52,31 @@ const MIN_BRIDGE_COUNT: usize = 5; /// Max distance of bridges to consider for selection (km). const MAX_BRIDGE_DISTANCE: f64 = 1500f64; -#[derive(err_derive::Error, Debug)] -#[error(no_from)] +#[derive(thiserror::Error, Debug)] pub enum Error { - #[error(display = "Failed to open relay cache file")] - OpenRelayCache(#[error(source)] io::Error), + #[error("Failed to open relay cache file")] + OpenRelayCache(#[source] io::Error), - #[error(display = "Failed to write relay cache file to disk")] - WriteRelayCache(#[error(source)] io::Error), + #[error("Failed to write relay cache file to disk")] + WriteRelayCache(#[source] io::Error), - #[error(display = "No relays matching current constraints")] + #[error("No relays matching current constraints")] NoRelay, - #[error(display = "No bridges matching current constraints")] + #[error("No bridges matching current constraints")] NoBridge, - #[error(display = "No obfuscators matching current constraints")] + #[error("No obfuscators matching current constraints")] NoObfuscator, - #[error(display = "Failure in serialization of the relay list")] - Serialize(#[error(source)] serde_json::Error), + #[error("Failure in serialization of the relay list")] + Serialize(#[source] serde_json::Error), - #[error(display = "Downloader already shut down")] + #[error("Downloader already shut down")] DownloaderShutDown, - #[error(display = "Invalid bridge settings")] - InvalidBridgeSettings(#[error(source)] MissingCustomBridgeSettings), + #[error("Invalid bridge settings")] + InvalidBridgeSettings(#[source] MissingCustomBridgeSettings), } struct ParsedRelays { diff --git a/mullvad-setup/Cargo.toml b/mullvad-setup/Cargo.toml index bb602303db..f8a8239f43 100644 --- a/mullvad-setup/Cargo.toml +++ b/mullvad-setup/Cargo.toml @@ -17,7 +17,7 @@ path = "src/main.rs" [dependencies] clap = { workspace = true } env_logger = { workspace = true } -err-derive = { workspace = true } +thiserror = { workspace = true } once_cell = { workspace = true } mullvad-management-interface = { path = "../mullvad-management-interface" } diff --git a/mullvad-setup/src/main.rs b/mullvad-setup/src/main.rs index 6155f0eaa9..34155fbb71 100644 --- a/mullvad-setup/src/main.rs +++ b/mullvad-setup/src/main.rs @@ -31,40 +31,39 @@ impl From<Error> for ExitStatus { } } -#[derive(err_derive::Error, Debug)] -#[error(no_from)] +#[derive(thiserror::Error, Debug)] pub enum Error { - #[error(display = "Failed to connect to RPC client")] - RpcConnectionError(#[error(source)] mullvad_management_interface::Error), + #[error("Failed to connect to RPC client")] + RpcConnectionError(#[source] mullvad_management_interface::Error), - #[error(display = "RPC call failed")] - DaemonRpcError(#[error(source)] mullvad_management_interface::Error), + #[error("RPC call failed")] + DaemonRpcError(#[source] mullvad_management_interface::Error), - #[error(display = "This command cannot be run if the daemon is active")] + #[error("This command cannot be run if the daemon is active")] DaemonIsRunning, - #[error(display = "Firewall error")] - FirewallError(#[error(source)] firewall::Error), + #[error("Firewall error")] + FirewallError(#[source] firewall::Error), - #[error(display = "Failed to initialize mullvad RPC runtime")] - RpcInitializationError(#[error(source)] mullvad_api::Error), + #[error("Failed to initialize mullvad RPC runtime")] + RpcInitializationError(#[source] mullvad_api::Error), - #[error(display = "Failed to remove device from account")] - RemoveDeviceError(#[error(source)] mullvad_api::rest::Error), + #[error("Failed to remove device from account")] + RemoveDeviceError(#[source] mullvad_api::rest::Error), - #[error(display = "Failed to obtain settings directory path")] - SettingsPathError(#[error(source)] mullvad_paths::Error), + #[error("Failed to obtain settings directory path")] + SettingsPathError(#[source] mullvad_paths::Error), - #[error(display = "Failed to obtain cache directory path")] - CachePathError(#[error(source)] mullvad_paths::Error), + #[error("Failed to obtain cache directory path")] + CachePathError(#[source] mullvad_paths::Error), - #[error(display = "Failed to read the device cache")] - ReadDeviceCacheError(#[error(source)] mullvad_daemon::device::Error), + #[error("Failed to read the device cache")] + ReadDeviceCacheError(#[source] mullvad_daemon::device::Error), - #[error(display = "Failed to write the device cache")] - WriteDeviceCacheError(#[error(source)] mullvad_daemon::device::Error), + #[error("Failed to write the device cache")] + WriteDeviceCacheError(#[source] mullvad_daemon::device::Error), - #[error(display = "Cannot parse the version string")] + #[error("Cannot parse the version string")] ParseVersionStringError, } diff --git a/mullvad-types/Cargo.toml b/mullvad-types/Cargo.toml index 64d2f25a69..8b614dd182 100644 --- a/mullvad-types/Cargo.toml +++ b/mullvad-types/Cargo.toml @@ -12,7 +12,7 @@ workspace = true [dependencies] chrono = { workspace = true, features = ["clock", "serde"] } -err-derive = { workspace = true } +thiserror = { workspace = true } ipnetwork = "0.16" once_cell = { workspace = true } log = { workspace = true } diff --git a/mullvad-types/src/access_method.rs b/mullvad-types/src/access_method.rs index fb365101be..c5f0b41859 100644 --- a/mullvad-types/src/access_method.rs +++ b/mullvad-types/src/access_method.rs @@ -140,10 +140,10 @@ impl Default for Settings { } } -#[derive(err_derive::Error, Debug)] +#[derive(thiserror::Error, Debug)] pub enum Error { /// Built-in access methods can not be removed - #[error(display = "Cannot remove built-in access method {}", attempted)] + #[error("Cannot remove built-in access method {}", attempted)] RemoveBuiltin { attempted: BuiltInAccessMethod }, } diff --git a/mullvad-types/src/custom_tunnel.rs b/mullvad-types/src/custom_tunnel.rs index 09298c49e0..53c84179bc 100644 --- a/mullvad-types/src/custom_tunnel.rs +++ b/mullvad-types/src/custom_tunnel.rs @@ -8,12 +8,12 @@ use std::{ }; use talpid_types::net::{openvpn, proxy::CustomProxy, wireguard, Endpoint, TunnelParameters}; -#[derive(err_derive::Error, Debug)] +#[derive(thiserror::Error, Debug)] pub enum Error { - #[error(display = "Invalid host/domain: {}", _0)] - InvalidHost(String, #[error(source)] io::Error), + #[error("Invalid host/domain: {0}")] + InvalidHost(String, #[source] io::Error), - #[error(display = "Host has no IPv4 address: {}", _0)] + #[error("Host has no IPv4 address: {0}")] HostHasNoIpv4(String), } diff --git a/mullvad-types/src/relay_constraints.rs b/mullvad-types/src/relay_constraints.rs index 0669d8bd8b..dfdf462ced 100644 --- a/mullvad-types/src/relay_constraints.rs +++ b/mullvad-types/src/relay_constraints.rs @@ -647,8 +647,8 @@ impl FromStr for Ownership { /// Returned when `Ownership::from_str` fails to convert a string into a /// [`Ownership`] object. -#[derive(err_derive::Error, Debug, Clone, PartialEq, Eq)] -#[error(display = "Not a valid ownership setting")] +#[derive(thiserror::Error, Debug, Clone, PartialEq, Eq)] +#[error("Not a valid ownership setting")] pub struct OwnershipParseError; /// Limits the set of [`crate::relay_list::Relay`]s used by a `RelaySelector` based on @@ -851,8 +851,8 @@ impl fmt::Display for BridgeType { } } -#[derive(err_derive::Error, Debug)] -#[error(display = "Missing custom bridge settings")] +#[derive(thiserror::Error, Debug)] +#[error("Missing custom bridge settings")] pub struct MissingCustomBridgeSettings(()); /// Specifies a specific endpoint or [`BridgeConstraints`] to use when `mullvad-daemon` selects a diff --git a/mullvad-types/src/wireguard.rs b/mullvad-types/src/wireguard.rs index db1d44f4d5..3bfe7f79f2 100644 --- a/mullvad-types/src/wireguard.rs +++ b/mullvad-types/src/wireguard.rs @@ -51,8 +51,8 @@ impl FromStr for QuantumResistantState { /// Returned when `QuantumResistantState::from_str` fails to convert a string into a /// [`QuantumResistantState`] object. -#[derive(err_derive::Error, Debug, Clone, PartialEq, Eq)] -#[error(display = "Not a valid state")] +#[derive(thiserror::Error, Debug, Clone, PartialEq, Eq)] +#[error("Not a valid state")] pub struct QuantumResistantStateParseError; /// Contains account specific wireguard data diff --git a/talpid-core/Cargo.toml b/talpid-core/Cargo.toml index 2256efedd6..dcd0c5af4c 100644 --- a/talpid-core/Cargo.toml +++ b/talpid-core/Cargo.toml @@ -12,7 +12,7 @@ workspace = true [dependencies] chrono = { workspace = true, features = ["clock"] } -err-derive = { workspace = true } +thiserror = { workspace = true } futures = "0.3.15" ipnetwork = "0.16" libc = "0.2" 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, } diff --git a/talpid-dbus/Cargo.toml b/talpid-dbus/Cargo.toml index 46f226e7e7..b81af13602 100644 --- a/talpid-dbus/Cargo.toml +++ b/talpid-dbus/Cargo.toml @@ -11,7 +11,7 @@ workspace = true [target.'cfg(target_os = "linux")'.dependencies] dbus = "0.9" -err-derive = { workspace = true } +thiserror = { workspace = true } once_cell = { workspace = true } log = { workspace = true } libc = "0.2" diff --git a/talpid-dbus/src/network_manager.rs b/talpid-dbus/src/network_manager.rs index 7cddb33981..b2787bf4a2 100644 --- a/talpid-dbus/src/network_manager.rs +++ b/talpid-dbus/src/network_manager.rs @@ -61,51 +61,50 @@ const NM_DEVICE_STATE_CHANGED: &str = "StateChanged"; pub type Result<T> = std::result::Result<T, Error>; type NetworkSettings<'a> = HashMap<String, HashMap<String, Variant<Box<dyn RefArg + 'a>>>>; -#[derive(err_derive::Error, Debug)] +#[derive(thiserror::Error, Debug)] pub enum Error { - #[error(display = "Error while communicating over Dbus")] - Dbus(#[error(source)] dbus::Error), + #[error("Error while communicating over Dbus")] + Dbus(#[from] dbus::Error), - #[error(display = "Failed to match the returned D-Bus object with expected type")] - MatchDBusTypeError(#[error(source)] dbus::arg::TypeMismatchError), + #[error("Failed to match the returned D-Bus object with expected type")] + MatchDBusTypeError(#[from] dbus::arg::TypeMismatchError), #[error( - display = "NM is configured to manage DNS via systemd-resolved but systemd-resolved is not managing /etc/resolv.conf: {}", - _0 + "NM is configured to manage DNS via systemd-resolved but systemd-resolved is not managing /etc/resolv.conf: {0}", )] SystemdResolvedNotManagingResolvconf(systemd_resolved::Error), - #[error(display = "Configuration has no device associated to it")] + #[error("Configuration has no device associated to it")] NoDevice, - #[error(display = "NetworkManager is too old: {}.{}", _0, _1)] + #[error("NetworkManager is too old: {0}.{1}")] NMTooOld(u32, u32), - #[error(display = "NetworkManager is too new to manage DNS: {}.{}", _0, _1)] + #[error("NetworkManager is too new to manage DNS: {0}.{1}")] NMTooNewFroDns(u32, u32), - #[error(display = "Failed to parse NetworkManager version string: {}", _0)] + #[error("Failed to parse NetworkManager version string: {0}")] ParseNmVersionError(String), - #[error(display = "Device inactive: {}", _0)] + #[error("Device inactive: {0}")] DeviceNotReady(u32), - #[error(display = "Device not found")] + #[error("Device not found")] DeviceNotFound, - #[error(display = "NetworkManager not detected")] + #[error("NetworkManager not detected")] NetworkManagerNotDetected, - #[error(display = "NetworkManager is using dnsmasq to manage DNS")] + #[error("NetworkManager is using dnsmasq to manage DNS")] UsingDnsmasq, - #[error(display = "NetworkManager is too old: {}", 0)] + #[error("NetworkManager is too old: {0}")] TooOldNetworkManager(String), - #[error(display = "NetworkManager is not managing DNS")] + #[error("NetworkManager is not managing DNS")] NetworkManagerNotManagingDns, - #[error(display = "Failed to get devices from NetworkManager object")] + #[error("Failed to get devices from NetworkManager object")] ObtainDevices, } diff --git a/talpid-dbus/src/systemd.rs b/talpid-dbus/src/systemd.rs index 521f2a1b8e..76e9823be6 100644 --- a/talpid-dbus/src/systemd.rs +++ b/talpid-dbus/src/systemd.rs @@ -3,14 +3,13 @@ use std::{sync::Arc, time::Duration}; 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 = "Failed to create a DBus connection")] - ConnectError(#[error(source)] dbus::Error), + #[error("Failed to create a DBus connection")] + ConnectError(#[source] dbus::Error), - #[error(display = "Failed to read SystemState property")] - ReadSystemStateError(#[error(source)] dbus::Error), + #[error("Failed to read SystemState property")] + ReadSystemStateError(#[source] dbus::Error), } const SYSTEMD_BUS: &str = "org.freedesktop.systemd1"; diff --git a/talpid-dbus/src/systemd_resolved.rs b/talpid-dbus/src/systemd_resolved.rs index 51de941990..f4defcee22 100644 --- a/talpid-dbus/src/systemd_resolved.rs +++ b/talpid-dbus/src/systemd_resolved.rs @@ -12,50 +12,49 @@ use std::{fs, io, net::IpAddr, path::Path, sync::Arc, time::Duration}; 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 = "Failed to initialize a connection to D-Bus")] - ConnectDBus(#[error(source)] dbus::Error), + #[error("Failed to initialize a connection to D-Bus")] + ConnectDBus(#[source] dbus::Error), - #[error(display = "Failed to read /etc/resolv.conf: _0")] - ReadResolvConfError(#[error(source)] io::Error), + #[error("Failed to read /etc/resolv.conf: {0}")] + ReadResolvConfError(#[source] io::Error), - #[error(display = "/etc/resolv.conf contents do not match systemd-resolved resolv.conf")] + #[error("/etc/resolv.conf contents do not match systemd-resolved resolv.conf")] ResolvConfDiffers, - #[error(display = "/etc/resolv.conf is not a symlink to Systemd resolved")] + #[error("/etc/resolv.conf is not a symlink to Systemd resolved")] NotSymlinkedToResolvConf, - #[error(display = "Static stub file does not point to localhost")] + #[error("Static stub file does not point to localhost")] StaticStubNotPointingToLocalhost, - #[error(display = "Systemd resolved not detected")] - NoSystemdResolved(#[error(source)] dbus::Error), + #[error("Systemd resolved not detected")] + NoSystemdResolved(#[source] dbus::Error), - #[error(display = "Failed to find link interface in resolved manager")] - GetLinkError(#[error(source)] Box<Error>), + #[error("Failed to find link interface in resolved manager")] + GetLinkError(#[source] Box<Error>), - #[error(display = "Failed to configure DNS domains")] - SetDomainsError(#[error(source)] dbus::Error), + #[error("Failed to configure DNS domains")] + SetDomainsError(#[source] dbus::Error), - #[error(display = "Failed to revert DNS settings of interface: {}", _0)] - RevertDnsError(String, #[error(source)] dbus::Error), + #[error("Failed to revert DNS settings of interface: {0}")] + RevertDnsError(String, #[source] dbus::Error), - #[error(display = "Failed to replace DNS settings")] + #[error("Failed to replace DNS settings")] ReplaceDnsError, - #[error(display = "Failed to perform RPC call on D-Bus")] - DBusRpcError(#[error(source)] dbus::Error), + #[error("Failed to perform RPC call on D-Bus")] + DBusRpcError(#[source] dbus::Error), - #[error(display = "Failed to add a match to listen for DNS config updates")] - DnsUpdateMatchError(#[error(source)] dbus::Error), + #[error("Failed to add a match to listen for DNS config updates")] + DnsUpdateMatchError(#[source] dbus::Error), - #[error(display = "Failed to remove a match for DNS config updates")] - DnsUpdateRemoveMatchError(#[error(source)] dbus::Error), + #[error("Failed to remove a match for DNS config updates")] + DnsUpdateRemoveMatchError(#[source] dbus::Error), - #[error(display = "Async D-Bus task failed")] - AsyncTaskError(#[error(source)] tokio::task::JoinError), + #[error("Async D-Bus task failed")] + AsyncTaskError(#[source] tokio::task::JoinError), } static RESOLVED_STUB_PATHS: Lazy<Vec<&'static Path>> = Lazy::new(|| { diff --git a/talpid-openvpn-plugin/Cargo.toml b/talpid-openvpn-plugin/Cargo.toml index a3d0d96ba2..972190f03c 100644 --- a/talpid-openvpn-plugin/Cargo.toml +++ b/talpid-openvpn-plugin/Cargo.toml @@ -14,7 +14,7 @@ workspace = true crate-type = ["cdylib"] [dependencies] -err-derive = { workspace = true } +thiserror = { workspace = true } log = { workspace = true } env_logger = { workspace = true } parity-tokio-ipc = "0.9" diff --git a/talpid-openvpn-plugin/src/lib.rs b/talpid-openvpn-plugin/src/lib.rs index f35a9a5d07..571991917d 100644 --- a/talpid-openvpn-plugin/src/lib.rs +++ b/talpid-openvpn-plugin/src/lib.rs @@ -5,28 +5,27 @@ use talpid_types::ErrorExt; mod processing; use crate::processing::EventProcessor; -#[derive(err_derive::Error, Debug)] -#[error(no_from)] +#[derive(thiserror::Error, Debug)] pub enum Error { - #[error(display = "No core server id given as first argument")] + #[error("No core server id given as first argument")] MissingCoreServerId, - #[error(display = "Failed to send an event to daemon over the IPC channel")] - SendEvent(#[error(source)] tonic::Status), + #[error("Failed to send an event to daemon over the IPC channel")] + SendEvent(#[source] tonic::Status), - #[error(display = "Unable to start Tokio runtime")] - CreateRuntime(#[error(source)] io::Error), + #[error("Unable to start Tokio runtime")] + CreateRuntime(#[source] io::Error), - #[error(display = "Unable to create IPC transport")] - CreateTransport(#[error(source)] tonic::transport::Error), + #[error("Unable to create IPC transport")] + CreateTransport(#[source] tonic::transport::Error), - #[error(display = "Unable to parse environment variables from OpenVPN")] - ParseEnvFailed(#[error(source)] std::str::Utf8Error), + #[error("Unable to parse environment variables from OpenVPN")] + ParseEnvFailed(#[source] std::str::Utf8Error), - #[error(display = "Unable to parse arguments from OpenVPN")] - ParseArgsFailed(#[error(source)] std::str::Utf8Error), + #[error("Unable to parse arguments from OpenVPN")] + ParseArgsFailed(#[source] std::str::Utf8Error), - #[error(display = "Unhandled event type: {:?}", _0)] + #[error("Unhandled event type: {0:?}")] UnhandledEvent(openvpn_plugin::EventType), } diff --git a/talpid-openvpn/Cargo.toml b/talpid-openvpn/Cargo.toml index 49e8a96675..c9341add9b 100644 --- a/talpid-openvpn/Cargo.toml +++ b/talpid-openvpn/Cargo.toml @@ -12,7 +12,7 @@ workspace = true [dependencies] async-trait = "0.1" -err-derive = { workspace = true } +thiserror = { workspace = true } futures = "0.3.15" once_cell = { workspace = true } log = { workspace = true } diff --git a/talpid-openvpn/src/lib.rs b/talpid-openvpn/src/lib.rs index 8bb09549d8..7426228812 100644 --- a/talpid-openvpn/src/lib.rs +++ b/talpid-openvpn/src/lib.rs @@ -56,73 +56,72 @@ const ADAPTER_GUID: GUID = GUID { pub type Result<T> = std::result::Result<T, Error>; /// Errors that can happen when using the OpenVPN tunnel. -#[derive(err_derive::Error, Debug)] -#[error(no_from)] +#[derive(thiserror::Error, Debug)] pub enum Error { /// Failed to initialize the tokio runtime. - #[error(display = "Failed to initialize the tokio runtime")] - RuntimeError(#[error(source)] io::Error), + #[error("Failed to initialize the tokio runtime")] + RuntimeError(#[source] io::Error), /// Unable to start, wait for or kill the OpenVPN process. - #[error(display = "Error in OpenVPN process management: {}", _0)] - ChildProcessError(&'static str, #[error(source)] io::Error), + #[error("Error in OpenVPN process management: {0}")] + ChildProcessError(&'static str, #[source] io::Error), /// Unable to start the IPC server. - #[error(display = "Unable to start the event dispatcher IPC server")] - EventDispatcherError(#[error(source)] event_server::Error), + #[error("Unable to start the event dispatcher IPC server")] + EventDispatcherError(#[source] event_server::Error), /// The OpenVPN event dispatcher exited unexpectedly - #[error(display = "The OpenVPN event dispatcher exited unexpectedly")] + #[error("The OpenVPN event dispatcher exited unexpectedly")] EventDispatcherExited, /// cannot load wintun.dll #[cfg(windows)] - #[error(display = "Failed to load wintun.dll")] - WintunDllError(#[error(source)] io::Error), + #[error("Failed to load wintun.dll")] + WintunDllError(#[source] io::Error), /// cannot create a wintun interface #[cfg(windows)] - #[error(display = "Failed to create Wintun adapter")] - WintunCreateAdapterError(#[error(source)] io::Error), + #[error("Failed to create Wintun adapter")] + WintunCreateAdapterError(#[source] io::Error), /// OpenVPN process died unexpectedly - #[error(display = "OpenVPN process died unexpectedly")] + #[error("OpenVPN process died unexpectedly")] ChildProcessDied, /// Failed before OpenVPN started - #[error(display = "Failed to start OpenVPN")] + #[error("Failed to start OpenVPN")] StartProcessError, /// The OpenVPN binary was not found. - #[error(display = "No OpenVPN binary found at {}", _0)] + #[error("No OpenVPN binary found at {0}")] OpenVpnNotFound(String), /// The OpenVPN plugin was not found. - #[error(display = "No OpenVPN plugin found at {}", _0)] + #[error("No OpenVPN plugin found at {0}")] PluginNotFound(String), /// Error while writing credentials to temporary file. - #[error(display = "Error while writing credentials to temporary file")] - CredentialsWriteError(#[error(source)] io::Error), + #[error("Error while writing credentials to temporary file")] + CredentialsWriteError(#[source] io::Error), /// Failures related to the proxy service. - #[error(display = "Proxy service failed")] - ProxyError(#[error(source)] proxy::Error), + #[error("Proxy service failed")] + ProxyError(#[source] proxy::Error), /// The map is missing 'dev' #[cfg(target_os = "linux")] - #[error(display = "Failed to obtain tunnel interface name")] + #[error("Failed to obtain tunnel interface name")] MissingTunnelInterface, /// The map has no 'route_n' entries #[cfg(target_os = "linux")] - #[error(display = "Failed to obtain OpenVPN server")] + #[error("Failed to obtain OpenVPN server")] MissingRemoteHost, /// Cannot parse the remote_n in the provided map #[cfg(target_os = "linux")] - #[error(display = "Cannot parse remote host string")] - ParseRemoteHost(#[error(source)] std::net::AddrParseError), + #[error("Cannot parse remote host string")] + ParseRemoteHost(#[source] std::net::AddrParseError), } impl Error { @@ -793,15 +792,15 @@ mod event_server { EventDetails, }; - #[derive(err_derive::Error, Debug)] + #[derive(thiserror::Error, Debug)] pub enum Error { /// Failure to set up the IPC server. - #[error(display = "Failed to create pipe or Unix socket")] - StartServer(#[error(source)] std::io::Error), + #[error("Failed to create pipe or Unix socket")] + StartServer(#[from] std::io::Error), /// An error occurred while the server was running. - #[error(display = "Tonic error")] - TonicError(#[error(source)] tonic::transport::Error), + #[error("Tonic error")] + TonicError(#[from] tonic::transport::Error), } /// Implements a gRPC service used to process events sent to by OpenVPN. diff --git a/talpid-openvpn/src/proxy/mod.rs b/talpid-openvpn/src/proxy/mod.rs index 6bc0fe92d5..b87e38206c 100644 --- a/talpid-openvpn/src/proxy/mod.rs +++ b/talpid-openvpn/src/proxy/mod.rs @@ -6,12 +6,12 @@ use async_trait::async_trait; use std::{fmt, io}; use talpid_types::net::proxy::CustomProxy; -#[derive(err_derive::Error, Debug)] +#[derive(thiserror::Error, Debug)] pub enum Error { - #[error(display = "Monitor exited unexpectedly: {}", _0)] + #[error("Monitor exited unexpectedly: {0}")] UnexpectedExit(String), - #[error(display = "I/O error")] + #[error("I/O error")] Io(io::Error), } diff --git a/talpid-routing/Cargo.toml b/talpid-routing/Cargo.toml index 26879a4687..cf2f3c9ade 100644 --- a/talpid-routing/Cargo.toml +++ b/talpid-routing/Cargo.toml @@ -11,7 +11,7 @@ rust-version.workspace = true workspace = true [dependencies] -err-derive = { workspace = true } +thiserror = { workspace = true } futures = "0.3.15" ipnetwork = "0.16" log = { workspace = true } diff --git a/talpid-routing/src/unix/android.rs b/talpid-routing/src/unix/android.rs index b8ee26e480..8abb23859b 100644 --- a/talpid-routing/src/unix/android.rs +++ b/talpid-routing/src/unix/android.rs @@ -2,8 +2,8 @@ use crate::imp::RouteManagerCommand; use futures::{channel::mpsc, stream::StreamExt}; /// Stub error type for routing errors on Android. -#[derive(Debug, err_derive::Error)] -#[error(display = "Failed to send shutdown result")] +#[derive(Debug, thiserror::Error)] +#[error("Failed to send shutdown result")] pub struct Error; /// Stub route manager for Android diff --git a/talpid-routing/src/unix/linux.rs b/talpid-routing/src/unix/linux.rs index 600ddd6794..785105ad56 100644 --- a/talpid-routing/src/unix/linux.rs +++ b/talpid-routing/src/unix/linux.rs @@ -85,47 +85,46 @@ fn no_fwmark_rule_v6(fwmark: u32, table: u32) -> RuleMessage { pub type Result<T> = std::result::Result<T, Error>; /// Errors that can happen in the Linux routing integration -#[derive(err_derive::Error, Debug)] -#[error(no_from)] +#[derive(thiserror::Error, Debug)] pub enum Error { - #[error(display = "Failed to open a netlink connection")] - Connect(#[error(source)] io::Error), + #[error("Failed to open a netlink connection")] + Connect(#[source] io::Error), - #[error(display = "Failed to bind netlink socket")] - Bind(#[error(source)] io::Error), + #[error("Failed to bind netlink socket")] + Bind(#[source] io::Error), - #[error(display = "Netlink error")] - Netlink(#[error(source)] rtnetlink::Error), + #[error("Netlink error")] + Netlink(#[source] rtnetlink::Error), - #[error(display = "Route without a valid node")] + #[error("Route without a valid node")] InvalidRoute, - #[error(display = "Invalid length of byte buffer for IP address")] + #[error("Invalid length of byte buffer for IP address")] InvalidIpBytes, - #[error(display = "Invalid network prefix")] - InvalidNetworkPrefix(#[error(source)] ipnetwork::IpNetworkError), + #[error("Invalid network prefix")] + InvalidNetworkPrefix(#[source] ipnetwork::IpNetworkError), - #[error(display = "Unknown device index: {}", _0)] + #[error("Unknown device index: {0}")] UnknownDeviceIndex(u32), - #[error(display = "Failed to get a route for the given IP address")] - GetRoute(#[error(source)] rtnetlink::Error), + #[error("Failed to get a route for the given IP address")] + GetRoute(#[source] rtnetlink::Error), - #[error(display = "No netlink response for route query")] + #[error("No netlink response for route query")] NoRoute, - #[error(display = "Route node was malformed")] + #[error("Route node was malformed")] InvalidRouteNode, - #[error(display = "No link found")] + #[error("No link found")] LinkNotFound, /// Unable to create routing table for tagged connections and packets. - #[error(display = "Cannot find a free routing table ID")] + #[error("Cannot find a free routing table ID")] NoFreeRoutingTableId, - #[error(display = "Shutting down route manager")] + #[error("Shutting down route manager")] Shutdown, } diff --git a/talpid-routing/src/unix/macos/mod.rs b/talpid-routing/src/unix/macos/mod.rs index f45d67c8d0..35220b45f8 100644 --- a/talpid-routing/src/unix/macos/mod.rs +++ b/talpid-routing/src/unix/macos/mod.rs @@ -31,27 +31,26 @@ const BURST_BUFFER_PERIOD: Duration = Duration::from_millis(200); const BURST_LONGEST_BUFFER_PERIOD: Duration = Duration::from_secs(2); /// Errors that can happen in the macOS routing integration. -#[derive(err_derive::Error, Debug)] -#[error(no_from)] +#[derive(thiserror::Error, Debug)] pub enum Error { /// Encountered an error when interacting with the routing socket - #[error(display = "Error occurred when interfacing with the routing table")] - RoutingTable(#[error(source)] watch::Error), + #[error("Error occurred when interfacing with the routing table")] + RoutingTable(#[source] watch::Error), /// Failed to remove route - #[error(display = "Error occurred when deleting a route")] - DeleteRoute(#[error(source)] watch::Error), + #[error("Error occurred when deleting a route")] + DeleteRoute(#[source] watch::Error), /// Failed to add route - #[error(display = "Error occurred when adding a route")] - AddRoute(#[error(source)] watch::Error), + #[error("Error occurred when adding a route")] + AddRoute(#[source] watch::Error), /// Failed to fetch link addresses - #[error(display = "Failed to fetch link addresses")] - FetchLinkAddresses(#[error(source)] std::io::Error), + #[error("Failed to fetch link addresses")] + FetchLinkAddresses(#[source] std::io::Error), /// Received message isn't valid - #[error(display = "Invalid data")] + #[error("Invalid data")] InvalidData(data::Error), } diff --git a/talpid-routing/src/unix/macos/routing_socket.rs b/talpid-routing/src/unix/macos/routing_socket.rs index ddd69bab2e..e82b8522aa 100644 --- a/talpid-routing/src/unix/macos/routing_socket.rs +++ b/talpid-routing/src/unix/macos/routing_socket.rs @@ -20,17 +20,17 @@ use super::data::{rt_msghdr_short, MessageType, RouteMessage}; use tokio::io::{unix::AsyncFd, AsyncWrite, AsyncWriteExt}; -#[derive(err_derive::Error, Debug)] +#[derive(thiserror::Error, Debug)] pub enum Error { - #[error(display = "Failed to open routing socket")] + #[error("Failed to open routing socket")] OpenSocket(io::Error), - #[error(display = "Failed to write to routing socket")] + #[error("Failed to write to routing socket")] Write(io::Error), - #[error(display = "Failed to read from routing socket")] + #[error("Failed to read from routing socket")] Read(io::Error), - #[error(display = "Received a message that's too small")] + #[error("Received a message that's too small")] MessageTooSmall(usize), - #[error(display = "Failed to receive response to route message")] + #[error("Failed to receive response to route message")] ResponseTimeout, } diff --git a/talpid-routing/src/unix/macos/watch.rs b/talpid-routing/src/unix/macos/watch.rs index d22a262e2c..20dc988086 100644 --- a/talpid-routing/src/unix/macos/watch.rs +++ b/talpid-routing/src/unix/macos/watch.rs @@ -7,28 +7,28 @@ use std::io; type Result<T> = std::result::Result<T, Error>; /// Errors that can occur for a PF_ROUTE socket -#[derive(Debug, err_derive::Error)] +#[derive(Debug, thiserror::Error)] pub enum Error { /// Generic routing socket error - #[error(display = "Routing socket error: {}", _0)] + #[error("Routing socket error: {0}")] RoutingSocket(routing_socket::Error), /// Failed to parse route message - #[error(display = "Invalid message")] + #[error("Invalid message")] InvalidMessage(data::Error), /// Failed to send route message - #[error(display = "Failed to send routing message")] + #[error("Failed to send routing message")] Send(routing_socket::Error), /// Received unexpected response to route message - #[error(display = "Unexpected message type")] + #[error("Unexpected message type")] UnexpectedMessageType(RouteSocketMessage, MessageType), /// Route not found - #[error(display = "Route not found")] + #[error("Route not found")] RouteNotFound, /// No route to destination - #[error(display = "Destination unreachable")] + #[error("Destination unreachable")] Unreachable, /// Failed to delete route - #[error(display = "Failed to delete a route")] + #[error("Failed to delete a route")] Deletion(RouteMessage), } diff --git a/talpid-routing/src/unix/mod.rs b/talpid-routing/src/unix/mod.rs index a0952e43be..45b7b92b60 100644 --- a/talpid-routing/src/unix/mod.rs +++ b/talpid-routing/src/unix/mod.rs @@ -33,22 +33,22 @@ mod imp; pub use imp::Error as PlatformError; /// Errors that can be encountered whilst initializing RouteManager -#[derive(err_derive::Error, Debug)] +#[derive(thiserror::Error, Debug)] pub enum Error { /// Route manager thread may have panicked - #[error(display = "The channel sender was dropped")] + #[error("The channel sender was dropped")] ManagerChannelDown, /// Platform specific error occurred - #[error(display = "Internal route manager error")] - PlatformError(#[error(source)] imp::Error), + #[error("Internal route manager error")] + PlatformError(#[from] imp::Error), /// Failed to spawn route manager future - #[error(display = "Failed to spawn route manager on the provided executor")] + #[error("Failed to spawn route manager on the provided executor")] FailedToSpawnManager, /// Failed to spawn route manager runtime - #[error(display = "Failed to spawn route manager runtime")] - FailedToSpawnRuntime(#[error(source)] io::Error), + #[error("Failed to spawn route manager runtime")] + FailedToSpawnRuntime(#[from] io::Error), /// Attempt to use route manager that has been dropped - #[error(display = "Cannot send message to route manager since it is down")] + #[error("Cannot send message to route manager since it is down")] RouteManagerDown, } diff --git a/talpid-routing/src/windows/mod.rs b/talpid-routing/src/windows/mod.rs index 7f30327cb0..055b4c2b68 100644 --- a/talpid-routing/src/windows/mod.rs +++ b/talpid-routing/src/windows/mod.rs @@ -19,75 +19,75 @@ mod get_best_default_route; mod route_manager; /// Windows routing errors. -#[derive(err_derive::Error, Debug)] +#[derive(thiserror::Error, Debug)] pub enum Error { /// The sender was dropped unexpectedly -- possible panic - #[error(display = "The channel sender was dropped")] + #[error("The channel sender was dropped")] ManagerChannelDown, /// Failure to initialize route manager - #[error(display = "Failed to start route manager")] + #[error("Failed to start route manager")] FailedToStartManager, /// Attempt to use route manager that has been dropped - #[error(display = "Cannot send message to route manager since it is down")] + #[error("Cannot send message to route manager since it is down")] RouteManagerDown, /// Low level error caused by a failure to add to route table - #[error(display = "Could not add route to route table")] + #[error("Could not add route to route table")] AddToRouteTable(io::Error), /// Low level error caused by failure to delete route from route table - #[error(display = "Failed to delete applied routes")] + #[error("Failed to delete applied routes")] DeleteFromRouteTable(io::Error), /// GetIpForwardTable2 windows API call failed - #[error(display = "Failed to retrieve the routing table")] + #[error("Failed to retrieve the routing table")] GetIpForwardTableFailed(io::Error), /// GetIfEntry2 windows API call failed - #[error(display = "Failed to retrieve network interface entry")] + #[error("Failed to retrieve network interface entry")] GetIfEntryFailed(io::Error), /// Low level error caused by failing to register the route callback - #[error(display = "Attempt to register notify route change callback failed")] + #[error("Attempt to register notify route change callback failed")] RegisterNotifyRouteCallback(io::Error), /// Low level error caused by failing to register the ip interface callback - #[error(display = "Attempt to register notify ip interface change callback failed")] + #[error("Attempt to register notify ip interface change callback failed")] RegisterNotifyIpInterfaceCallback(io::Error), /// Low level error caused by failing to register the unicast ip address callback - #[error(display = "Attempt to register notify unicast ip address change callback failed")] + #[error("Attempt to register notify unicast ip address change callback failed")] RegisterNotifyUnicastIpAddressCallback(io::Error), /// Low level error caused by windows Adapters API - #[error(display = "Windows adapter error")] + #[error("Windows adapter error")] Adapter(io::Error), /// High level error caused by a failure to clear the routes in the route manager. /// Contains the lower error - #[error(display = "Failed to clear applied routes")] + #[error("Failed to clear applied routes")] ClearRoutesFailed(Box<Error>), /// High level error caused by a failure to add routes in the route manager. /// Contains the lower error - #[error(display = "Failed to add routes")] + #[error("Failed to add routes")] AddRoutesFailed(Box<Error>), /// Something went wrong when getting the mtu of the interface - #[error(display = "Could not get the mtu of the interface")] + #[error("Could not get the mtu of the interface")] GetMtu, /// The SI family was of an unexpected value - #[error(display = "The SI family was of an unexpected value")] + #[error("The SI family was of an unexpected value")] InvalidSiFamily, /// Device name not found - #[error(display = "The device name was not found")] + #[error("The device name was not found")] DeviceNameNotFound, /// No default route - #[error(display = "No default route found")] + #[error("No default route found")] NoDefaultRoute, /// Conversion error between types - #[error(display = "Conversion error")] + #[error("Conversion error")] Conversion, /// Could not find device gateway - #[error(display = "Could not find device gateway")] + #[error("Could not find device gateway")] DeviceGatewayNotFound, /// Could not get default route - #[error(display = "Could not get default route")] + #[error("Could not get default route")] GetDefaultRoute, /// Could not find device by name - #[error(display = "Could not find device by name")] + #[error("Could not find device by name")] GetDeviceByName, /// Could not find device by gateway - #[error(display = "Could not find device by gateway")] + #[error("Could not find device by gateway")] GetDeviceByGateway, } diff --git a/talpid-tunnel/Cargo.toml b/talpid-tunnel/Cargo.toml index 8c4a64a769..3d6d8cc498 100644 --- a/talpid-tunnel/Cargo.toml +++ b/talpid-tunnel/Cargo.toml @@ -11,7 +11,7 @@ rust-version.workspace = true workspace = true [dependencies] -err-derive = { workspace = true } +thiserror = { workspace = true } cfg-if = "1.0" ipnetwork = "0.16" talpid-routing = { path = "../talpid-routing" } diff --git a/talpid-tunnel/src/tun_provider/android/mod.rs b/talpid-tunnel/src/tun_provider/android/mod.rs index 06ffac9aa9..187dd3b4f5 100644 --- a/talpid-tunnel/src/tun_provider/android/mod.rs +++ b/talpid-tunnel/src/tun_provider/android/mod.rs @@ -19,41 +19,33 @@ use std::{ use talpid_types::{android::AndroidContext, ErrorExt}; /// Errors that occur while setting up VpnService tunnel. -#[derive(Debug, err_derive::Error)] -#[error(no_from)] +#[derive(Debug, thiserror::Error)] pub enum Error { - #[error(display = "Failed to attach Java VM to tunnel thread")] - AttachJvmToThread(#[error(source)] jnix::jni::errors::Error), + #[error("Failed to attach Java VM to tunnel thread")] + AttachJvmToThread(#[source] jnix::jni::errors::Error), - #[error(display = "Failed to allow socket to bypass tunnel")] + #[error("Failed to allow socket to bypass tunnel")] Bypass, - #[error(display = "Failed to call Java method TalpidVpnService.{}", _0)] - CallMethod(&'static str, #[error(source)] jnix::jni::errors::Error), + #[error("Failed to call Java method TalpidVpnService.{0}")] + CallMethod(&'static str, #[source] jnix::jni::errors::Error), - #[error(display = "Failed to create Java VM handle clone")] - CloneJavaVm(#[error(source)] jnix::jni::errors::Error), + #[error("Failed to create Java VM handle clone")] + CloneJavaVm(#[source] jnix::jni::errors::Error), - #[error(display = "Failed to find TalpidVpnService.{} method", _0)] - FindMethod(&'static str, #[error(source)] jnix::jni::errors::Error), + #[error("Failed to find TalpidVpnService.{0} method")] + FindMethod(&'static str, #[source] jnix::jni::errors::Error), - #[error( - display = "Attempt to configure the tunnel with an invalid DNS server address(es): {:?}", - _0 - )] + #[error("Attempt to configure the tunnel with an invalid DNS server address(es): {0:?}")] InvalidDnsServers(Vec<IpAddr>), - #[error( - display = "Received an invalid result from TalpidVpnService.{}: {}", - _0, - _1 - )] + #[error("Received an invalid result from TalpidVpnService.{0}: {1}")] InvalidMethodResult(&'static str, String), - #[error(display = "Failed to create tunnel device")] + #[error("Failed to create tunnel device")] TunnelDeviceError, - #[error(display = "Permission denied when trying to create tunnel")] + #[error("Permission denied when trying to create tunnel")] PermissionDenied, } diff --git a/talpid-tunnel/src/tun_provider/unix.rs b/talpid-tunnel/src/tun_provider/unix.rs index 525e895d06..457f124f64 100644 --- a/talpid-tunnel/src/tun_provider/unix.rs +++ b/talpid-tunnel/src/tun_provider/unix.rs @@ -9,20 +9,19 @@ use std::{ use tun::{platform, Configuration, Device}; /// Errors that can occur while setting up a tunnel device. -#[derive(Debug, err_derive::Error)] -#[error(no_from)] +#[derive(Debug, thiserror::Error)] pub enum Error { /// Failure to create a tunnel device. - #[error(display = "Failed to create a tunnel device")] - CreateTunnelDevice(#[cause] NetworkInterfaceError), + #[error("Failed to create a tunnel device")] + CreateTunnelDevice(#[source] NetworkInterfaceError), /// Failure to set a tunnel device IP address. - #[error(display = "Failed to set tunnel IP address: {}", _0)] - SetIpAddr(IpAddr, #[cause] NetworkInterfaceError), + #[error("Failed to set tunnel IP address: {0}")] + SetIpAddr(IpAddr, #[source] NetworkInterfaceError), /// Failure to set the tunnel device as up. - #[error(display = "Failed to set the tunnel device as up")] - SetUp(#[cause] NetworkInterfaceError), + #[error("Failed to set the tunnel device as up")] + SetUp(#[source] NetworkInterfaceError), } /// Factory of tunnel devices on Unix systems. @@ -75,28 +74,27 @@ impl Deref for UnixTun { } /// Errors that can happen when working with *nix tunnel interfaces. -#[derive(err_derive::Error, Debug)] -#[error(no_from)] +#[derive(thiserror::Error, Debug)] pub enum NetworkInterfaceError { /// Failed to set IP address - #[error(display = "Failed to set IPv4 address")] - SetIpv4(#[error(source)] tun::Error), + #[error("Failed to set IPv4 address")] + SetIpv4(#[source] tun::Error), /// Failed to set IP address - #[error(display = "Failed to set IPv6 address")] - SetIpv6(#[error(source)] io::Error), + #[error("Failed to set IPv6 address")] + SetIpv6(#[source] io::Error), /// Unable to open a tunnel device - #[error(display = "Unable to open a tunnel device")] - CreateDevice(#[error(source)] tun::Error), + #[error("Unable to open a tunnel device")] + CreateDevice(#[source] tun::Error), /// Failed to apply async flags to tunnel device - #[error(display = "Failed to apply async flags to tunnel device")] - SetDeviceAsync(#[error(source)] nix::Error), + #[error("Failed to apply async flags to tunnel device")] + SetDeviceAsync(#[source] nix::Error), /// Failed to enable/disable link device - #[error(display = "Failed to enable/disable link device")] - ToggleDevice(#[error(source)] tun::Error), + #[error("Failed to enable/disable link device")] + ToggleDevice(#[source] tun::Error), } /// A trait for managing link devices diff --git a/talpid-types/Cargo.toml b/talpid-types/Cargo.toml index bf87b12ba0..c44001b4cd 100644 --- a/talpid-types/Cargo.toml +++ b/talpid-types/Cargo.toml @@ -15,7 +15,7 @@ serde = { version = "1.0", features = ["derive"] } ipnetwork = "0.16" base64 = "0.13" x25519-dalek = { version = "2.0.1", features = ["static_secrets", "zeroize", "getrandom"] } -err-derive = { workspace = true } +thiserror = { workspace = true } zeroize = "1.5.7" [target.'cfg(target_os = "android")'.dependencies] diff --git a/talpid-types/src/net/mod.rs b/talpid-types/src/net/mod.rs index 28fcf08a57..0c3a357432 100644 --- a/talpid-types/src/net/mod.rs +++ b/talpid-types/src/net/mod.rs @@ -161,8 +161,8 @@ impl FromStr for TunnelType { /// Returned when `TunnelType::from_str` fails to convert a string into a /// [`TunnelType`] object. -#[derive(err_derive::Error, Debug, Clone, PartialEq, Eq)] -#[error(display = "Not a valid tunnel protocol")] +#[derive(thiserror::Error, Debug, Clone, PartialEq, Eq)] +#[error("Not a valid tunnel protocol")] pub struct TunnelTypeParseError; /// A tunnel endpoint is broadcast during the connecting and connected states of the tunnel state @@ -450,8 +450,8 @@ impl FromStr for IpVersion { /// Returned when `IpVersion::from_str` fails to convert a string into a /// [`IpVersion`] object. -#[derive(err_derive::Error, Debug, Clone, PartialEq, Eq)] -#[error(display = "Not a valid IP protocol")] +#[derive(thiserror::Error, Debug, Clone, PartialEq, Eq)] +#[error("Not a valid IP protocol")] pub struct IpVersionParseError; /// Representation of a transport protocol, either UDP or TCP. @@ -491,8 +491,8 @@ impl fmt::Display for TransportProtocol { /// Returned when `TransportProtocol::from_str` fails to convert a string into a /// [`TransportProtocol`] object. -#[derive(err_derive::Error, Debug, Clone, PartialEq, Eq)] -#[error(display = "Not a valid transport protocol")] +#[derive(thiserror::Error, Debug, Clone, PartialEq, Eq)] +#[error("Not a valid transport protocol")] pub struct TransportProtocolParseError; /// Holds optional settings that can apply to different kinds of tunnels diff --git a/talpid-types/src/net/proxy.rs b/talpid-types/src/net/proxy.rs index f873d26c84..fc3333a69f 100644 --- a/talpid-types/src/net/proxy.rs +++ b/talpid-types/src/net/proxy.rs @@ -4,10 +4,10 @@ use std::{fmt, net::SocketAddr}; use super::TransportProtocol; -#[derive(err_derive::Error, Debug)] +#[derive(thiserror::Error, Debug)] pub enum Error { /// Validation of SOCKS5 username or password failed. - #[error(display = "Invalid SOCKS5 authentication credentials: {}", _0)] + #[error("Invalid SOCKS5 authentication credentials: {0}")] InvalidSocksAuthValues(&'static str), } diff --git a/talpid-types/src/net/wireguard.rs b/talpid-types/src/net/wireguard.rs index 2c79e2938b..db7b2da3a9 100644 --- a/talpid-types/src/net/wireguard.rs +++ b/talpid-types/src/net/wireguard.rs @@ -155,11 +155,11 @@ impl<'de> Deserialize<'de> for PrivateKey { pub struct PublicKey(x25519_dalek::PublicKey); /// Error returned if an input represents an invalid key -#[derive(Debug, err_derive::Error)] +#[derive(Debug, thiserror::Error)] pub enum InvalidKey { - #[error(display = "Invalid key: {}", _0)] - Format(#[error(source)] base64::DecodeError), - #[error(display = "Invalid key length: {}", _0)] + #[error("Invalid key: {0}")] + Format(#[from] base64::DecodeError), + #[error("Invalid key length: {0}")] Length(usize), } diff --git a/talpid-types/src/tunnel.rs b/talpid-types/src/tunnel.rs index ebd3121a86..6c85dcfb34 100644 --- a/talpid-types/src/tunnel.rs +++ b/talpid-types/src/tunnel.rs @@ -120,22 +120,22 @@ impl ErrorStateCause { } /// Errors that can occur when generating tunnel parameters. -#[derive(err_derive::Error, Debug, Serialize, Clone, Deserialize)] +#[derive(thiserror::Error, Debug, Serialize, Clone, Deserialize)] #[serde(rename_all = "snake_case")] #[cfg_attr(target_os = "android", derive(IntoJava))] #[cfg_attr(target_os = "android", jnix(package = "net.mullvad.talpid.tunnel"))] pub enum ParameterGenerationError { /// Failure to select a matching tunnel relay - #[error(display = "Failure to select a matching tunnel relay")] + #[error("Failure to select a matching tunnel relay")] NoMatchingRelay, /// Failure to select a matching bridge relay - #[error(display = "Failure to select a matching bridge relay")] + #[error("Failure to select a matching bridge relay")] NoMatchingBridgeRelay, /// Returned when tunnel parameters can't be generated because wireguard key is not available. - #[error(display = "No wireguard key available")] + #[error("No wireguard key available")] NoWireguardKey, /// Failure to resolve the hostname of a custom tunnel configuration - #[error(display = "Can't resolve hostname for custom tunnel host")] + #[error("Can't resolve hostname for custom tunnel host")] CustomTunnelHostResultionError, } @@ -148,18 +148,18 @@ pub struct BlockingApplication { } /// Errors that can occur when setting the firewall policy. -#[derive(err_derive::Error, Debug, Serialize, Clone, Deserialize)] +#[derive(thiserror::Error, Debug, Serialize, Clone, Deserialize)] #[serde(rename_all = "snake_case")] #[serde(tag = "reason", content = "details")] #[cfg_attr(target_os = "android", derive(IntoJava))] #[cfg_attr(target_os = "android", jnix(package = "net.mullvad.talpid.tunnel"))] pub enum FirewallPolicyError { /// General firewall failure - #[error(display = "Failed to set firewall policy")] + #[error("Failed to set firewall policy")] Generic, /// An application prevented the firewall policy from being set #[cfg(windows)] - #[error(display = "An application prevented the firewall policy from being set")] + #[error("An application prevented the firewall policy from being set")] Locked(Option<BlockingApplication>), } diff --git a/talpid-windows/Cargo.toml b/talpid-windows/Cargo.toml index fb32b8219e..c968397465 100644 --- a/talpid-windows/Cargo.toml +++ b/talpid-windows/Cargo.toml @@ -11,7 +11,7 @@ rust-version.workspace = true workspace = true [target.'cfg(windows)'.dependencies] -err-derive = { workspace = true } +thiserror = { workspace = true } socket2 = { version = "0.5.3" } futures = "0.3.15" diff --git a/talpid-windows/src/net.rs b/talpid-windows/src/net.rs index 196d6a66b6..188fb5a498 100644 --- a/talpid-windows/src/net.rs +++ b/talpid-windows/src/net.rs @@ -41,66 +41,65 @@ const DAD_CHECK_TIMEOUT: Duration = Duration::from_secs(5); const DAD_CHECK_INTERVAL: Duration = Duration::from_millis(100); /// Errors returned by some functions in this module. -#[derive(err_derive::Error, Debug)] -#[error(no_from)] +#[derive(thiserror::Error, Debug)] pub enum Error { /// Error returned from `ConvertInterfaceAliasToLuid` #[cfg(windows)] - #[error(display = "Cannot find LUID for virtual adapter")] - NoDeviceLuid(#[error(source)] io::Error), + #[error("Cannot find LUID for virtual adapter")] + NoDeviceLuid(#[source] io::Error), /// Error returned from `GetUnicastIpAddressTable`/`GetUnicastIpAddressEntry` #[cfg(windows)] - #[error(display = "Failed to obtain unicast IP address table")] - ObtainUnicastAddress(#[error(source)] io::Error), + #[error("Failed to obtain unicast IP address table")] + ObtainUnicastAddress(#[source] io::Error), /// `GetUnicastIpAddressTable` contained no addresses for the interface #[cfg(windows)] - #[error(display = "Found no addresses for the given adapter")] + #[error("Found no addresses for the given adapter")] NoUnicastAddress, /// Error returned from `CreateUnicastIpAddressEntry` #[cfg(windows)] - #[error(display = "Failed to create unicast IP address")] - CreateUnicastEntry(#[error(source)] io::Error), + #[error("Failed to create unicast IP address")] + CreateUnicastEntry(#[source] io::Error), /// Unexpected DAD state returned for a unicast address #[cfg(windows)] - #[error(display = "Unexpected DAD state")] - DadStateError(#[error(source)] DadStateError), + #[error("Unexpected DAD state")] + DadStateError(#[source] DadStateError), /// DAD check failed. #[cfg(windows)] - #[error(display = "Timed out waiting on tunnel device")] + #[error("Timed out waiting on tunnel device")] DeviceReadyTimeout, /// Unicast DAD check fail. #[cfg(windows)] - #[error(display = "Unicast channel sender was unexpectedly dropped")] + #[error("Unicast channel sender was unexpectedly dropped")] UnicastSenderDropped, /// Unknown address family - #[error(display = "Unknown address family: {}", _0)] + #[error("Unknown address family: {0}")] UnknownAddressFamily(u16), } /// Handles cases where there DAD state is neither tentative nor preferred. -#[derive(err_derive::Error, Debug)] +#[derive(thiserror::Error, Debug)] pub enum DadStateError { /// Invalid DAD state. - #[error(display = "Invalid DAD state")] + #[error("Invalid DAD state")] Invalid, /// Duplicate unicast address. - #[error(display = "A duplicate IP address was detected")] + #[error("A duplicate IP address was detected")] Duplicate, /// Deprecated unicast address. - #[error(display = "The IP address has been deprecated")] + #[error("The IP address has been deprecated")] Deprecated, /// Unknown DAD state constant. - #[error(display = "Unknown DAD state: {}", _0)] + #[error("Unknown DAD state: {0}")] Unknown(i32), } diff --git a/talpid-wireguard/Cargo.toml b/talpid-wireguard/Cargo.toml index b378417d63..de7a6d4b19 100644 --- a/talpid-wireguard/Cargo.toml +++ b/talpid-wireguard/Cargo.toml @@ -11,7 +11,7 @@ rust-version.workspace = true workspace = true [dependencies] -err-derive = { workspace = true } +thiserror = { workspace = true } futures = "0.3.15" hex = "0.4" ipnetwork = "0.16" diff --git a/talpid-wireguard/src/config.rs b/talpid-wireguard/src/config.rs index b30e9053fc..29328eb681 100644 --- a/talpid-wireguard/src/config.rs +++ b/talpid-wireguard/src/config.rs @@ -31,14 +31,14 @@ pub struct Config { } /// Configuration errors -#[derive(err_derive::Error, Debug)] +#[derive(thiserror::Error, Debug)] pub enum Error { /// Supplied parameters don't contain a valid tunnel IP - #[error(display = "No valid tunnel IP")] + #[error("No valid tunnel IP")] InvalidTunnelIpError, /// Peer has no valid IPs - #[error(display = "Supplied peer has no valid IPs")] + #[error("Supplied peer has no valid IPs")] InvalidPeerIpError, } diff --git a/talpid-wireguard/src/connectivity_check.rs b/talpid-wireguard/src/connectivity_check.rs index 3a8208400e..a515ff5c6b 100644 --- a/talpid-wireguard/src/connectivity_check.rs +++ b/talpid-wireguard/src/connectivity_check.rs @@ -36,15 +36,15 @@ const MAX_ESTABLISH_TIMEOUT: Duration = PING_TIMEOUT; const SECONDS_PER_PING: Duration = Duration::from_secs(3); /// Connectivity monitor errors -#[derive(err_derive::Error, Debug)] +#[derive(thiserror::Error, Debug)] pub enum Error { /// Failed to read tunnel's configuration - #[error(display = "Failed to read tunnel's configuration")] + #[error("Failed to read tunnel's configuration")] ConfigReadError(TunnelError), /// Failed to send ping - #[error(display = "Ping monitor failed")] - PingError(#[error(source)] crate::ping_monitor::Error), + #[error("Ping monitor failed")] + PingError(#[from] crate::ping_monitor::Error), } /// Verifies if a connection to a tunnel is working. diff --git a/talpid-wireguard/src/lib.rs b/talpid-wireguard/src/lib.rs index 78843570be..4f02bfcb09 100644 --- a/talpid-wireguard/src/lib.rs +++ b/talpid-wireguard/src/lib.rs @@ -67,46 +67,45 @@ type Result<T> = std::result::Result<T, Error>; type EventCallback = Box<dyn (Fn(TunnelEvent) -> BoxFuture<'static, ()>) + Send + Sync + 'static>; /// Errors that can happen in the Wireguard tunnel monitor. -#[derive(err_derive::Error, Debug)] -#[error(no_from)] +#[derive(thiserror::Error, Debug)] pub enum Error { /// Failed to set up routing. - #[error(display = "Failed to setup routing")] - SetupRoutingError(#[error(source)] talpid_routing::Error), + #[error("Failed to setup routing")] + SetupRoutingError(#[source] talpid_routing::Error), /// Tunnel timed out - #[error(display = "Tunnel timed out")] + #[error("Tunnel timed out")] TimeoutError, /// An interaction with a tunnel failed - #[error(display = "Tunnel failed")] - TunnelError(#[error(source)] TunnelError), + #[error("Tunnel failed")] + TunnelError(#[source] TunnelError), /// Failed to create tunnel obfuscator - #[error(display = "Failed to create tunnel obfuscator")] - CreateObfuscatorError(#[error(source)] ObfuscationError), + #[error("Failed to create tunnel obfuscator")] + CreateObfuscatorError(#[source] ObfuscationError), /// Failed to run tunnel obfuscator - #[error(display = "Tunnel obfuscator failed")] - ObfuscatorError(#[error(source)] ObfuscationError), + #[error("Tunnel obfuscator failed")] + ObfuscatorError(#[source] ObfuscationError), /// Failed to set up connectivity monitor - #[error(display = "Connectivity monitor failed")] - ConnectivityMonitorError(#[error(source)] connectivity_check::Error), + #[error("Connectivity monitor failed")] + ConnectivityMonitorError(#[source] connectivity_check::Error), /// Failed to negotiate PQ PSK - #[error(display = "Failed to negotiate PQ PSK")] - PskNegotiationError(#[error(source)] talpid_tunnel_config_client::Error), + #[error("Failed to negotiate PQ PSK")] + PskNegotiationError(#[source] talpid_tunnel_config_client::Error), /// Failed to set up IP interfaces. #[cfg(windows)] - #[error(display = "Failed to set up IP interfaces")] + #[error("Failed to set up IP interfaces")] IpInterfacesError, /// Failed to set IP addresses on WireGuard interface #[cfg(target_os = "windows")] - #[error(display = "Failed to set IP addresses on WireGuard interface")] - SetIpAddressesError(#[error(source)] talpid_windows::net::Error), + #[error("Failed to set IP addresses on WireGuard interface")] + SetIpAddressesError(#[source] talpid_windows::net::Error), } impl Error { @@ -998,14 +997,13 @@ pub(crate) trait Tunnel: Send { } /// Errors to be returned from WireGuard implementations, namely implementers of the Tunnel trait -#[derive(err_derive::Error, Debug)] -#[error(no_from)] +#[derive(thiserror::Error, Debug)] pub enum TunnelError { /// A recoverable error occurred while starting the wireguard tunnel /// /// This is an error returned by the implementation that indicates that trying to establish the /// tunnel again should work normally. The error encountered is known to be sporadic. - #[error(display = "Recoverable error while starting wireguard tunnel")] + #[error("Recoverable error while starting wireguard tunnel")] RecoverableStartWireguardError, /// An unrecoverable error occurred while starting the wireguard tunnel @@ -1013,65 +1011,65 @@ pub enum TunnelError { /// This is an error returned by the implementation that indicates that trying to establish the /// tunnel again will likely fail with the same error. An error was encountered during tunnel /// configuration which can't be dealt with gracefully. - #[error(display = "Failed to start wireguard tunnel")] + #[error("Failed to start wireguard tunnel")] FatalStartWireguardError, /// Failed to tear down wireguard tunnel. - #[error(display = "Failed to stop wireguard tunnel. Status: {}", status)] + #[error("Failed to stop wireguard tunnel. Status: {status}")] StopWireguardError { /// Returned error code status: i32, }, /// Error whilst trying to parse the WireGuard config to read the stats - #[error(display = "Reading tunnel stats failed")] - StatsError(#[error(source)] BoxedError), + #[error("Reading tunnel stats failed")] + StatsError(#[source] BoxedError), /// Error whilst trying to retrieve config of a WireGuard tunnel - #[error(display = "Failed to get config of WireGuard tunnel")] + #[error("Failed to get config of WireGuard tunnel")] GetConfigError, /// Failed to set WireGuard tunnel config on device - #[error(display = "Failed to set config of WireGuard tunnel")] + #[error("Failed to set config of WireGuard tunnel")] SetConfigError, /// Failed to duplicate tunnel file descriptor for wireguard-go #[cfg(any(target_os = "linux", target_os = "macos", target_os = "android"))] - #[error(display = "Failed to duplicate tunnel file descriptor for wireguard-go")] - FdDuplicationError(#[error(source)] nix::Error), + #[error("Failed to duplicate tunnel file descriptor for wireguard-go")] + FdDuplicationError(#[source] nix::Error), /// Failed to setup a tunnel device. #[cfg(not(windows))] - #[error(display = "Failed to create tunnel device")] - SetupTunnelDevice(#[error(source)] tun_provider::Error), + #[error("Failed to create tunnel device")] + SetupTunnelDevice(#[source] tun_provider::Error), /// Failed to set up a tunnel device #[cfg(windows)] - #[error(display = "Failed to create tunnel device")] - SetupTunnelDevice(#[error(source)] io::Error), + #[error("Failed to create tunnel device")] + SetupTunnelDevice(#[source] io::Error), /// Failed to setup a tunnel device. #[cfg(windows)] - #[error(display = "Failed to config IP interfaces on tunnel device")] - SetupIpInterfaces(#[error(source)] io::Error), + #[error("Failed to config IP interfaces on tunnel device")] + SetupIpInterfaces(#[source] io::Error), /// Failed to configure Wireguard sockets to bypass the tunnel. #[cfg(target_os = "android")] - #[error(display = "Failed to configure Wireguard sockets to bypass the tunnel")] - BypassError(#[error(source)] tun_provider::Error), + #[error("Failed to configure Wireguard sockets to bypass the tunnel")] + BypassError(#[source] tun_provider::Error), /// Invalid tunnel interface name. - #[error(display = "Invalid tunnel interface name")] - InterfaceNameError(#[error(source)] std::ffi::NulError), + #[error("Invalid tunnel interface name")] + InterfaceNameError(#[source] std::ffi::NulError), /// Failed to convert adapter alias to UTF-8. #[cfg(target_os = "windows")] - #[error(display = "Failed to convert adapter alias")] + #[error("Failed to convert adapter alias")] InvalidAlias, /// Failure to set up logging - #[error(display = "Failed to set up logging")] - LoggingError(#[error(source)] logging::Error), + #[error("Failed to set up logging")] + LoggingError(#[source] logging::Error), } #[cfg(target_os = "linux")] diff --git a/talpid-wireguard/src/logging.rs b/talpid-wireguard/src/logging.rs index f9adcb7f53..6d1d364342 100644 --- a/talpid-wireguard/src/logging.rs +++ b/talpid-wireguard/src/logging.rs @@ -7,11 +7,11 @@ static LOG_MUTEX: Lazy<Mutex<HashMap<u32, fs::File>>> = Lazy::new(|| Mutex::new( static mut LOG_CONTEXT_NEXT_ORDINAL: u32 = 0; /// Errors encountered when initializing logging -#[derive(err_derive::Error, Debug)] +#[derive(thiserror::Error, Debug)] pub enum Error { /// Failed to move or create a log file. - #[error(display = "Failed to setup a logging file")] - PrepareLogFileError(#[error(source)] std::io::Error), + #[error("Failed to setup a logging file")] + PrepareLogFileError(#[from] std::io::Error), } pub fn initialize_logging(log_path: Option<&Path>) -> Result<u32, Error> { diff --git a/talpid-wireguard/src/mtu_detection.rs b/talpid-wireguard/src/mtu_detection.rs index 54bbcb7b4d..55523da08b 100644 --- a/talpid-wireguard/src/mtu_detection.rs +++ b/talpid-wireguard/src/mtu_detection.rs @@ -5,31 +5,28 @@ use surge_ping::{Client, Config, PingIdentifier, PingSequence, SurgeError}; use talpid_tunnel::{ICMP_HEADER_SIZE, IPV4_HEADER_SIZE, MIN_IPV4_MTU}; use tokio_stream::StreamExt; -#[derive(err_derive::Error, Debug)] -#[error(no_from)] +#[derive(thiserror::Error, Debug)] pub enum Error { /// Failed to set MTU on the active tunnel - #[error(display = "Failed to set MTU on the active tunnel")] - SetMtu(#[error(source)] io::Error), + #[error("Failed to set MTU on the active tunnel")] + SetMtu(#[source] io::Error), /// Failed to set MTU - #[error(display = "Failed to detect MTU because every ping was dropped.")] + #[error("Failed to detect MTU because every ping was dropped.")] MtuDetectionAllDropped, /// Failed to set MTU - #[error(display = "Failed to detect MTU because of unexpected ping error.")] - MtuDetectionPing(#[error(source)] surge_ping::SurgeError), + #[error("Failed to detect MTU because of unexpected ping error.")] + MtuDetectionPing(#[source] surge_ping::SurgeError), /// Failed to set MTU - #[error( - display = "Failed to detect MTU because of an IO error when setting up the ping socket." - )] - MtuDetectionSetupSocket(#[error(source)] io::Error), + #[error("Failed to detect MTU because of an IO error when setting up the ping socket.")] + MtuDetectionSetupSocket(#[source] io::Error), /// Failed to set MTU #[cfg(target_os = "macos")] - #[error(display = "Failed to set buffer size")] - MtuSetBufferSize(#[error(source)] nix::Error), + #[error("Failed to set buffer size")] + MtuSetBufferSize(#[source] nix::Error), } /// Verify that the current MTU doesn't cause dropped packets, otherwise lower it to the /// largest value which doesn't. diff --git a/talpid-wireguard/src/ping_monitor/android.rs b/talpid-wireguard/src/ping_monitor/android.rs index 036db93563..00ad4d8fd3 100644 --- a/talpid-wireguard/src/ping_monitor/android.rs +++ b/talpid-wireguard/src/ping_monitor/android.rs @@ -1,14 +1,14 @@ use std::{io, net::Ipv4Addr}; /// Pinger errors -#[derive(err_derive::Error, Debug)] +#[derive(thiserror::Error, Debug)] pub enum Error { /// Failed to run `ping` process - #[error(display = "Failed to run ping command")] - PingError(#[error(source)] io::Error), + #[error("Failed to run ping command")] + PingError(#[from] io::Error), /// ICMP timed out - #[error(display = "Ping timed out")] + #[error("Ping timed out")] TimeoutError, } diff --git a/talpid-wireguard/src/ping_monitor/icmp.rs b/talpid-wireguard/src/ping_monitor/icmp.rs index ad31349799..ff709e4532 100644 --- a/talpid-wireguard/src/ping_monitor/icmp.rs +++ b/talpid-wireguard/src/ping_monitor/icmp.rs @@ -12,41 +12,40 @@ use std::{ const SEND_RETRY_ATTEMPTS: u32 = 10; /// Pinger errors -#[derive(err_derive::Error, Debug)] -#[error(no_from)] +#[derive(thiserror::Error, Debug)] pub enum Error { /// Failed to open raw socket - #[error(display = "Failed to open ICMP socket")] - Open(#[error(source)] io::Error), + #[error("Failed to open ICMP socket")] + Open(#[source] io::Error), /// Failed to read from raw socket - #[error(display = "Failed to read ICMP socket")] - Read(#[error(source)] io::Error), + #[error("Failed to read ICMP socket")] + Read(#[source] io::Error), /// Failed to set socket options - #[error(display = "Failed to set socket options")] - SocketOp(#[error(source)] io::Error), + #[error("Failed to set socket options")] + SocketOp(#[source] io::Error), /// Failed to write to raw socket - #[error(display = "Failed to write to socket")] - Write(#[error(source)] io::Error), + #[error("Failed to write to socket")] + Write(#[source] io::Error), /// Failed to get device index #[cfg(target_os = "macos")] - #[error(display = "Failed to obtain device index")] + #[error("Failed to obtain device index")] DeviceIdx(nix::errno::Errno), /// Failed to bind socket to device by index #[cfg(target_os = "macos")] - #[error(display = "Failed to bind socket to device by index")] + #[error("Failed to bind socket to device by index")] BindSocketByDevice(io::Error), /// ICMP buffer too small - #[error(display = "ICMP message buffer too small")] + #[error("ICMP message buffer too small")] BufferTooSmall, /// Interface name contains null bytes - #[error(display = "Interface name contains a null byte")] + #[error("Interface name contains a null byte")] InterfaceNameContainsNull, } diff --git a/talpid-wireguard/src/wireguard_go.rs b/talpid-wireguard/src/wireguard_go.rs index 28c05676de..8a4a194198 100644 --- a/talpid-wireguard/src/wireguard_go.rs +++ b/talpid-wireguard/src/wireguard_go.rs @@ -320,13 +320,13 @@ extern "C" { mod stats { use super::{Stats, StatsMap}; - #[derive(err_derive::Error, Debug, PartialEq)] + #[derive(thiserror::Error, Debug, PartialEq)] pub enum Error { - #[error(display = "Failed to parse peer pubkey from string \"{}\"", _0)] - PubKeyParse(String, #[error(source)] hex::FromHexError), + #[error("Failed to parse peer pubkey from string \"{0}\"")] + PubKeyParse(String, #[source] hex::FromHexError), - #[error(display = "Failed to parse integer from string \"{}\"", _0)] - IntParse(String, #[error(source)] std::num::ParseIntError), + #[error("Failed to parse integer from string \"{0}\"")] + IntParse(String, #[source] std::num::ParseIntError), } impl Stats { diff --git a/talpid-wireguard/src/wireguard_kernel/mod.rs b/talpid-wireguard/src/wireguard_kernel/mod.rs index aa999bf987..a3c053acfc 100644 --- a/talpid-wireguard/src/wireguard_kernel/mod.rs +++ b/talpid-wireguard/src/wireguard_kernel/mod.rs @@ -30,59 +30,58 @@ pub use netlink_tunnel::NetlinkTunnel; pub mod nm_tunnel; pub use nm_tunnel::NetworkManagerTunnel; -#[derive(err_derive::Error, Debug)] -#[error(no_from)] +#[derive(thiserror::Error, Debug)] pub enum Error { - #[error(display = "Failed to decode netlink message")] - Decode(#[error(source)] DecodeError), + #[error("Failed to decode netlink message")] + Decode(#[source] DecodeError), - #[error(display = "Failed to execute netlink control request")] - NetlinkControlMessage(#[error(source)] nl_message::Error), + #[error("Failed to execute netlink control request")] + NetlinkControlMessage(#[source] nl_message::Error), - #[error(display = "Failed to open netlink socket")] - NetlinkSocket(#[error(source)] std::io::Error), + #[error("Failed to open netlink socket")] + NetlinkSocket(#[source] std::io::Error), - #[error(display = "Failed to send netlink control request")] - NetlinkRequest(#[error(source)] netlink_proto::Error<NetlinkControlMessage>), + #[error("Failed to send netlink control request")] + NetlinkRequest(#[source] netlink_proto::Error<NetlinkControlMessage>), - #[error(display = "WireGuard netlink interface unavailable. Is the kernel module loaded?")] + #[error("WireGuard netlink interface unavailable. Is the kernel module loaded?")] WireguardNetlinkInterfaceUnavailable, - #[error(display = "Unknown WireGuard command _0")] + #[error("Unknown WireGuard command: {0}")] UnnkownWireguardCommmand(u8), - #[error(display = "Received no response")] + #[error("Received no response")] NoResponse, - #[error(display = "Received truncated message")] + #[error("Received truncated message")] Truncated, - #[error(display = "WireGuard device does not exist")] + #[error("WireGuard device does not exist")] NoDevice, - #[error(display = "Failed to get config: _0")] + #[error("Failed to get config: {0}")] WgGetConf(netlink_packet_core::error::ErrorMessage), - #[error(display = "Failed to apply config: _0")] + #[error("Failed to apply config: {0}")] WgSetConf(netlink_packet_core::error::ErrorMessage), - #[error(display = "Interface name too long")] + #[error("Interface name too long")] InterfaceName, - #[error(display = "Send request error")] - SendRequest(#[error(source)] NetlinkError<DeviceMessage>), + #[error("Send request error")] + SendRequest(#[source] NetlinkError<DeviceMessage>), - #[error(display = "Create device error")] - NetlinkCreateDevice(#[error(source)] rtnetlink::Error), + #[error("Create device error")] + NetlinkCreateDevice(#[source] rtnetlink::Error), - #[error(display = "Add IP to device error")] + #[error("Add IP to device error")] NetlinkSetIp(rtnetlink::Error), - #[error(display = "Failed to delete device")] - DeleteDevice(#[error(source)] rtnetlink::Error), + #[error("Failed to delete device")] + DeleteDevice(#[source] rtnetlink::Error), - #[error(display = "NetworkManager error")] - NetworkManager(#[error(source)] nm_tunnel::Error), + #[error("NetworkManager error")] + NetworkManager(#[source] nm_tunnel::Error), } pub(crate) const MULLVAD_INTERFACE_NAME: &str = "wg0-mullvad"; diff --git a/talpid-wireguard/src/wireguard_kernel/nl_message.rs b/talpid-wireguard/src/wireguard_kernel/nl_message.rs index 87f1537ea0..a66947120e 100644 --- a/talpid-wireguard/src/wireguard_kernel/nl_message.rs +++ b/talpid-wireguard/src/wireguard_kernel/nl_message.rs @@ -10,9 +10,9 @@ use netlink_packet_utils::{ }; use std::{ffi::CString, io::Write, mem}; -#[derive(err_derive::Error, Debug)] +#[derive(thiserror::Error, Debug)] pub enum Error { - #[error(display = "Family name too long")] + #[error("Family name too long")] FamilyNameTooLong, } diff --git a/talpid-wireguard/src/wireguard_kernel/nm_tunnel.rs b/talpid-wireguard/src/wireguard_kernel/nm_tunnel.rs index 7b5966b9e4..7c24c42a70 100644 --- a/talpid-wireguard/src/wireguard_kernel/nm_tunnel.rs +++ b/talpid-wireguard/src/wireguard_kernel/nm_tunnel.rs @@ -12,13 +12,13 @@ use talpid_dbus::{ }, }; -#[derive(err_derive::Error, Debug)] +#[derive(thiserror::Error, Debug)] pub enum Error { - #[error(display = "Error while communicating over Dbus")] - Dbus(#[error(source)] dbus::Error), + #[error("Error while communicating over Dbus")] + Dbus(#[from] dbus::Error), - #[error(display = "NetworkManager error")] - NetworkManager(#[error(source)] NetworkManagerError), + #[error("NetworkManager error")] + NetworkManager(#[from] NetworkManagerError), } pub struct NetworkManagerTunnel { @@ -222,12 +222,12 @@ fn iface_index(name: &str) -> std::result::Result<libc::c_uint, IfaceIndexLookup } /// Failure to lookup an interfaces index by its name. -#[derive(Debug, err_derive::Error)] +#[derive(Debug, thiserror::Error)] pub enum IfaceIndexLookupError { /// The interface name is invalid - contains null bytes or is too long. - #[error(display = "Invalid network interface name: {}", _0)] - InvalidInterfaceName(String, #[error(source)] std::ffi::NulError), + #[error("Invalid network interface name: {0}")] + InvalidInterfaceName(String, #[source] std::ffi::NulError), /// Interface wasn't found by its name. - #[error(display = "Failed to get index for interface {}", _0)] - InterfaceLookupError(String, #[error(source)] std::io::Error), + #[error("Failed to get index for interface {0}")] + InterfaceLookupError(String, #[source] std::io::Error), } diff --git a/talpid-wireguard/src/wireguard_nt.rs b/talpid-wireguard/src/wireguard_nt.rs index 1c7c9d0c71..10cc45b384 100644 --- a/talpid-wireguard/src/wireguard_nt.rs +++ b/talpid-wireguard/src/wireguard_nt.rs @@ -106,59 +106,58 @@ type WireGuardSetAdapterLoggingFn = pub type Result<T> = std::result::Result<T, Error>; -#[derive(err_derive::Error, Debug)] -#[error(no_from)] +#[derive(thiserror::Error, Debug)] pub enum Error { /// Failed to load WireGuardNT - #[error(display = "Failed to load mullvad-wireguard.dll")] - LoadDll(#[error(source)] io::Error), + #[error("Failed to load mullvad-wireguard.dll")] + LoadDll(#[source] io::Error), /// Failed to create tunnel interface - #[error(display = "Failed to create WireGuard device")] - CreateTunnelDevice(#[error(source)] io::Error), + #[error("Failed to create WireGuard device")] + CreateTunnelDevice(#[source] io::Error), /// Failed to obtain tunnel interface alias - #[error(display = "Failed to obtain interface name")] - ObtainAlias(#[error(source)] io::Error), + #[error("Failed to obtain interface name")] + ObtainAlias(#[source] io::Error), /// Failed to get WireGuard tunnel config for device - #[error(display = "Failed to get tunnel WireGuard config")] - GetWireGuardConfig(#[error(source)] io::Error), + #[error("Failed to get tunnel WireGuard config")] + GetWireGuardConfig(#[source] io::Error), /// Failed to set WireGuard tunnel config on device - #[error(display = "Failed to set tunnel WireGuard config")] - SetWireGuardConfig(#[error(source)] io::Error), + #[error("Failed to set tunnel WireGuard config")] + SetWireGuardConfig(#[source] io::Error), /// Error listening to tunnel IP interfaces - #[error(display = "Failed to wait on tunnel IP interfaces")] - IpInterfaces(#[error(source)] io::Error), + #[error("Failed to wait on tunnel IP interfaces")] + IpInterfaces(#[source] io::Error), /// Failed to set MTU and metric on tunnel device - #[error(display = "Failed to set tunnel interface MTU")] - SetTunnelMtu(#[error(source)] io::Error), + #[error("Failed to set tunnel interface MTU")] + SetTunnelMtu(#[source] io::Error), /// Failed to set the tunnel state to up - #[error(display = "Failed to enable the tunnel adapter")] - EnableTunnel(#[error(source)] io::Error), + #[error("Failed to enable the tunnel adapter")] + EnableTunnel(#[source] io::Error), /// Unknown address family - #[error(display = "Unknown address family: {}", _0)] + #[error("Unknown address family: {0}")] UnknownAddressFamily(u16), /// Failure to set up logging - #[error(display = "Failed to set up logging")] - InitLogging(#[error(source)] logging::Error), + #[error("Failed to set up logging")] + InitLogging(#[source] logging::Error), /// Invalid allowed IP - #[error(display = "Invalid CIDR prefix")] + #[error("Invalid CIDR prefix")] InvalidAllowedIpCidr, /// Allowed IP contains non-zero host bits - #[error(display = "Allowed IP contains non-zero host bits")] + #[error("Allowed IP contains non-zero host bits")] InvalidAllowedIpBits, /// Failed to parse data returned by the driver - #[error(display = "Failed to parse data returned by wireguard-nt")] + #[error("Failed to parse data returned by wireguard-nt")] InvalidConfigData, } diff --git a/test/Cargo.lock b/test/Cargo.lock index 19d0d98bda..3b6fb48523 100644 --- a/test/Cargo.lock +++ b/test/Cargo.lock @@ -170,7 +170,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.51", ] [[package]] @@ -191,7 +191,7 @@ checksum = "bc00ceb34980c03614e35a3a4e218276a0a824e911d07651cd0d858a51e8c0f0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.51", ] [[package]] @@ -454,7 +454,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.51", ] [[package]] @@ -612,7 +612,7 @@ checksum = "83fdaf97f4804dcebfa5862639bc9ce4121e82140bec2a987ac5140294865b5b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.51", ] [[package]] @@ -764,7 +764,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.51", ] [[package]] @@ -777,7 +777,7 @@ dependencies = [ "num-traits", "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.51", ] [[package]] @@ -800,20 +800,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] -name = "err-derive" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c34a887c8df3ed90498c1c437ce21f211c8e27672921a8ffa293cb8d6d4caa9e" -dependencies = [ - "proc-macro-error", - "proc-macro2", - "quote", - "rustversion", - "syn 1.0.109", - "synstructure", -] - -[[package]] name = "errno" version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -969,7 +955,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.51", ] [[package]] @@ -1052,7 +1038,7 @@ checksum = "ba330b70a5341d3bc730b8e205aaee97ddab5d9c448c4f51a7c2d924266fa8f9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.51", ] [[package]] @@ -1718,7 +1704,6 @@ version = "0.0.0" dependencies = [ "cbindgen", "chrono", - "err-derive", "futures", "http", "hyper", @@ -1734,6 +1719,7 @@ dependencies = [ "shadowsocks", "talpid-time", "talpid-types", + "thiserror", "tokio", "tokio-rustls", "tokio-socks", @@ -1755,7 +1741,6 @@ name = "mullvad-management-interface" version = "0.0.0" dependencies = [ "chrono", - "err-derive", "futures", "log", "mullvad-paths", @@ -1766,6 +1751,7 @@ dependencies = [ "prost", "prost-types", "talpid-types", + "thiserror", "tokio", "tonic", "tonic-build", @@ -1776,9 +1762,9 @@ dependencies = [ name = "mullvad-paths" version = "0.0.0" dependencies = [ - "err-derive", "log", "once_cell", + "thiserror", "widestring", "windows-sys 0.48.0", ] @@ -1788,13 +1774,13 @@ name = "mullvad-relay-selector" version = "0.0.0" dependencies = [ "chrono", - "err-derive", "ipnetwork 0.16.0", "log", "mullvad-types", "rand 0.8.5", "serde_json", "talpid-types", + "thiserror", ] [[package]] @@ -1802,7 +1788,6 @@ name = "mullvad-types" version = "0.0.0" dependencies = [ "chrono", - "err-derive", "ipnetwork 0.16.0", "jnix", "log", @@ -1810,6 +1795,7 @@ dependencies = [ "regex", "serde", "talpid-types", + "thiserror", "uuid", ] @@ -2119,7 +2105,7 @@ checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.51", ] [[package]] @@ -2248,38 +2234,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae005bd773ab59b4725093fd7df83fd7892f7d8eafb48dbd7de6e024e4215f9d" dependencies = [ "proc-macro2", - "syn 2.0.37", -] - -[[package]] -name = "proc-macro-error" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" -dependencies = [ - "proc-macro-error-attr", - "proc-macro2", - "quote", - "syn 1.0.109", - "version_check", -] - -[[package]] -name = "proc-macro-error-attr" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" -dependencies = [ - "proc-macro2", - "quote", - "version_check", + "syn 2.0.51", ] [[package]] name = "proc-macro2" -version = "1.0.67" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d433d9f1a3e8c1263d9456598b16fec66f4acc9a74dacffd35c7bb09b3a1328" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] @@ -2311,7 +2273,7 @@ dependencies = [ "prost", "prost-types", "regex", - "syn 2.0.37", + "syn 2.0.51", "tempfile", "which", ] @@ -2326,7 +2288,7 @@ dependencies = [ "itertools 0.11.0", "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.51", ] [[package]] @@ -2355,9 +2317,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.33" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -2752,7 +2714,7 @@ checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.51", ] [[package]] @@ -2927,10 +2889,10 @@ dependencies = [ name = "socks-server" version = "0.0.0" dependencies = [ - "err-derive", "fast-socks5", "futures", "log", + "thiserror", "tokio", ] @@ -3002,9 +2964,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.37" +version = "2.0.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7303ef2c05cd654186cb250d29049a24840ca25d2747c25c0381c8d9e2f582e8" +checksum = "6ab617d94515e94ae53b8406c628598680aa0c9587474ecbe58188f7b345d66c" dependencies = [ "proc-macro2", "quote", @@ -3018,26 +2980,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" [[package]] -name = "synstructure" -version = "0.12.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", - "unicode-xid", -] - -[[package]] name = "talpid-dbus" version = "0.0.0" dependencies = [ "dbus", - "err-derive", "libc", "log", "once_cell", + "thiserror", "tokio", ] @@ -3063,10 +3013,10 @@ name = "talpid-types" version = "0.0.0" dependencies = [ "base64 0.13.1", - "err-derive", "ipnetwork 0.16.0", "jnix", "serde", + "thiserror", "x25519-dalek", "zeroize", ] @@ -3075,10 +3025,10 @@ dependencies = [ name = "talpid-windows" version = "0.0.0" dependencies = [ - "err-derive", "futures", "socket2 0.5.4", "talpid-types", + "thiserror", "windows-sys 0.48.0", ] @@ -3153,7 +3103,6 @@ dependencies = [ "data-encoding-macro", "dirs", "env_logger", - "err-derive", "futures", "inventory", "ipnetwork 0.20.0", @@ -3177,6 +3126,7 @@ dependencies = [ "tarpc", "test-rpc", "test_macro", + "thiserror", "tokio", "tokio-serde", "tokio-serial", @@ -3194,7 +3144,6 @@ dependencies = [ "async-trait", "bytes", "colored", - "err-derive", "futures", "hyper", "hyper-rustls", @@ -3204,6 +3153,7 @@ dependencies = [ "serde", "serde_json", "tarpc", + "thiserror", "tokio", "tokio-rustls", "tokio-serde", @@ -3216,7 +3166,6 @@ version = "0.0.0" dependencies = [ "bytes", "chrono", - "err-derive", "futures", "libc", "log", @@ -3233,6 +3182,7 @@ dependencies = [ "talpid-windows", "tarpc", "test-rpc", + "thiserror", "tokio", "tokio-serde", "tokio-serial", @@ -3253,22 +3203,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.49" +version = "1.0.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" +checksum = "1e45bcbe8ed29775f228095caf2cd67af7a4ccf756ebff23a306bf3e8b47b24b" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.49" +version = "1.0.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" +checksum = "a953cb265bef375dae3de6663da4d3804eee9682ea80d8e2542529b73c531c81" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.51", ] [[package]] @@ -3361,7 +3311,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.51", ] [[package]] @@ -3503,7 +3453,7 @@ dependencies = [ "proc-macro2", "prost-build", "quote", - "syn 2.0.37", + "syn 2.0.51", ] [[package]] @@ -3559,7 +3509,7 @@ checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.51", ] [[package]] @@ -3696,12 +3646,6 @@ dependencies = [ ] [[package]] -name = "unicode-xid" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" - -[[package]] name = "universal-hash" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -3814,7 +3758,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.51", "wasm-bindgen-shared", ] @@ -3836,7 +3780,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.51", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -4149,5 +4093,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.51", ] diff --git a/test/Cargo.toml b/test/Cargo.toml index 27c0f94469..44cc016d66 100644 --- a/test/Cargo.toml +++ b/test/Cargo.toml @@ -37,7 +37,7 @@ prost-types = "0.12.0" tarpc = { version = "0.30", features = ["tokio1", "serde-transport", "serde1"] } # Logging env_logger = "0.10.0" -err-derive = "0.3.1" +thiserror = "1.0.57" log = "0.4" colored = "2.0.0" # Proxy protocols diff --git a/test/socks-server/Cargo.toml b/test/socks-server/Cargo.toml index ba6d1ba4f8..c37450fd87 100644 --- a/test/socks-server/Cargo.toml +++ b/test/socks-server/Cargo.toml @@ -12,7 +12,7 @@ workspace = true [dependencies] fast-socks5 = "0.9.5" -err-derive = { workspace = true } +thiserror = { workspace = true } tokio = { workspace = true } log = { workspace = true } futures = { workspace = true } diff --git a/test/socks-server/src/lib.rs b/test/socks-server/src/lib.rs index eed676ac8e..9a85297036 100644 --- a/test/socks-server/src/lib.rs +++ b/test/socks-server/src/lib.rs @@ -2,11 +2,10 @@ use futures::StreamExt; use std::io; use std::net::SocketAddr; -#[derive(err_derive::Error, Debug)] -#[error(no_from)] +#[derive(thiserror::Error, Debug)] pub enum Error { - #[error(display = "Failed to start SOCKS5 server")] - StartSocksServer(#[error(source)] io::Error), + #[error("Failed to start SOCKS5 server")] + StartSocksServer(#[source] io::Error), } pub struct Handle { diff --git a/test/test-manager/Cargo.toml b/test/test-manager/Cargo.toml index 086d937e45..66ef6f0025 100644 --- a/test/test-manager/Cargo.toml +++ b/test/test-manager/Cargo.toml @@ -18,7 +18,7 @@ chrono = { workspace = true } tarpc = { workspace = true } tokio = { workspace = true } tokio-serial = { workspace = true } -err-derive = { workspace = true } +thiserror = { workspace = true } bytes = { workspace = true } test_macro = { path = "./test_macro" } ipnetwork = "0.20" diff --git a/test/test-manager/src/config.rs b/test/test-manager/src/config.rs index 0acbeb322e..1605661d53 100644 --- a/test/test-manager/src/config.rs +++ b/test/test-manager/src/config.rs @@ -8,13 +8,13 @@ use std::{ path::{Path, PathBuf}, }; -#[derive(err_derive::Error, Debug)] +#[derive(thiserror::Error, Debug)] pub enum Error { - #[error(display = "Failed to read config")] + #[error("Failed to read config")] Read(io::Error), - #[error(display = "Failed to parse config")] + #[error("Failed to parse config")] InvalidConfig(serde_json::Error), - #[error(display = "Failed to write config")] + #[error("Failed to write config")] Write(io::Error), } diff --git a/test/test-manager/src/logging.rs b/test/test-manager/src/logging.rs index 56f7401d65..cd0bd4af28 100644 --- a/test/test-manager/src/logging.rs +++ b/test/test-manager/src/logging.rs @@ -107,8 +107,8 @@ impl log::Log for Logger { fn flush(&self) {} } -#[derive(Debug, err_derive::Error)] -#[error(display = "Test panic: {}", _0)] +#[derive(Debug, thiserror::Error)] +#[error("Test panic: {0}")] pub struct PanicMessage(String); pub struct TestOutput { diff --git a/test/test-manager/src/summary.rs b/test/test-manager/src/summary.rs index 27ff2db572..c485ac6397 100644 --- a/test/test-manager/src/summary.rs +++ b/test/test-manager/src/summary.rs @@ -5,21 +5,20 @@ use tokio::{ io::{AsyncBufReadExt, AsyncWriteExt}, }; -#[derive(err_derive::Error, Debug)] -#[error(no_from)] +#[derive(thiserror::Error, Debug)] pub enum Error { - #[error(display = "Failed to open log file {:?}", _1)] - Open(#[error(source)] io::Error, std::path::PathBuf), - #[error(display = "Failed to write to log file")] - Write(#[error(source)] io::Error), - #[error(display = "Failed to read from log file")] - Read(#[error(source)] io::Error), - #[error(display = "Failed to parse log file")] + #[error("Failed to open log file {1:?}")] + Open(#[source] io::Error, std::path::PathBuf), + #[error("Failed to write to log file")] + Write(#[source] io::Error), + #[error("Failed to read from log file")] + Read(#[source] io::Error), + #[error("Failed to parse log file")] Parse, - #[error(display = "Failed to serialize value")] - Serialize(#[error(source)] serde_json::Error), - #[error(display = "Failed to deserialize value")] - Deserialize(#[error(source)] serde_json::Error), + #[error("Failed to serialize value")] + Serialize(#[source] serde_json::Error), + #[error("Failed to deserialize value")] + Deserialize(#[source] serde_json::Error), } #[derive(Clone, Copy)] diff --git a/test/test-manager/src/tests/mod.rs b/test/test-manager/src/tests/mod.rs index 7847bc2424..0e3e73a2f6 100644 --- a/test/test-manager/src/tests/mod.rs +++ b/test/test-manager/src/tests/mod.rs @@ -37,34 +37,34 @@ pub type TestWrapperFunction = Box< ) -> BoxFuture<'static, Result<(), Error>>, >; -#[derive(err_derive::Error, Debug)] +#[derive(thiserror::Error, Debug)] pub enum Error { - #[error(display = "RPC call failed")] - Rpc(#[source] test_rpc::Error), + #[error("RPC call failed")] + Rpc(#[from] test_rpc::Error), - #[error(display = "Timeout waiting for ping")] + #[error("Timeout waiting for ping")] PingTimeout, - #[error(display = "geoip lookup failed")] + #[error("geoip lookup failed")] GeoipLookup(test_rpc::Error), - #[error(display = "Found running daemon unexpectedly")] + #[error("Found running daemon unexpectedly")] DaemonRunning, - #[error(display = "Daemon unexpectedly not running")] + #[error("Daemon unexpectedly not running")] DaemonNotRunning, - #[error(display = "The daemon returned an error: {}", _0)] + #[error("The daemon returned an error: {0}")] Daemon(String), - #[error(display = "The daemon ended up in the error state")] + #[error("The daemon ended up in the error state")] UnexpectedErrorState(talpid_types::tunnel::ErrorState), - #[error(display = "The gRPC client ran into an error: {}", _0)] - ManagementInterface(#[source] mullvad_management_interface::Error), + #[error("The gRPC client ran into an error: {0}")] + ManagementInterface(#[from] mullvad_management_interface::Error), #[cfg(target_os = "macos")] - #[error(display = "An error occurred: {}", _0)] + #[error("An error occurred: {0}")] Other(String), } diff --git a/test/test-manager/src/vm/network/linux.rs b/test/test-manager/src/vm/network/linux.rs index ae4d708c01..d375fc2eb5 100644 --- a/test/test-manager/src/vm/network/linux.rs +++ b/test/test-manager/src/vm/network/linux.rs @@ -66,35 +66,34 @@ pub const NON_TUN_GATEWAY: Ipv4Addr = Ipv4Addr::new(172, 29, 1, 1); /// Name of the wireguard interface on the host pub const CUSTOM_TUN_INTERFACE_NAME: &str = "wg-relay0"; -#[derive(err_derive::Error, Debug)] -#[error(no_from)] +#[derive(thiserror::Error, Debug)] pub enum Error { - #[error(display = "Failed to start 'ip'")] + #[error("Failed to start 'ip'")] IpStart(io::Error), - #[error(display = "'ip' command failed: {}", _0)] + #[error("'ip' command failed: {0}")] IpFailed(i32), - #[error(display = "Failed to start 'sysctl'")] + #[error("Failed to start 'sysctl'")] SysctlStart(io::Error), - #[error(display = "'sysctl' failed: {}", _0)] + #[error("'sysctl' failed: {0}")] SysctlFailed(i32), - #[error(display = "Failed to start 'nft'")] + #[error("Failed to start 'nft'")] NftStart(io::Error), - #[error(display = "Failed to wait for 'nft'")] + #[error("Failed to wait for 'nft'")] NftRun(io::Error), - #[error(display = "'nft' command failed: {}", _0)] + #[error("'nft' command failed: {0}")] NftFailed(i32), - #[error(display = "Failed to create wg config")] - CreateWireguardConfig(#[error(source)] async_tempfile::Error), - #[error(display = "Failed to write wg config")] - WriteWireguardConfig(#[error(source)] io::Error), - #[error(display = "Failed to start 'wg'")] + #[error("Failed to create wg config")] + CreateWireguardConfig(#[source] async_tempfile::Error), + #[error("Failed to write wg config")] + WriteWireguardConfig(#[source] io::Error), + #[error("Failed to start 'wg'")] WgStart(io::Error), - #[error(display = "'wg' failed: {}", _0)] + #[error("'wg' failed: {0}")] WgFailed(i32), - #[error(display = "Failed to start 'dnsmasq'")] + #[error("Failed to start 'dnsmasq'")] DnsmasqStart(io::Error), - #[error(display = "Failed to create dnsmasq tempfile")] - CreateDnsmasqFile(#[error(source)] async_tempfile::Error), + #[error("Failed to create dnsmasq tempfile")] + CreateDnsmasqFile(#[source] async_tempfile::Error), } pub type Result<T> = std::result::Result<T, Error>; diff --git a/test/test-manager/src/vm/qemu.rs b/test/test-manager/src/vm/qemu.rs index 88f7f95430..5688f47101 100644 --- a/test/test-manager/src/vm/qemu.rs +++ b/test/test-manager/src/vm/qemu.rs @@ -25,30 +25,30 @@ const STDERR_LOG_LEVEL: log::Level = log::Level::Error; const STDOUT_LOG_LEVEL: log::Level = log::Level::Debug; const OBTAIN_IP_TIMEOUT: Duration = Duration::from_secs(60); -#[derive(err_derive::Error, Debug)] +#[derive(thiserror::Error, Debug)] pub enum Error { - #[error(display = "Failed to set up network")] - Network(network::linux::Error), - #[error(display = "Failed to start QEMU")] - StartQemu(io::Error), - #[error(display = "QEMU exited unexpectedly")] + #[error("Failed to set up network")] + Network(#[source] network::linux::Error), + #[error("Failed to start QEMU")] + StartQemu(#[source] io::Error), + #[error("QEMU exited unexpectedly")] QemuFailed(Option<ExitStatus>), - #[error(display = "Could not find pty")] + #[error("Could not find pty")] NoPty, - #[error(display = "Could not find IP address of guest")] + #[error("Could not find IP address of guest")] NoIpAddr, - #[error(display = "Failed to copy OVMF vars")] - CopyOvmfVars(io::Error), - #[error(display = "Failed to wrap OVMF vars copy in tempfile object")] + #[error("Failed to copy OVMF vars")] + CopyOvmfVars(#[source] io::Error), + #[error("Failed to wrap OVMF vars copy in tempfile object")] WrapOvmfVars, - #[error(display = "Failed to start swtpm")] - StartTpmEmulator(io::Error), - #[error(display = "swtpm failed")] - TpmEmulator(io::Error), - #[error(display = "Timed out waiting for swtpm socket")] + #[error("Failed to start swtpm")] + StartTpmEmulator(#[source] io::Error), + #[error("swtpm failed")] + TpmEmulator(#[source] io::Error), + #[error("Timed out waiting for swtpm socket")] TpmSocketTimeout, - #[error(display = "Failed to create temp dir")] - MkTempDir(io::Error), + #[error("Failed to create temp dir")] + MkTempDir(#[source] io::Error), } pub type Result<T> = std::result::Result<T, Error>; diff --git a/test/test-rpc/Cargo.toml b/test/test-rpc/Cargo.toml index 37335b599e..24596a09af 100644 --- a/test/test-rpc/Cargo.toml +++ b/test/test-rpc/Cargo.toml @@ -19,7 +19,7 @@ serde = { workspace = true } serde_json = { workspace = true } once_cell = { workspace = true } bytes = { workspace = true } -err-derive = { workspace = true } +thiserror = { workspace = true } log = { workspace = true } colored = { workspace = true } async-trait = { workspace = true } diff --git a/test/test-rpc/src/lib.rs b/test/test-rpc/src/lib.rs index d2bee40dbb..166a00d9a7 100644 --- a/test/test-rpc/src/lib.rs +++ b/test/test-rpc/src/lib.rs @@ -13,47 +13,47 @@ pub mod net; pub mod package; pub mod transport; -#[derive(err_derive::Error, Debug, Serialize, Deserialize, PartialEq, Eq)] +#[derive(thiserror::Error, Debug, Serialize, Deserialize, PartialEq, Eq)] pub enum Error { - #[error(display = "Test runner RPC failed")] - Tarpc(#[error(source)] tarpc::client::RpcError), - #[error(display = "Syscall failed")] + #[error("Test runner RPC failed")] + Tarpc(#[from] tarpc::client::RpcError), + #[error("Syscall failed")] Syscall, - #[error(display = "Interface not found")] + #[error("Interface not found")] InterfaceNotFound, - #[error(display = "HTTP request failed")] + #[error("HTTP request failed")] HttpRequest(String), - #[error(display = "Failed to deserialize HTTP body")] + #[error("Failed to deserialize HTTP body")] DeserializeBody, - #[error(display = "DNS resolution failed")] + #[error("DNS resolution failed")] DnsResolution, - #[error(display = "Test runner RPC timed out")] + #[error("Test runner RPC timed out")] TestRunnerTimeout, - #[error(display = "Package error")] - Package(#[error(source)] package::Error), - #[error(display = "Logger error")] - Logger(#[error(source)] logging::Error), - #[error(display = "Failed to send UDP datagram")] + #[error("Package error")] + Package(#[from] package::Error), + #[error("Logger error")] + Logger(#[from] logging::Error), + #[error("Failed to send UDP datagram")] SendUdp, - #[error(display = "Failed to send TCP segment")] + #[error("Failed to send TCP segment")] SendTcp, - #[error(display = "Failed to send ping")] + #[error("Failed to send ping")] Ping, - #[error(display = "Failed to get or set registry value")] + #[error("Failed to get or set registry value")] Registry(String), - #[error(display = "Failed to change the service")] + #[error("Failed to change the service")] Service(String), - #[error(display = "Could not read from or write to the file system")] + #[error("Could not read from or write to the file system")] FileSystem(String), - #[error(display = "Could not serialize or deserialize file")] + #[error("Could not serialize or deserialize file")] FileSerialization(String), - #[error(display = "User must be logged in but is not")] + #[error("User must be logged in but is not")] UserNotLoggedIn(String), - #[error(display = "Invalid URL")] + #[error("Invalid URL")] InvalidUrl, - #[error(display = "Timeout")] + #[error("Timeout")] Timeout, - #[error(display = "TCP forward error")] + #[error("TCP forward error")] TcpForward, } diff --git a/test/test-rpc/src/logging.rs b/test/test-rpc/src/logging.rs index a2156f6d9b..0e5205888b 100644 --- a/test/test-rpc/src/logging.rs +++ b/test/test-rpc/src/logging.rs @@ -4,11 +4,11 @@ use std::fmt; pub type Result<T> = std::result::Result<T, Error>; -#[derive(err_derive::Error, Serialize, Deserialize, Debug, PartialEq, Eq, Clone)] +#[derive(thiserror::Error, Serialize, Deserialize, Debug, PartialEq, Eq, Clone)] pub enum Error { - #[error(display = "Could not get standard output from runner")] + #[error("Could not get standard output from runner")] StandardOutput, - #[error(display = "Could not get mullvad app logs from runner")] + #[error("Could not get mullvad app logs from runner")] Logs(String), } diff --git a/test/test-rpc/src/package.rs b/test/test-rpc/src/package.rs index 89d6dce495..36b7f479ad 100644 --- a/test/test-rpc/src/package.rs +++ b/test/test-rpc/src/package.rs @@ -1,40 +1,36 @@ use serde::{Deserialize, Serialize}; use std::path::PathBuf; -#[derive(err_derive::Error, Debug, Deserialize, Serialize, PartialEq, Eq)] -#[error(no_from)] +#[derive(thiserror::Error, Debug, Deserialize, Serialize, PartialEq, Eq)] pub enum Error { - #[error(display = "Failed open file for writing")] + #[error("Failed open file for writing")] OpenFile, - #[error(display = "Failed to write downloaded file to disk")] + #[error("Failed to write downloaded file to disk")] WriteFile, - #[error(display = "Failed to convert download to bytes")] + #[error("Failed to convert download to bytes")] ToBytes, - #[error(display = "Failed to convert download to bytes")] + #[error("Failed to convert download to bytes")] RequestFailed, - #[error(display = "Cannot parse version")] + #[error("Cannot parse version")] InvalidVersion, - #[error(display = "Failed to run package installer")] + #[error("Failed to run package installer")] RunApp, - #[error(display = "Failed to create temporary uninstaller")] + #[error("Failed to create temporary uninstaller")] CreateTempUninstaller, - #[error( - display = "Installer or uninstaller failed due to an unknown error: {}", - _0 - )] + #[error("Installer or uninstaller failed due to an unknown error: {0}")] InstallerFailed(i32), - #[error(display = "Installer or uninstaller failed due to a signal")] + #[error("Installer or uninstaller failed due to a signal")] InstallerFailedSignal, - #[error(display = "Unrecognized OS: {}", _0)] + #[error("Unrecognized OS: {0}")] UnknownOs(String), } diff --git a/test/test-rpc/src/transport.rs b/test/test-rpc/src/transport.rs index 6a9f8b4588..b8086b4145 100644 --- a/test/test-rpc/src/transport.rs +++ b/test/test-rpc/src/transport.rs @@ -217,26 +217,25 @@ type ClientTransports = ( CompletionHandle, ); -#[derive(err_derive::Error, Debug)] -#[error(no_from)] +#[derive(thiserror::Error, Debug)] enum ForwardError { - #[error(display = "Failed to deserialize JSON data")] - DeserializeFailed(#[error(source)] serde_json::Error), + #[error("Failed to deserialize JSON data")] + DeserializeFailed(#[source] serde_json::Error), - #[error(display = "Failed to serialize JSON data")] - SerializeFailed(#[error(source)] serde_json::Error), + #[error("Failed to serialize JSON data")] + SerializeFailed(#[source] serde_json::Error), - #[error(display = "Serial connection error")] - SerialConnection(#[error(source)] io::Error), + #[error("Serial connection error")] + SerialConnection(#[source] io::Error), - #[error(display = "Test runner channel error")] - TestRunnerChannel(#[error(source)] tarpc::transport::channel::ChannelError), + #[error("Test runner channel error")] + TestRunnerChannel(#[source] tarpc::transport::channel::ChannelError), - #[error(display = "Daemon channel error")] - DaemonChannel(#[error(source)] io::Error), + #[error("Daemon channel error")] + DaemonChannel(#[source] io::Error), - #[error(display = "Handshake error")] - HandshakeError(#[error(source)] io::Error), + #[error("Handshake error")] + HandshakeError(#[source] io::Error), } async fn forward_messages< diff --git a/test/test-runner/Cargo.toml b/test/test-runner/Cargo.toml index 1a0163213f..dbe57c938e 100644 --- a/test/test-runner/Cargo.toml +++ b/test/test-runner/Cargo.toml @@ -15,7 +15,7 @@ futures = { workspace = true } tarpc = { workspace = true } tokio = { workspace = true } tokio-serial = { workspace = true } -err-derive = { workspace = true } +thiserror = { workspace = true } log = { workspace = true } once_cell = { workspace = true } parity-tokio-ipc = "0.9" diff --git a/test/test-runner/src/main.rs b/test/test-runner/src/main.rs index 74f7761cc2..befeeb61e0 100644 --- a/test/test-runner/src/main.rs +++ b/test/test-runner/src/main.rs @@ -325,9 +325,9 @@ fn get_pipe_status() -> ServiceStatus { /// Keep this constant in sync with `test-manager/src/run_tests.rs` const BAUD: u32 = if cfg!(target_os = "macos") { 0 } else { 115200 }; -#[derive(err_derive::Error, Debug)] +#[derive(thiserror::Error, Debug)] pub enum Error { - #[error(display = "Unknown RPC")] + #[error("Unknown RPC")] UnknownRpc, } diff --git a/tunnel-obfuscation/Cargo.toml b/tunnel-obfuscation/Cargo.toml index b1bc9f1f07..25c6951352 100644 --- a/tunnel-obfuscation/Cargo.toml +++ b/tunnel-obfuscation/Cargo.toml @@ -12,6 +12,6 @@ workspace = true [dependencies] async-trait = "0.1" -err-derive = { workspace = true } +thiserror = { workspace = true } tokio = { workspace = true, features = ["rt-multi-thread", "macros", "net", "io-util"] } udp-over-tcp = { git = "https://github.com/mullvad/udp-over-tcp", rev = "87936ac29b68b902565955f138ab02294bcc8593" } diff --git a/tunnel-obfuscation/src/lib.rs b/tunnel-obfuscation/src/lib.rs index 07ab422dd7..d1a0fa46e0 100644 --- a/tunnel-obfuscation/src/lib.rs +++ b/tunnel-obfuscation/src/lib.rs @@ -6,14 +6,13 @@ pub use udp2tcp::Udp2TcpSettings; 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 = "Failed to create Udp2Tcp obfuscator")] - CreateUdp2TcpObfuscator(#[error(source)] udp2tcp::Error), + #[error("Failed to create Udp2Tcp obfuscator")] + CreateUdp2TcpObfuscator(#[source] udp2tcp::Error), - #[error(display = "Failed to run Udp2Tcp obfuscator")] - RunUdp2TcpObfuscator(#[error(source)] udp2tcp::Error), + #[error("Failed to run Udp2Tcp obfuscator")] + RunUdp2TcpObfuscator(#[source] udp2tcp::Error), } #[async_trait] diff --git a/tunnel-obfuscation/src/udp2tcp.rs b/tunnel-obfuscation/src/udp2tcp.rs index 0eada9b928..9469441564 100644 --- a/tunnel-obfuscation/src/udp2tcp.rs +++ b/tunnel-obfuscation/src/udp2tcp.rs @@ -14,20 +14,19 @@ pub struct Udp2TcpSettings { pub type Result<T> = std::result::Result<T, Error>; -#[derive(err_derive::Error, Debug)] -#[error(no_from)] +#[derive(thiserror::Error, Debug)] pub enum Error { /// Failed to create obfuscator - #[error(display = "Failed to create obfuscator")] - CreateObfuscator(#[error(source)] udp2tcp::Error), + #[error("Failed to create obfuscator")] + CreateObfuscator(#[source] udp2tcp::Error), /// Failed to determine UDP socket details - #[error(display = "Failed to determine UDP socket details")] - GetUdpSocketDetails(#[error(source)] std::io::Error), + #[error("Failed to determine UDP socket details")] + GetUdpSocketDetails(#[source] std::io::Error), /// Failed to run obfuscator - #[error(display = "Failed to run obfuscator")] - RunObfuscator(#[error(source)] udp2tcp::Error), + #[error("Failed to run obfuscator")] + RunObfuscator(#[source] udp2tcp::Error), } struct Udp2Tcp { |
