Skip to content

Commit c31188d

Browse files
authored
Replace failure with thiserror (#70)
1 parent 2d648f3 commit c31188d

File tree

5 files changed

+18
-19
lines changed

5 files changed

+18
-19
lines changed

influxdb/Cargo.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ repository = "https://github.com/Empty2k12/influxdb-rust"
1616
travis-ci = { repository = "Empty2k12/influxdb-rust", branch = "master" }
1717

1818
[dependencies]
19-
chrono = { version = "0.4.11", features = ["serde"] }
20-
failure = "0.1.7"
19+
chrono = { version = "0.4.11", features = ["serde"] }
2120
futures = "0.3.4"
21+
lazy_static = "1.4.0"
2222
influxdb_derive = { version = "0.1.0", optional = true }
23+
regex = "1.3.5"
2324
reqwest = { version = "0.10.4", features = ["json"] }
2425
serde = { version = "1.0.104", features = ["derive"], optional = true }
2526
serde_json = { version = "1.0.48", optional = true }
26-
regex = "1.3.5"
27-
lazy_static = "1.4.0"
27+
thiserror = "1.0"
2828

2929
[features]
3030
use-serde = ["serde", "serde_json"]

influxdb/src/client/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ impl Client {
166166
/// use std::time::{SystemTime, UNIX_EPOCH};
167167
///
168168
/// # #[tokio::main]
169-
/// # async fn main() -> Result<(), failure::Error> {
169+
/// # async fn main() -> Result<(), influxdb::Error> {
170170
/// let start = SystemTime::now();
171171
/// let since_the_epoch = start
172172
/// .duration_since(UNIX_EPOCH)

influxdb/src/error.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,41 @@
11
//! Errors that might happen in the crate
22
3-
#[derive(Debug, Fail)]
3+
use thiserror::Error;
4+
5+
#[derive(Debug, Error)]
46
pub enum Error {
5-
#[fail(display = "query is invalid: {}", error)]
7+
#[error("query is invalid: {error}")]
68
/// Error happens when a query is invalid
79
InvalidQueryError { error: String },
810

9-
#[fail(display = "Failed to build URL: {}", error)]
11+
#[error("Failed to build URL: {error}")]
1012
/// Error happens when a query is invalid
1113
UrlConstructionError { error: String },
1214

13-
#[fail(display = "http protocol error: {}", error)]
15+
#[error("http protocol error: {error}")]
1416
/// Error happens when a query is invalid
1517
ProtocolError { error: String },
1618

17-
#[fail(display = "http protocol error: {}", error)]
19+
#[error("http protocol error: {error}")]
1820
/// Error happens when Serde cannot deserialize the response
1921
DeserializationError { error: String },
2022

21-
#[fail(display = "InfluxDB encountered the following error: {}", error)]
23+
#[error("InfluxDB encountered the following error: {error}")]
2224
/// Error which has happened inside InfluxDB
2325
DatabaseError { error: String },
2426

25-
#[fail(display = "authentication error. No or incorrect credentials")]
27+
#[error("authentication error. No or incorrect credentials")]
2628
/// Error happens when no or incorrect credentials are used. `HTTP 401 Unauthorized`
2729
AuthenticationError,
2830

29-
#[fail(display = "authorization error. User not authorized")]
31+
#[error("authorization error. User not authorized")]
3032
/// Error happens when the supplied user is not authorized. `HTTP 403 Forbidden`
3133
AuthorizationError,
3234

33-
#[fail(display = "connection error: {}", error)]
35+
#[error("connection error: {error}")]
3436
/// Error happens when reqwest fails
3537
ConnectionError {
36-
#[fail(cause)]
38+
#[from]
3739
error: reqwest::Error,
3840
},
3941
}

influxdb/src/integrations/serde_integration/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
//! }
2424
//!
2525
//! # #[tokio::main]
26-
//! # async fn main() -> Result<(), failure::Error> {
26+
//! # async fn main() -> Result<(), influxdb::Error> {
2727
//! let client = Client::new("http://localhost:8086", "test");
2828
//! let query = Query::raw_read_query(
2929
//! "SELECT temperature FROM /weather_[a-z]*$/ WHERE time > now() - 1m ORDER BY DESC",

influxdb/src/lib.rs

-3
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@
7373
7474
#![allow(clippy::needless_doctest_main)]
7575

76-
#[macro_use]
77-
extern crate failure;
78-
7976
mod client;
8077
mod error;
8178
mod query;

0 commit comments

Comments
 (0)