Skip to content

Replace failure with thiserror #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions influxdb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ repository = "https://github.com/Empty2k12/influxdb-rust"
travis-ci = { repository = "Empty2k12/influxdb-rust", branch = "master" }

[dependencies]
chrono = { version = "0.4.11", features = ["serde"] }
failure = "0.1.7"
chrono = { version = "0.4.11", features = ["serde"] }
futures = "0.3.4"
lazy_static = "1.4.0"
influxdb_derive = { version = "0.1.0", optional = true }
regex = "1.3.5"
reqwest = { version = "0.10.4", features = ["json"] }
serde = { version = "1.0.104", features = ["derive"], optional = true }
serde_json = { version = "1.0.48", optional = true }
regex = "1.3.5"
lazy_static = "1.4.0"
thiserror = "1.0"

[features]
use-serde = ["serde", "serde_json"]
Expand Down
2 changes: 1 addition & 1 deletion influxdb/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ impl Client {
/// use std::time::{SystemTime, UNIX_EPOCH};
///
/// # #[tokio::main]
/// # async fn main() -> Result<(), failure::Error> {
/// # async fn main() -> Result<(), influxdb::Error> {
/// let start = SystemTime::now();
/// let since_the_epoch = start
/// .duration_since(UNIX_EPOCH)
Expand Down
22 changes: 12 additions & 10 deletions influxdb/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
//! Errors that might happen in the crate

#[derive(Debug, Fail)]
use thiserror::Error;

#[derive(Debug, Error)]
pub enum Error {
#[fail(display = "query is invalid: {}", error)]
#[error("query is invalid: {error}")]
/// Error happens when a query is invalid
InvalidQueryError { error: String },

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

#[fail(display = "http protocol error: {}", error)]
#[error("http protocol error: {error}")]
/// Error happens when a query is invalid
ProtocolError { error: String },

#[fail(display = "http protocol error: {}", error)]
#[error("http protocol error: {error}")]
/// Error happens when Serde cannot deserialize the response
DeserializationError { error: String },

#[fail(display = "InfluxDB encountered the following error: {}", error)]
#[error("InfluxDB encountered the following error: {error}")]
/// Error which has happened inside InfluxDB
DatabaseError { error: String },

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

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

#[fail(display = "connection error: {}", error)]
#[error("connection error: {error}")]
/// Error happens when reqwest fails
ConnectionError {
#[fail(cause)]
#[from]
error: reqwest::Error,
},
}
2 changes: 1 addition & 1 deletion influxdb/src/integrations/serde_integration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
//! }
//!
//! # #[tokio::main]
//! # async fn main() -> Result<(), failure::Error> {
//! # async fn main() -> Result<(), influxdb::Error> {
//! let client = Client::new("http://localhost:8086", "test");
//! let query = Query::raw_read_query(
//! "SELECT temperature FROM /weather_[a-z]*$/ WHERE time > now() - 1m ORDER BY DESC",
Expand Down
3 changes: 0 additions & 3 deletions influxdb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@

#![allow(clippy::needless_doctest_main)]

#[macro_use]
extern crate failure;

mod client;
mod error;
mod query;
Expand Down