Skip to content

Commit 381ed77

Browse files
committed
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.
1 parent 3543421 commit 381ed77

File tree

146 files changed

+1341
-1480
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

146 files changed

+1341
-1480
lines changed

Cargo.lock

+51-51
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ prost = "0.12.0"
5656
prost-types = "0.12.0"
5757

5858
env_logger = "0.10.0"
59-
err-derive = "0.3.1"
59+
thiserror = "1.0.57"
6060
log = "0.4"
6161

6262
shadowsocks = { version = "1.16" }

android/translations-converter/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ rust-version.workspace = true
1111
workspace = true
1212

1313
[dependencies]
14-
err-derive = { workspace = true }
14+
thiserror = { workspace = true }
1515
htmlize = { version = "1.0.2", features = ["unescape"] }
1616
once_cell = { workspace = true }
1717
regex = "1"

android/translations-converter/src/gettext/messages.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,13 @@ impl From<MsgString> for MsgValue {
103103
}
104104
}
105105

106-
#[derive(Debug, err_derive::Error)]
106+
#[derive(Debug, thiserror::Error)]
107107
pub enum Error {
108108
/// Parser error while parsing file
109-
#[error(display = "Failed to parse input file")]
110-
Parse(#[error(source)] super::parser::Error),
109+
#[error("Failed to parse input file")]
110+
Parse(#[from] super::parser::Error),
111111

112112
/// IO error while reading input file.
113-
#[error(display = "Failed to read from the input file")]
114-
Io(#[error(source)] std::io::Error),
113+
#[error("Failed to read from the input file")]
114+
Io(#[from] std::io::Error),
115115
}

android/translations-converter/src/gettext/parser.rs

+7-13
Original file line numberDiff line numberDiff line change
@@ -526,35 +526,29 @@ fn collect_variants(
526526
}
527527

528528
/// Parsing errors.
529-
#[derive(Clone, Debug, Eq, PartialEq, err_derive::Error)]
529+
#[derive(Clone, Debug, Eq, PartialEq, thiserror::Error)]
530530
pub enum Error {
531531
/// An unexpected line was read while parsing.
532-
#[error(display = "Unexpected line parsing gettext messages: {}", _0)]
532+
#[error("Unexpected line parsing gettext messages: {0}")]
533533
UnexpectedLine(String),
534534

535535
/// Input uses an unrecognized plural forumal.
536-
#[error(
537-
display = "Input uses an unrecognized formula for the plural form: {}",
538-
_0
539-
)]
536+
#[error("Input uses an unrecognized formula for the plural form: {0}")]
540537
UnrecognizedPluralFormula(String),
541538

542539
/// Input ended with an incomplete entry.
543-
#[error(
544-
display = "Input ended with an incomplete gettext entry with ID: {}",
545-
_0
546-
)]
540+
#[error("Input ended with an incomplete gettext entry with ID: {0}")]
547541
IncompleteEntry(MsgString),
548542

549543
/// Plural entry definition is missing a plural variant.
550-
#[error(display = "Plural entry is missing a plural variant: {}", _0)]
544+
#[error("Plural entry is missing a plural variant: {0}")]
551545
IncompletePluralEntry(MsgString),
552546

553547
/// Plural variant is invalid.
554-
#[error(display = "Plural variant line is invalid: {}", _0)]
548+
#[error("Plural variant line is invalid: {0}")]
555549
InvalidPluralVariant(String),
556550

557551
/// Plural variant index was not parsable.
558-
#[error(display = "Plural variant line contains an invalid index: {}", _0)]
552+
#[error("Plural variant line contains an invalid index: {0}")]
559553
InvalidPluralIndex(String),
560554
}

android/translations-converter/src/gettext/plural_form.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ impl FromStr for PluralForm {
4444
/// Failed to create [`PluralForm`] from specified plural formula.
4545
///
4646
/// The formula could be an invalid formula, or support for it hasn't been added yet.
47-
#[derive(Clone, Debug, err_derive::Error)]
48-
#[error(display = "Unsupported plural formula: {}", _0)]
47+
#[derive(Clone, Debug, thiserror::Error)]
48+
#[error("Unsupported plural formula: {0}")]
4949
pub struct UnsupportedPluralFormulaError(String);

mullvad-api/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ api-override = []
1717
[dependencies]
1818
libc = "0.2"
1919
chrono = { workspace = true }
20-
err-derive = { workspace = true }
20+
thiserror = { workspace = true }
2121
futures = "0.3"
2222
http = "0.2"
2323
hyper = { version = "0.14", features = ["client", "stream", "http1", "tcp" ] }

mullvad-api/src/abortable_stream.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use std::{
1212
};
1313
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
1414

15-
#[derive(err_derive::Error, Debug)]
16-
#[error(display = "Stream is closed")]
15+
#[derive(thiserror::Error, Debug)]
16+
#[error("Stream is closed")]
1717
pub struct Aborted(());
1818

1919
#[derive(Clone, Debug)]

mullvad-api/src/address_cache.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,19 @@ use tokio::{
88
sync::Mutex,
99
};
1010

11-
#[derive(err_derive::Error, Debug)]
12-
#[error(no_from)]
11+
#[derive(thiserror::Error, Debug)]
1312
pub enum Error {
14-
#[error(display = "Failed to open the address cache file")]
15-
Open(#[error(source)] io::Error),
13+
#[error("Failed to open the address cache file")]
14+
Open(#[source] io::Error),
1615

17-
#[error(display = "Failed to read the address cache file")]
18-
Read(#[error(source)] io::Error),
16+
#[error("Failed to read the address cache file")]
17+
Read(#[source] io::Error),
1918

20-
#[error(display = "Failed to parse the address cache file")]
19+
#[error("Failed to parse the address cache file")]
2120
Parse,
2221

23-
#[error(display = "Failed to update the address cache file")]
24-
Write(#[error(source)] io::Error),
22+
#[error("Failed to update the address cache file")]
23+
Write(#[source] io::Error),
2524
}
2625

2726
#[derive(Clone)]

mullvad-api/src/availability.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ const CHANNEL_CAPACITY: usize = 100;
1111
/// called for this long.
1212
const INACTIVITY_TIME: Duration = Duration::from_secs(3 * 24 * 60 * 60);
1313

14-
#[derive(err_derive::Error, Debug)]
14+
#[derive(thiserror::Error, Debug)]
1515
pub enum Error {
1616
/// The [`ApiAvailability`] instance was dropped, or the receiver lagged behind.
17-
#[error(display = "API availability instance was dropped")]
18-
Interrupted(#[error(source)] broadcast::error::RecvError),
17+
#[error("API availability instance was dropped")]
18+
Interrupted(#[from] broadcast::error::RecvError),
1919
}
2020

2121
#[derive(PartialEq, Eq, Clone, Copy, Debug, Default)]

mullvad-api/src/https_client_with_sni.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,9 @@ struct SocksConfig {
222222
authentication: Option<proxy::SocksAuth>,
223223
}
224224

225-
#[derive(err_derive::Error, Debug)]
225+
#[derive(thiserror::Error, Debug)]
226226
enum ProxyConfigError {
227-
#[error(display = "Unrecognized cipher selected: {}", _0)]
227+
#[error("Unrecognized cipher selected: {0}")]
228228
InvalidCipher(String),
229229
}
230230

mullvad-api/src/lib.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -314,16 +314,16 @@ pub struct Runtime {
314314
socket_bypass_tx: Option<mpsc::Sender<SocketBypassRequest>>,
315315
}
316316

317-
#[derive(err_derive::Error, Debug)]
317+
#[derive(thiserror::Error, Debug)]
318318
pub enum Error {
319-
#[error(display = "Failed to construct a rest client")]
320-
RestError(#[error(source)] rest::Error),
319+
#[error("Failed to construct a rest client")]
320+
RestError(#[from] rest::Error),
321321

322-
#[error(display = "Failed to load address cache")]
323-
AddressCacheError(#[error(source)] address_cache::Error),
322+
#[error("Failed to load address cache")]
323+
AddressCacheError(#[from] address_cache::Error),
324324

325-
#[error(display = "API availability check failed")]
326-
ApiCheckError(#[error(source)] availability::Error),
325+
#[error("API availability check failed")]
326+
ApiCheckError(#[from] availability::Error),
327327
}
328328

329329
impl Runtime {

mullvad-api/src/rest.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -34,38 +34,38 @@ pub type Result<T> = std::result::Result<T, Error>;
3434
const DEFAULT_TIMEOUT: Duration = Duration::from_secs(10);
3535

3636
/// Describes all the ways a REST request can fail
37-
#[derive(err_derive::Error, Debug, Clone)]
37+
#[derive(thiserror::Error, Debug, Clone)]
3838
pub enum Error {
39-
#[error(display = "REST client service is down")]
39+
#[error("REST client service is down")]
4040
RestServiceDown,
4141

42-
#[error(display = "Request cancelled")]
42+
#[error("Request cancelled")]
4343
Aborted,
4444

45-
#[error(display = "Hyper error")]
46-
HyperError(#[error(source)] Arc<hyper::Error>),
45+
#[error("Hyper error")]
46+
HyperError(#[from] Arc<hyper::Error>),
4747

48-
#[error(display = "Invalid header value")]
48+
#[error("Invalid header value")]
4949
InvalidHeaderError,
5050

51-
#[error(display = "HTTP error")]
52-
HttpError(#[error(source)] Arc<http::Error>),
51+
#[error("HTTP error")]
52+
HttpError(#[from] Arc<http::Error>),
5353

54-
#[error(display = "Request timed out")]
54+
#[error("Request timed out")]
5555
TimeoutError,
5656

57-
#[error(display = "Failed to deserialize data")]
58-
DeserializeError(#[error(source)] Arc<serde_json::Error>),
57+
#[error("Failed to deserialize data")]
58+
DeserializeError(#[from] Arc<serde_json::Error>),
5959

6060
/// Unexpected response code
61-
#[error(display = "Unexpected response status code {} - {}", _0, _1)]
61+
#[error("Unexpected response status code {0} - {1}")]
6262
ApiError(StatusCode, String),
6363

6464
/// The string given was not a valid URI.
65-
#[error(display = "Not a valid URI")]
65+
#[error("Not a valid URI")]
6666
InvalidUri,
6767

68-
#[error(display = "Set account token on factory with no access token store")]
68+
#[error("Set account token on factory with no access token store")]
6969
NoAccessTokenStore,
7070
}
7171

mullvad-cli/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ path = "src/main.rs"
1818
anyhow = "1.0"
1919
chrono = { workspace = true }
2020
clap = { workspace = true }
21-
err-derive = { workspace = true }
21+
thiserror = { workspace = true }
2222
futures = "0.3"
2323
itertools = "0.10"
2424
natord = "1.0.9"

mullvad-cli/src/cmds/proxies.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ use talpid_types::net::{
55
Endpoint, TransportProtocol,
66
};
77

8-
#[derive(err_derive::Error, Debug)]
8+
#[derive(thiserror::Error, Debug)]
99
pub enum Error {
10-
#[error(display = "{}", _0)]
11-
InvalidAuth(#[error(source)] talpid_types::net::proxy::Error),
10+
#[error("{0}")]
11+
InvalidAuth(#[from] talpid_types::net::proxy::Error),
1212
}
1313

1414
#[derive(Args, Debug, Clone)]

mullvad-daemon/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ api-override = ["mullvad-api/api-override"]
1616

1717
[dependencies]
1818
chrono = { workspace = true }
19-
err-derive = { workspace = true }
19+
thiserror = { workspace = true }
2020
fern = { version = "0.6", features = ["colored"] }
2121
futures = "0.3"
2222
once_cell = { workspace = true }

mullvad-daemon/src/access_method.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,27 @@ use mullvad_types::{
55
settings::Settings,
66
};
77

8-
#[derive(err_derive::Error, Debug)]
8+
#[derive(thiserror::Error, Debug)]
99
pub enum Error {
1010
/// Can not add access method
11-
#[error(display = "Cannot add custom access method")]
11+
#[error("Cannot add custom access method")]
1212
Add,
1313
/// Can not find access method
14-
#[error(display = "Cannot find custom access method {}", _0)]
14+
#[error("Cannot find custom access method {0}")]
1515
NoSuchMethod(access_method::Id),
1616
/// Some error occured in the daemon's state of handling
1717
/// [`AccessMethodSetting`]s & [`ApiConnectionMode`]s
18-
#[error(display = "Error occured when handling connection settings & details")]
19-
ApiService(#[error(source)] api::Error),
18+
#[error("Error occured when handling connection settings & details")]
19+
ApiService(#[from] api::Error),
2020
/// A REST request failed
21-
#[error(display = "Reset request failed")]
22-
Rest(#[error(source)] rest::Error),
21+
#[error("Reset request failed")]
22+
Rest(#[from] rest::Error),
2323
/// Something went wrong in the [`access_method`](mod@access_method) module.
24-
#[error(display = "Access method error")]
25-
AccessMethod(#[error(source)] access_method::Error),
24+
#[error("Access method error")]
25+
AccessMethod(#[from] access_method::Error),
2626
/// Access methods settings error
27-
#[error(display = "Settings error")]
28-
Settings(#[error(source)] settings::Error),
27+
#[error("Settings error")]
28+
Settings(#[from] settings::Error),
2929
}
3030

3131
impl<L> Daemon<L>

mullvad-daemon/src/account_history.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,19 @@ use tokio::{
1010

1111
pub type Result<T> = std::result::Result<T, Error>;
1212

13-
#[derive(err_derive::Error, Debug)]
14-
#[error(no_from)]
13+
#[derive(thiserror::Error, Debug)]
1514
pub enum Error {
16-
#[error(display = "Unable to open or read account history file")]
17-
Read(#[error(source)] io::Error),
15+
#[error("Unable to open or read account history file")]
16+
Read(#[source] io::Error),
1817

19-
#[error(display = "Failed to serialize account history")]
20-
Serialize(#[error(source)] serde_json::Error),
18+
#[error("Failed to serialize account history")]
19+
Serialize(#[source] serde_json::Error),
2120

22-
#[error(display = "Unable to write account history file")]
23-
Write(#[error(source)] io::Error),
21+
#[error("Unable to write account history file")]
22+
Write(#[source] io::Error),
2423

25-
#[error(display = "Write task panicked or was cancelled")]
26-
WriteCancelled(#[error(source)] tokio::task::JoinError),
24+
#[error("Write task panicked or was cancelled")]
25+
WriteCancelled(#[source] tokio::task::JoinError),
2726
}
2827

2928
static ACCOUNT_HISTORY_FILE: &str = "account-history.json";

mullvad-daemon/src/api.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,16 @@ pub struct ResolvedConnectionMode {
9797

9898
/// Describes all the ways the daemon service which handles access methods can
9999
/// fail.
100-
#[derive(err_derive::Error, Debug)]
100+
#[derive(thiserror::Error, Debug)]
101101
pub enum Error {
102-
#[error(display = "No access methods were provided.")]
102+
#[error("No access methods were provided.")]
103103
NoAccessMethods,
104-
#[error(display = "AccessModeSelector is not receiving any messages.")]
105-
SendFailed(#[error(source)] mpsc::TrySendError<Message>),
106-
#[error(display = "AccessModeSelector is not receiving any messages.")]
104+
#[error("AccessModeSelector is not receiving any messages.")]
105+
SendFailed(#[from] mpsc::TrySendError<Message>),
106+
#[error("AccessModeSelector is not receiving any messages.")]
107107
OneshotSendFailed,
108-
#[error(display = "AccessModeSelector is not responding.")]
109-
NotRunning(#[error(source)] oneshot::Canceled),
108+
#[error("AccessModeSelector is not responding.")]
109+
NotRunning(#[from] oneshot::Canceled),
110110
}
111111

112112
impl std::fmt::Display for Message {

0 commit comments

Comments
 (0)