~qaul/community

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch

[PATCH] Replace failure with thiserror

Alyssa Ross <hi@alyssa.is>
Details
Message ID
<20210228022154.12619-1-hi@alyssa.is>
DKIM signature
missing
Download raw message
Patch: +47 -108
failure is unmaintained.  The replacement for the derive bits of
failure (which is all we were using) is thiserror, so switch to using
that.

The main difference is that failure had to implement a bunch of stuff
itself that has since been added to the standard library, so the
replacements use the stuff in std rather than rolling their own.
---
 Cargo.lock                      | 103 +++++++-------------------------
 netmods/netmod-tcp/Cargo.toml   |   2 +-
 netmods/netmod-tcp/src/error.rs |  10 ++--
 utils/alexandria/Cargo.toml     |   2 +-
 utils/alexandria/src/error.rs   |  38 ++++++------
 5 files changed, 47 insertions(+), 108 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock
index 623cf3ec..f8fe4ffe 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1,20 +1,5 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "addr2line"
version = "0.14.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a55f82cfe485775d02112886f4169bde0c5894d75e79ead7eafe7e40a25e45f7"
dependencies = [
 "gimli",
]

[[package]]
name = "adler"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee2a4ec343196209d6594e19543ae87a39f96d5534d7174822a3ad825dd6ed7e"

[[package]]
name = "aho-corasick"
version = "0.7.15"
@@ -33,7 +18,6 @@ dependencies = [
 "bincode",
 "chrono",
 "ed25519-dalek",
 "failure",
 "hex",
 "keybob",
 "rand 0.7.3",
@@ -42,6 +26,7 @@ dependencies = [
 "serde_json",
 "sodiumoxide",
 "tempfile",
 "thiserror",
 "tracing",
 "tracing-futures",
]
@@ -196,20 +181,6 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"

[[package]]
name = "backtrace"
version = "0.3.56"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d117600f438b1707d4e4ae15d3595657288f8235a0eb593e80ecc98ab34e1bc"
dependencies = [
 "addr2line",
 "cfg-if 1.0.0",
 "libc",
 "miniz_oxide",
 "object",
 "rustc-demangle",
]

[[package]]
name = "base64"
version = "0.9.3"
@@ -732,28 +703,6 @@ dependencies = [
 "version_check",
]

[[package]]
name = "failure"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d32e9bd16cc02eae7db7ef620b392808b89f6a5e16bb3497d159c6b92a0f4f86"
dependencies = [
 "backtrace",
 "failure_derive",
]

[[package]]
name = "failure_derive"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4"
dependencies = [
 "proc-macro2",
 "quote",
 "syn",
 "synstructure",
]

[[package]]
name = "fake-simd"
version = "0.1.2"
@@ -971,12 +920,6 @@ dependencies = [
 "wasi 0.10.2+wasi-snapshot-preview1",
]

[[package]]
name = "gimli"
version = "0.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6503fe142514ca4799d4c26297c4248239fe8838d827db6bd6065c6ed29a6ce"

[[package]]
name = "glob"
version = "0.2.11"
@@ -1348,16 +1291,6 @@ version = "0.3.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d"

[[package]]
name = "miniz_oxide"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f2d26ec3309788e423cfbf68ad1800f061638098d76a83681af979dc4eda19d"
dependencies = [
 "adler",
 "autocfg",
]

[[package]]
name = "mio"
version = "0.6.23"
@@ -1443,10 +1376,10 @@ dependencies = [
 "async-trait",
 "bincode",
 "byteorder",
 "failure",
 "ratman-identity 0.6.0",
 "ratman-netmod 0.3.0",
 "serde",
 "thiserror",
 "tracing",
 "tracing-futures",
]
@@ -1516,12 +1449,6 @@ dependencies = [
 "libc",
]

[[package]]
name = "object"
version = "0.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a9a7ab5d64814df0fe4a4b5ead45ed6c5f181ee3ff04ba344313a6c80446c5d4"

[[package]]
name = "once_cell"
version = "1.6.0"
@@ -2142,12 +2069,6 @@ dependencies = [
 "crossbeam-utils 0.8.2",
]

[[package]]
name = "rustc-demangle"
version = "0.1.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e3bad0ee36814ca07d7968269dd4b7ec89ec2da10c4bb613928d3077083c232"

[[package]]
name = "rustc-hash"
version = "1.1.0"
@@ -2488,6 +2409,26 @@ dependencies = [
 "unicode-width",
]

[[package]]
name = "thiserror"
version = "1.0.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e0f4a65597094d4483ddaed134f409b2cb7c1beccf25201a9f73c719254fa98e"
dependencies = [
 "thiserror-impl",
]

[[package]]
name = "thiserror-impl"
version = "1.0.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7765189610d8241a44529806d6fd1f2e0a08734313a35d5b3a556f92b381f3c0"
dependencies = [
 "proc-macro2",
 "quote",
 "syn",
]

[[package]]
name = "thread_local"
version = "1.1.3"
diff --git a/netmods/netmod-tcp/Cargo.toml b/netmods/netmod-tcp/Cargo.toml
index c6c09cb6..c2d5a117 100644
--- a/netmods/netmod-tcp/Cargo.toml
+++ b/netmods/netmod-tcp/Cargo.toml
@@ -14,7 +14,7 @@ async-std = { version = "=1.5", features = ["attributes", "unstable"] }
async-trait = "0.1"
bincode = "1.0"
byteorder = "1.0"
failure = "0.1"
thiserror = "1.0"
serde = { version = "1.0", features = ["derive"] }
tracing = "0.1"
tracing-futures = "0.2"
diff --git a/netmods/netmod-tcp/src/error.rs b/netmods/netmod-tcp/src/error.rs
index c3a32ae7..2e17aedd 100644
--- a/netmods/netmod-tcp/src/error.rs
+++ b/netmods/netmod-tcp/src/error.rs
@@ -1,17 +1,15 @@
//! TCP ovelay specific error handling

use failure::Fail;

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

/// A generic initialisation error
#[derive(Debug, Fail)]
#[derive(Debug, thiserror::Error)]
pub enum Error {
    #[fail(display = "the selected mode does not allow for this operation")]
    #[error("the selected mode does not allow for this operation")]
    InvalidMode,
    #[fail(display = "failed to initialise socket: invalid address")]
    #[error("failed to initialise socket: invalid address")]
    InvalidAddr,
    #[fail(display = "failed to send packet!")]
    #[error("failed to send packet!")]
    FailedToSend
}

diff --git a/utils/alexandria/Cargo.toml b/utils/alexandria/Cargo.toml
index 702e7646..506f3b4b 100644
--- a/utils/alexandria/Cargo.toml
+++ b/utils/alexandria/Cargo.toml
@@ -15,7 +15,7 @@ alexandria-tags = { path = "../alexandria-tags" }
async-std = { version = "=1.5", features = ["unstable", "attributes"] }
bincode = "1.0"
chrono = { version = "0.4", features = ["serde"] }
failure = "0.1"
thiserror = "1.0"
hex = "0.4"
keybob = "0.3"
serde = { version = "1.0", features = ["derive", "rc"] }
diff --git a/utils/alexandria/src/error.rs b/utils/alexandria/src/error.rs
index c22086ac..c7e68bf2 100644
--- a/utils/alexandria/src/error.rs
+++ b/utils/alexandria/src/error.rs
@@ -11,59 +11,59 @@
//! on `Error`.  These can be bugs in Alexandria itself, or some
//! runtime constraint like having run out of memory or disk space.

use failure::Fail;
use std::fmt::{self, Display, Formatter};

/// Common alexandria error fascade
#[derive(Debug, Fail)]
#[derive(Debug, thiserror::Error)]
pub enum Error {
    #[fail(display = "failed to add a user that already exits")]
    #[error("failed to add a user that already exits")]
    UserAlreadyExists,

    #[fail(display = "operation failed because user `{}` doesn't exist", id)]
    #[error("operation failed because user `{}` doesn't exist", id)]
    NoSuchUser { id: String },

    #[fail(display = "failed to initialise library at offset `{}`", offset)]
    #[error("failed to initialise library at offset `{}`", offset)]
    InitFailed { offset: String },

    #[fail(display = "failed to perform action because user `{}` is locked", id)]
    #[error("failed to perform action because user `{}` is locked", id)]
    UserNotOpen { id: String },

    #[fail(display = "bad unlock token (password?) for id `{}`", id)]
    #[error("bad unlock token (password?) for id `{}`", id)]
    UnlockFailed { id: String },

    #[fail(display = "tried to operate on locked encrypted state: {}", msg)]
    #[error("tried to operate on locked encrypted state: {}", msg)]
    LockedState { msg: String },

    #[fail(display = "tried to unlock user Id `{}` twice", id)]
    #[error("tried to unlock user Id `{}` twice", id)]
    AlreadyUnlocked { id: String },

    #[fail(display = "no such path: `{}`", path)]
    #[error("no such path: `{}`", path)]
    NoSuchPath { path: String },

    #[fail(display = "path exists already: {}", path)]
    #[error("path exists already: {}", path)]
    PathExists { path: String },

    #[fail(display = "failed to load data: `{}`", msg)]
    #[error("failed to load data: `{}`", msg)]
    LoadFailed { msg: String },

    #[fail(display = "failed to sync data: `{}`", msg)]
    #[error("failed to sync data: `{}`", msg)]
    SyncFailed { msg: String },

    #[fail(display = "tried to apply Diff of incompatible type")]
    #[error("tried to apply Diff of incompatible type")]
    BadDiffType,

    #[fail(display = "a Diff failed to apply: \n{}", msgs)]
    #[error("a Diff failed to apply: \n{}", msgs)]
    BadDiff { msgs: DiffErrors },

    #[fail(
        display = "can't merge two iterators with different underlying queries: a: '{}', b: '{}'",
        q1, q2
    #[error(
        "can't merge two iterators with different underlying queries: a: '{}', b: '{}'",
        q1,
        q2
    )]
    IncompatibleQuery { q1: String, q2: String },

    #[doc(hidden)]
    #[fail(display = "An alexandria internal error occured: `{}`", msg)]
    #[error("An alexandria internal error occured: `{}`", msg)]
    InternalError { msg: String },
}

-- 
2.30.0
Reply to thread Export thread (mbox)